From 5d96ed01d282beeb2af5906741aaaa55e29ffc20 Mon Sep 17 00:00:00 2001 From: Jeff Downie Date: Fri, 17 Feb 2017 16:18:43 +0000 Subject: [PATCH 1/2] allowing docker to use cached base image in build --- .gitignore | 3 +++ main.go | 6 ++++++ plugin.go | 7 ++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index fa8a04b..62ee6df 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,6 @@ _testmain.go coverage.out drone-docker + +# IDE/Editor related files +**.swp diff --git a/main.go b/main.go index 6e61c7a..eb7e4a1 100644 --- a/main.go +++ b/main.go @@ -118,6 +118,11 @@ func main() { Usage: "squash the layers at build time", EnvVar: "PLUGIN_SQUASH", }, + cli.BoolTFlag{ + Name: "cache", + Usage: "don't attempt to re-build layers of the image that already exist", + EnvVar: "PLUGIN_USE_CACHE", + }, cli.BoolFlag{ Name: "compress", Usage: "compress the build context using gzip", @@ -172,6 +177,7 @@ func run(c *cli.Context) error { Tags: c.StringSlice("tags"), Args: c.StringSlice("args"), Squash: c.Bool("squash"), + Cache: c.Bool("cache"), Compress: c.Bool("compress"), Repo: c.String("repo"), }, diff --git a/plugin.go b/plugin.go index e2c9237..14b222d 100644 --- a/plugin.go +++ b/plugin.go @@ -47,6 +47,7 @@ type ( Tags []string // Docker build tags Args []string // Docker build args Squash bool // Docker build squash + Cache bool // Docker build without pulling Compress bool // Docker build compress Repo string // Docker build repository } @@ -187,7 +188,6 @@ func commandInfo() *exec.Cmd { func commandBuild(build Build) *exec.Cmd { args := []string { "build", - "--pull=true", "--rm=true", "-f", build.Dockerfile, "-t", build.Name, @@ -200,6 +200,11 @@ func commandBuild(build Build) *exec.Cmd { if build.Compress { args = append(args, "--compress") } + if build.Cache { + args = append(args, "--pull=false") + } else { + args = append(args, "--pull=true") + } for _, arg := range build.Args { args = append(args, "--build-arg", arg) } From 8551bcc59f8b4fbcefb983188e80018a8deb07d4 Mon Sep 17 00:00:00 2001 From: Jeff Downie Date: Mon, 20 Feb 2017 11:40:35 +0000 Subject: [PATCH 2/2] Renaming use_cache to pull_image --- .gitignore | 3 --- main.go | 8 ++++---- plugin.go | 12 +++++------- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index 62ee6df..fa8a04b 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,3 @@ _testmain.go coverage.out drone-docker - -# IDE/Editor related files -**.swp diff --git a/main.go b/main.go index eb7e4a1..b16f035 100644 --- a/main.go +++ b/main.go @@ -119,9 +119,9 @@ func main() { EnvVar: "PLUGIN_SQUASH", }, cli.BoolTFlag{ - Name: "cache", - Usage: "don't attempt to re-build layers of the image that already exist", - EnvVar: "PLUGIN_USE_CACHE", + Name: "pull-image", + Usage: "force pull base image at build time", + EnvVar: "PLUGIN_PULL_IMAGE", }, cli.BoolFlag{ Name: "compress", @@ -177,7 +177,7 @@ func run(c *cli.Context) error { Tags: c.StringSlice("tags"), Args: c.StringSlice("args"), Squash: c.Bool("squash"), - Cache: c.Bool("cache"), + Pull: c.BoolT("pull-image"), Compress: c.Bool("compress"), Repo: c.String("repo"), }, diff --git a/plugin.go b/plugin.go index 14b222d..f65921a 100644 --- a/plugin.go +++ b/plugin.go @@ -47,7 +47,7 @@ type ( Tags []string // Docker build tags Args []string // Docker build args Squash bool // Docker build squash - Cache bool // Docker build without pulling + Pull bool // Docker build pull Compress bool // Docker build compress Repo string // Docker build repository } @@ -186,7 +186,7 @@ func commandInfo() *exec.Cmd { // helper function to create the docker build command. func commandBuild(build Build) *exec.Cmd { - args := []string { + args := []string{ "build", "--rm=true", "-f", build.Dockerfile, @@ -200,11 +200,9 @@ func commandBuild(build Build) *exec.Cmd { if build.Compress { args = append(args, "--compress") } - if build.Cache { - args = append(args, "--pull=false") - } else { - args = append(args, "--pull=true") - } + if build.Pull { + args = append(args, "--pull=true") + } for _, arg := range build.Args { args = append(args, "--build-arg", arg) }