From aaa702dab6858ac47a71e93c2ed6e9c54e0527be Mon Sep 17 00:00:00 2001 From: Joachim Hill-Grannec Date: Sat, 13 Aug 2016 14:38:37 -0700 Subject: [PATCH 1/2] Adding the ability to label containers that are launched using labels: something: value something2: value2 --- agent/agent.go | 1 + build/docker/util.go | 1 + yaml/container.go | 3 +++ yaml/transform/labels.go | 19 +++++++++++++++++++ 4 files changed, 24 insertions(+) create mode 100644 yaml/transform/labels.go diff --git a/agent/agent.go b/agent/agent.go index e441608be..853a62be2 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -138,6 +138,7 @@ func (a *Agent) prep(w *queue.Work) (*yaml.Config, error) { } transform.Clone(conf, w.Repo.Kind) + transform.Labels(conf) transform.Environ(conf, envs) transform.DefaultFilter(conf) if w.BuildLast != nil { diff --git a/build/docker/util.go b/build/docker/util.go index c4b9d3e4d..f7ede3f92 100644 --- a/build/docker/util.go +++ b/build/docker/util.go @@ -14,6 +14,7 @@ func toContainerConfig(c *yaml.Container) *dockerclient.ContainerConfig { config := &dockerclient.ContainerConfig{ Image: c.Image, Env: toEnvironmentSlice(c.Environment), + Labels: c.Labels, Cmd: c.Command, Entrypoint: c.Entrypoint, WorkingDir: c.WorkingDir, diff --git a/yaml/container.go b/yaml/container.go index 012be8a0f..77e41c1f6 100644 --- a/yaml/container.go +++ b/yaml/container.go @@ -27,6 +27,7 @@ type Container struct { Privileged bool WorkingDir string Environment map[string]string + Labels map[string]string Entrypoint []string Command []string Commands []string @@ -61,6 +62,7 @@ type container struct { Pull bool `yaml:"pull"` Privileged bool `yaml:"privileged"` Environment types.MapEqualSlice `yaml:"environment"` + Labels types.MapEqualSlice `yaml:"labels"` Entrypoint types.StringOrSlice `yaml:"entrypoint"` Command types.StringOrSlice `yaml:"command"` Commands types.StringOrSlice `yaml:"commands"` @@ -129,6 +131,7 @@ func (c *containerList) UnmarshalYAML(unmarshal func(interface{}) error) error { Pull: cc.Pull, Privileged: cc.Privileged, Environment: cc.Environment.Map(), + Labels: cc.Labels.Map(), Entrypoint: cc.Entrypoint.Slice(), Command: cc.Command.Slice(), Commands: cc.Commands.Slice(), diff --git a/yaml/transform/labels.go b/yaml/transform/labels.go new file mode 100644 index 000000000..ba85e979e --- /dev/null +++ b/yaml/transform/labels.go @@ -0,0 +1,19 @@ +package transform + +import ( + "github.com/drone/drone/yaml" +) + +// Labels transforms the steps in the Yaml pipeline to include a Labels if it doens't exist +func Labels(c *yaml.Config) error { + var images []*yaml.Container + images = append(images, c.Pipeline...) + images = append(images, c.Services...) + + for _, p := range images { + if p.Labels == nil { + p.Labels = map[string]string{} + } + } + return nil +} From 72e960e46afb4a86f2440d96ac0a4de9464e03c9 Mon Sep 17 00:00:00 2001 From: Joachim Hill-Grannec Date: Sat, 13 Aug 2016 14:59:44 -0700 Subject: [PATCH 2/2] Removing transformations that aren't needed. --- agent/agent.go | 1 - yaml/transform/labels.go | 19 ------------------- 2 files changed, 20 deletions(-) delete mode 100644 yaml/transform/labels.go diff --git a/agent/agent.go b/agent/agent.go index 853a62be2..e441608be 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -138,7 +138,6 @@ func (a *Agent) prep(w *queue.Work) (*yaml.Config, error) { } transform.Clone(conf, w.Repo.Kind) - transform.Labels(conf) transform.Environ(conf, envs) transform.DefaultFilter(conf) if w.BuildLast != nil { diff --git a/yaml/transform/labels.go b/yaml/transform/labels.go deleted file mode 100644 index ba85e979e..000000000 --- a/yaml/transform/labels.go +++ /dev/null @@ -1,19 +0,0 @@ -package transform - -import ( - "github.com/drone/drone/yaml" -) - -// Labels transforms the steps in the Yaml pipeline to include a Labels if it doens't exist -func Labels(c *yaml.Config) error { - var images []*yaml.Container - images = append(images, c.Pipeline...) - images = append(images, c.Services...) - - for _, p := range images { - if p.Labels == nil { - p.Labels = map[string]string{} - } - } - return nil -}