mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-01-05 10:20:36 +02:00
Adding the ability to label containers that are launched using
labels: something: value something2: value2
This commit is contained in:
parent
fe750c751a
commit
aaa702dab6
@ -138,6 +138,7 @@ func (a *Agent) prep(w *queue.Work) (*yaml.Config, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
transform.Clone(conf, w.Repo.Kind)
|
transform.Clone(conf, w.Repo.Kind)
|
||||||
|
transform.Labels(conf)
|
||||||
transform.Environ(conf, envs)
|
transform.Environ(conf, envs)
|
||||||
transform.DefaultFilter(conf)
|
transform.DefaultFilter(conf)
|
||||||
if w.BuildLast != nil {
|
if w.BuildLast != nil {
|
||||||
|
@ -14,6 +14,7 @@ func toContainerConfig(c *yaml.Container) *dockerclient.ContainerConfig {
|
|||||||
config := &dockerclient.ContainerConfig{
|
config := &dockerclient.ContainerConfig{
|
||||||
Image: c.Image,
|
Image: c.Image,
|
||||||
Env: toEnvironmentSlice(c.Environment),
|
Env: toEnvironmentSlice(c.Environment),
|
||||||
|
Labels: c.Labels,
|
||||||
Cmd: c.Command,
|
Cmd: c.Command,
|
||||||
Entrypoint: c.Entrypoint,
|
Entrypoint: c.Entrypoint,
|
||||||
WorkingDir: c.WorkingDir,
|
WorkingDir: c.WorkingDir,
|
||||||
|
@ -27,6 +27,7 @@ type Container struct {
|
|||||||
Privileged bool
|
Privileged bool
|
||||||
WorkingDir string
|
WorkingDir string
|
||||||
Environment map[string]string
|
Environment map[string]string
|
||||||
|
Labels map[string]string
|
||||||
Entrypoint []string
|
Entrypoint []string
|
||||||
Command []string
|
Command []string
|
||||||
Commands []string
|
Commands []string
|
||||||
@ -61,6 +62,7 @@ type container struct {
|
|||||||
Pull bool `yaml:"pull"`
|
Pull bool `yaml:"pull"`
|
||||||
Privileged bool `yaml:"privileged"`
|
Privileged bool `yaml:"privileged"`
|
||||||
Environment types.MapEqualSlice `yaml:"environment"`
|
Environment types.MapEqualSlice `yaml:"environment"`
|
||||||
|
Labels types.MapEqualSlice `yaml:"labels"`
|
||||||
Entrypoint types.StringOrSlice `yaml:"entrypoint"`
|
Entrypoint types.StringOrSlice `yaml:"entrypoint"`
|
||||||
Command types.StringOrSlice `yaml:"command"`
|
Command types.StringOrSlice `yaml:"command"`
|
||||||
Commands types.StringOrSlice `yaml:"commands"`
|
Commands types.StringOrSlice `yaml:"commands"`
|
||||||
@ -129,6 +131,7 @@ func (c *containerList) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|||||||
Pull: cc.Pull,
|
Pull: cc.Pull,
|
||||||
Privileged: cc.Privileged,
|
Privileged: cc.Privileged,
|
||||||
Environment: cc.Environment.Map(),
|
Environment: cc.Environment.Map(),
|
||||||
|
Labels: cc.Labels.Map(),
|
||||||
Entrypoint: cc.Entrypoint.Slice(),
|
Entrypoint: cc.Entrypoint.Slice(),
|
||||||
Command: cc.Command.Slice(),
|
Command: cc.Command.Slice(),
|
||||||
Commands: cc.Commands.Slice(),
|
Commands: cc.Commands.Slice(),
|
||||||
|
19
yaml/transform/labels.go
Normal file
19
yaml/transform/labels.go
Normal file
@ -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
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user