From 0f7253febb1cad14e7fa115799fa170b57731eb8 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Thu, 25 Aug 2016 11:35:28 -0700 Subject: [PATCH] choose ambassador by platform --- agent/agent.go | 2 +- yaml/transform/pod.go | 41 +++++++++++++++++++++++++++++++++++++---- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/agent/agent.go b/agent/agent.go index 9a63fcf4..2a1e343f 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -167,7 +167,7 @@ func (a *Agent) prep(w *queue.Work) (*yaml.Config, error) { transform.ImageVolume(conf, []string{a.Local + ":" + conf.Workspace.Path}) } - transform.Pod(conf) + transform.Pod(conf, a.Platform) return conf, nil } diff --git a/yaml/transform/pod.go b/yaml/transform/pod.go index ae734cd6..dd92acbb 100644 --- a/yaml/transform/pod.go +++ b/yaml/transform/pod.go @@ -9,21 +9,54 @@ import ( "github.com/gorilla/securecookie" ) +type ambassador struct { + image string + entrypoint []string + command []string +} + +// default linux amd64 ambassador +var defaultAmbassador = ambassador{ + image: "busybox:latest", + entrypoint: []string{"/bin/sleep"}, + command: []string{"86400"}, +} + +// lookup ambassador configuration by architecture and os +var lookupAmbassador = map[string]ambassador{ + "linux/amd64": { + image: "busybox:latest", + entrypoint: []string{"/bin/sleep"}, + command: []string{"86400"}, + }, + "linux/arm": { + image: "armhf/alpine:latest", + entrypoint: []string{"/bin/sleep"}, + command: []string{"86400"}, + }, +} + // Pod transforms the containers in the Yaml to use Pod networking, where every // container shares the localhost connection. -func Pod(c *yaml.Config) error { +func Pod(c *yaml.Config, platform string) error { rand := base64.RawURLEncoding.EncodeToString( securecookie.GenerateRandomKey(8), ) + // choose the ambassador configuration based on os and architecture + conf, ok := lookupAmbassador[platform] + if !ok { + conf = defaultAmbassador + } + ambassador := &yaml.Container{ ID: fmt.Sprintf("drone_ambassador_%s", rand), Name: "ambassador", - Image: "busybox:latest", + Image: conf.image, Detached: true, - Entrypoint: []string{"/bin/sleep"}, - Command: []string{"86400"}, + Entrypoint: conf.entrypoint, + Command: conf.command, Volumes: []string{c.Workspace.Path, c.Workspace.Base}, Environment: map[string]string{}, }