From 167eb21b2142c44c26c2e8ced8d3d667ca1b4ba9 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Sat, 11 Oct 2014 14:35:06 -0700 Subject: [PATCH] modified Docker plugin to use new Condition struct to limit execution --- plugin/publish/docker.go | 11 ++++++++--- plugin/publish/publish.go | 4 ++-- server/main.go | 6 +++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/plugin/publish/docker.go b/plugin/publish/docker.go index 250248e8..9b5b34a4 100644 --- a/plugin/publish/docker.go +++ b/plugin/publish/docker.go @@ -4,8 +4,8 @@ import ( "fmt" "strconv" + "github.com/drone/drone/plugin/condition" "github.com/drone/drone/shared/build/buildfile" - "github.com/drone/drone/shared/build/repo" ) type Docker struct { @@ -35,7 +35,8 @@ type Docker struct { // Do we want to override "latest" automatically with this build? PushLatest bool `yaml:"push_latest"` CustomTag string `yaml:"custom_tag"` - Branch string `yaml:"branch"` + + Condition *condition.Condition `yaml:"when,omitempty"` } // Write adds commands to the buildfile to do the following: @@ -43,7 +44,7 @@ type Docker struct { // 2. Build a docker image based on the dockerfile defined in the config. // 3. Push that docker image to index.docker.io. // 4. Delete the docker image on the server it was build on so we conserve disk space. -func (d *Docker) Write(f *buildfile.Buildfile, r *repo.Repo) { +func (d *Docker) Write(f *buildfile.Buildfile) { if len(d.DockerServer) == 0 || d.DockerServerPort == 0 || len(d.DockerVersion) == 0 || len(d.ImageName) == 0 { f.WriteCmdSilent(`echo -e "Docker Plugin: Missing argument(s)\n\n"`) @@ -124,3 +125,7 @@ func (d *Docker) Write(f *buildfile.Buildfile, r *repo.Repo) { } } } + +func (d *Docker) GetCondition() *condition.Condition { + return d.Condition +} diff --git a/plugin/publish/publish.go b/plugin/publish/publish.go index cf369915..0b82a237 100644 --- a/plugin/publish/publish.go +++ b/plugin/publish/publish.go @@ -40,8 +40,8 @@ func (p *Publish) Write(f *buildfile.Buildfile, r *repo.Repo) { } // Docker - if p.Docker != nil && (len(p.Docker.Branch) == 0 || (len(p.Docker.Branch) > 0 && r.Branch == p.Docker.Branch)) { - p.Docker.Write(f, r) + if p.Docker != nil && match(p.Docker.GetCondition(), r) { + p.Docker.Write(f) } } diff --git a/server/main.go b/server/main.go index 40e0ab2b..c4ab4ac0 100644 --- a/server/main.go +++ b/server/main.go @@ -59,9 +59,9 @@ var ( pub *pubsub.PubSub // Docker configuration details. - tlscacert = config.String("docker-tlscacert") - tlscert = config.String("docker-tlscert") - tlskey = config.String("docker-tlskey") + tlscacert = config.String("docker-tlscacert", "") + tlscert = config.String("docker-tlscert", "") + tlskey = config.String("docker-tlskey", "") nodes StringArr db *sql.DB