mirror of
https://github.com/thegeeklab/wp-docker-buildx.git
synced 2024-11-22 10:10:39 +00:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
f69f3d2b74
@ -151,6 +151,11 @@ func main() {
|
||||
Usage: "build target",
|
||||
EnvVar: "PLUGIN_TARGET",
|
||||
},
|
||||
cli.StringSliceFlag{
|
||||
Name: "cache-from",
|
||||
Usage: "images to consider as cache sources",
|
||||
EnvVar: "PLUGIN_CACHE_FROM",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "squash",
|
||||
Usage: "squash the layers at build time",
|
||||
@ -245,6 +250,7 @@ func run(c *cli.Context) error {
|
||||
Target: c.String("target"),
|
||||
Squash: c.Bool("squash"),
|
||||
Pull: c.BoolT("pull-image"),
|
||||
CacheFrom: c.StringSlice("cache-from"),
|
||||
Compress: c.Bool("compress"),
|
||||
Repo: c.String("repo"),
|
||||
Labels: c.StringSlice("custom-labels"),
|
||||
|
22
docker.go
22
docker.go
@ -47,6 +47,7 @@ type (
|
||||
Target string // Docker build target
|
||||
Squash bool // Docker build squash
|
||||
Pull bool // Docker build pull
|
||||
CacheFrom []string // Docker build cache-from
|
||||
Compress bool // Docker build compress
|
||||
Repo string // Docker build repository
|
||||
LabelSchema []string // label-schema Label map
|
||||
@ -116,6 +117,11 @@ func (p Plugin) Exec() error {
|
||||
cmds = append(cmds, commandVersion()) // docker version
|
||||
cmds = append(cmds, commandInfo()) // docker info
|
||||
|
||||
// pre-pull cache images
|
||||
for _, img := range p.Build.CacheFrom {
|
||||
cmds = append(cmds, commandPull(img))
|
||||
}
|
||||
|
||||
cmds = append(cmds, commandBuild(p.Build)) // docker build
|
||||
|
||||
for _, tag := range p.Build.Tags {
|
||||
@ -138,7 +144,9 @@ func (p Plugin) Exec() error {
|
||||
trace(cmd)
|
||||
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
if err != nil && isCommandPull(cmd.Args) {
|
||||
fmt.Printf("Could not pull cache-from image %s. Ignoring...\n", cmd.Args[2])
|
||||
} else if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@ -162,6 +170,15 @@ func commandLogin(login Login) *exec.Cmd {
|
||||
)
|
||||
}
|
||||
|
||||
// helper to check if args match "docker pull <image>"
|
||||
func isCommandPull(args []string) bool {
|
||||
return len(args) > 2 && args[1] == "pull"
|
||||
}
|
||||
|
||||
func commandPull(repo string) *exec.Cmd {
|
||||
return exec.Command(dockerExe, "pull", repo)
|
||||
}
|
||||
|
||||
func commandLoginEmail(login Login) *exec.Cmd {
|
||||
return exec.Command(
|
||||
dockerExe, "login",
|
||||
@ -204,6 +221,9 @@ func commandBuild(build Build) *exec.Cmd {
|
||||
if build.NoCache {
|
||||
args = append(args, "--no-cache")
|
||||
}
|
||||
for _, arg := range build.CacheFrom {
|
||||
args = append(args, "--cache-from", arg)
|
||||
}
|
||||
for _, arg := range build.ArgsEnv {
|
||||
addProxyValue(&build, arg)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user