From 584ec88b076d5f662584ef54de0d89eb789ae40e Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Tue, 27 Sep 2016 20:16:46 -0500 Subject: [PATCH] add platform field and selector capabilities --- drone/agent/agent.go | 26 +++++++++++++++----------- server/build.go | 10 +++++++++- server/hook.go | 10 +++++++++- yaml/platform.go | 26 ++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 13 deletions(-) create mode 100644 yaml/platform.go diff --git a/drone/agent/agent.go b/drone/agent/agent.go index 7c35808fa..ec94eada4 100644 --- a/drone/agent/agent.go +++ b/drone/agent/agent.go @@ -57,12 +57,6 @@ var AgentCmd = cli.Command{ Usage: "docker architecture system", Value: "amd64", }, - cli.StringFlag{ - EnvVar: "DRONE_STORAGE_DRIVER", - Name: "drone-storage-driver", - Usage: "docker storage driver", - Value: "overlay", - }, cli.StringFlag{ EnvVar: "DRONE_SERVER", Name: "drone-server", @@ -102,6 +96,11 @@ var AgentCmd = cli.Command{ Usage: "drone timeout due to log inactivity", Value: time.Minute * 5, }, + cli.StringFlag{ + EnvVar: "DRONE_FILTER", + Name: "filter", + Usage: "filter jobs processed by this agent", + }, cli.IntFlag{ EnvVar: "DRONE_MAX_LOGS", Name: "max-log-size", @@ -219,15 +218,20 @@ func start(c *cli.Context) { continue } - // subscribe to the pending build queue. - client.Subscribe("/queue/pending", stomp.HandlerFunc(func(m *stomp.Message) { - go handler(m) // HACK until we a channel based Subscribe implementation - }), + opts = []stomp.MessageOption{ stomp.WithAck("client"), stomp.WithPrefetch( c.Int("docker-max-procs"), ), - ) + } + if filter := c.String("filter"); filter != "" { + opts = append(opts, stomp.WithSelector(filter)) + } + + // subscribe to the pending build queue. + client.Subscribe("/queue/pending", stomp.HandlerFunc(func(m *stomp.Message) { + go handler(m) // HACK until we a channel based Subscribe implementation + }), opts...) logrus.Infof("Server connection establish, ready to process builds.") <-client.Done() diff --git a/server/build.go b/server/build.go index 3fdc81960..5a35f126d 100644 --- a/server/build.go +++ b/server/build.go @@ -351,7 +351,15 @@ func PostBuild(c *gin.Context) { Yaml: string(raw), Secrets: secs, System: &model.System{Link: httputil.GetURL(c.Request)}, - }, stomp.WithHeaders(yaml.ParseLabel(raw))) + }, + stomp.WithHeader( + "platform", + yaml.ParsePlatformDefault(raw, "linux/amd64"), + ), + stomp.WithHeaders( + yaml.ParseLabel(raw), + ), + ) } } diff --git a/server/hook.go b/server/hook.go index 7f722c127..ef167f231 100644 --- a/server/hook.go +++ b/server/hook.go @@ -237,7 +237,15 @@ func PostHook(c *gin.Context) { Yaml: string(raw), Secrets: secs, System: &model.System{Link: httputil.GetURL(c.Request)}, - }, stomp.WithHeaders(yaml.ParseLabel(raw))) + }, + stomp.WithHeader( + "platform", + yaml.ParsePlatformDefault(raw, "linux/amd64"), + ), + stomp.WithHeaders( + yaml.ParseLabel(raw), + ), + ) } } diff --git a/yaml/platform.go b/yaml/platform.go new file mode 100644 index 000000000..69e1cccc2 --- /dev/null +++ b/yaml/platform.go @@ -0,0 +1,26 @@ +package yaml + +import "gopkg.in/yaml.v2" + +// ParsePlatform parses the platform section of the Yaml document. +func ParsePlatform(in []byte) string { + out := struct { + Platform string `yaml:"platform"` + }{} + + yaml.Unmarshal(in, &out) + return out.Platform +} + +// ParsePlatformString parses the platform section of the Yaml document. +func ParsePlatformString(in string) string { + return ParsePlatform([]byte(in)) +} + +// ParsePlatformDefault parses the platform section of the Yaml document. +func ParsePlatformDefault(in []byte, platform string) string { + if p := ParsePlatform([]byte(in)); p != "" { + return p + } + return platform +}