From f4756f8e398130793f2d826733f33880ca0d783e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ke=CC=81vin=20Darcel?= Date: Fri, 27 Jan 2017 12:04:55 -0600 Subject: [PATCH 1/7] Support --compress docker build flag --- main.go | 6 ++++++ plugin.go | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/main.go b/main.go index 5969295..6e61c7a 100644 --- a/main.go +++ b/main.go @@ -118,6 +118,11 @@ func main() { Usage: "squash the layers at build time", EnvVar: "PLUGIN_SQUASH", }, + cli.BoolFlag{ + Name: "compress", + Usage: "compress the build context using gzip", + EnvVar: "PLUGIN_COMPRESS", + }, cli.StringFlag{ Name: "repo", Usage: "docker repository", @@ -167,6 +172,7 @@ func run(c *cli.Context) error { Tags: c.StringSlice("tags"), Args: c.StringSlice("args"), Squash: c.Bool("squash"), + Compress: c.Bool("compress"), Repo: c.String("repo"), }, Daemon: Daemon{ diff --git a/plugin.go b/plugin.go index fbfbc0a..7a79dc4 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 + Compress bool // Docker build compress Repo string // Docker build repository } @@ -195,6 +196,9 @@ func commandBuild(build Build) *exec.Cmd { if build.Squash { args = append(args, "--squash") } + if build.Compress { + args = append(args, "--compress") + } for _, arg := range build.Args { args = append(args, "--build-arg", arg) } From c9fb4e5261c85fbe630f81e6e07ce101e5b3fed0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ke=CC=81vin=20Darcel?= Date: Fri, 27 Jan 2017 12:18:52 -0600 Subject: [PATCH 2/7] docker daemon is deprecated since 1.13, using dockerd binary instead --- plugin.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugin.go b/plugin.go index fbfbc0a..2c1f6df 100644 --- a/plugin.go +++ b/plugin.go @@ -147,6 +147,7 @@ func (p Plugin) Exec() error { } const dockerExe = "/usr/local/bin/docker" +const dockerdExe = "/usr/local/bin/dockerd" // helper function to create the docker login command. func commandLogin(login Login) *exec.Cmd { @@ -264,7 +265,7 @@ func commandPush(build Build, tag string) *exec.Cmd { // helper function to create the docker daemon command. func commandDaemon(daemon Daemon) *exec.Cmd { - args := []string{"daemon", "-g", daemon.StoragePath} + args := []string{"-g", daemon.StoragePath} if daemon.StorageDriver != "" { args = append(args, "-s", daemon.StorageDriver) @@ -290,7 +291,7 @@ func commandDaemon(daemon Daemon) *exec.Cmd { if daemon.Experimental { args = append(args, "--experimental") } - return exec.Command(dockerExe, args...) + return exec.Command(dockerdExe, args...) } // trace writes each command to stdout with the command wrapped in an xml From 322965b48927cf9cf7158d92bffd81a415382584 Mon Sep 17 00:00:00 2001 From: Ken Dombeck Date: Tue, 31 Jan 2017 10:51:42 -0600 Subject: [PATCH 3/7] Updated documentation link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7165ae1..eb32700 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Drone plugin can be used to build and publish Docker images to a container registry. For the usage information and a listing of the available options -please take a look at [the docs](DOCS.md). +please take a look at [the docs](http://plugins.drone.io/drone-plugins/drone-docker/). ## Build From 5d96ed01d282beeb2af5906741aaaa55e29ffc20 Mon Sep 17 00:00:00 2001 From: Jeff Downie Date: Fri, 17 Feb 2017 16:18:43 +0000 Subject: [PATCH 4/7] 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 5/7] 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) } From 661ee5d652475e6be6812f80156495d778d64173 Mon Sep 17 00:00:00 2001 From: Jacob McCann Date: Tue, 14 Mar 2017 16:14:48 -0500 Subject: [PATCH 6/7] Remove unused docker data --- plugin.go | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/plugin.go b/plugin.go index f65921a..c0e97ee 100644 --- a/plugin.go +++ b/plugin.go @@ -63,17 +63,6 @@ type ( // Exec executes the plugin step func (p Plugin) Exec() error { - - // TODO execute code remove dangling images - // this is problematic because we are running docker in scratch which does - // not have bash, so we need to hack something together - // docker images --quiet --filter=dangling=true | xargs --no-run-if-empty docker rmi - - /* - cmd = exec.Command("docker", "images", "-q", "-f", "dangling=true") - cmd = exec.Command("docker", append([]string{"rmi"}, images...)...) - */ - // start the Docker daemon server if !p.Daemon.Disabled { cmd := commandDaemon(p.Daemon) @@ -123,6 +112,7 @@ func (p Plugin) Exec() error { var cmds []*exec.Cmd cmds = append(cmds, commandVersion()) // docker version cmds = append(cmds, commandInfo()) // docker info + cmds = append(cmds, commandDockerPrune()) // cleanup docker cmds = append(cmds, commandBuild(p.Build)) // docker build for _, tag := range p.Build.Tags { @@ -301,6 +291,10 @@ func commandDaemon(daemon Daemon) *exec.Cmd { return exec.Command(dockerdExe, args...) } +func commandDockerPrune() *exec.Cmd { + return exec.Command(dockerExe, "system", "prune", "-f") +} + // trace writes each command to stdout with the command wrapped in an xml // tag so that it can be extracted and displayed in the logs. func trace(cmd *exec.Cmd) { From ddc25946e9ff7b0b4547d42040b6c0283431f7bb Mon Sep 17 00:00:00 2001 From: Greyson Dehn Date: Thu, 16 Mar 2017 14:17:34 -0500 Subject: [PATCH 7/7] Change env precedence --- main.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index b16f035..063ebc7 100644 --- a/main.go +++ b/main.go @@ -137,22 +137,22 @@ func main() { Name: "docker.registry", Usage: "docker registry", Value: defaultRegistry, - EnvVar: "DOCKER_REGISTRY,PLUGIN_REGISTRY", + EnvVar: "PLUGIN_REGISTRY,DOCKER_REGISTRY", }, cli.StringFlag{ Name: "docker.username", Usage: "docker username", - EnvVar: "DOCKER_USERNAME,PLUGIN_USERNAME", + EnvVar: "PLUGIN_USERNAME,DOCKER_USERNAME", }, cli.StringFlag{ Name: "docker.password", Usage: "docker password", - EnvVar: "DOCKER_PASSWORD,PLUGIN_PASSWORD", + EnvVar: "PLUGIN_PASSWORD,DOCKER_PASSWORD", }, cli.StringFlag{ Name: "docker.email", Usage: "docker email", - EnvVar: "DOCKER_EMAIL,PLUGIN_EMAIL", + EnvVar: "PLUGIN_EMAIL,DOCKER_EMAIL", }, }