From e2bb2340445c84bc49acc52379975c702a2135ff Mon Sep 17 00:00:00 2001 From: Erik Evenson Date: Sat, 27 Feb 2016 11:06:40 -0600 Subject: [PATCH 1/5] allows AWS ECR to work --- client/driver/docker.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/client/driver/docker.go b/client/driver/docker.go index 48e65f6fe2a..8448f5d6b2e 100644 --- a/client/driver/docker.go +++ b/client/driver/docker.go @@ -5,6 +5,7 @@ import ( "fmt" "log" "net" + "net/url" "os" "os/exec" "path/filepath" @@ -471,7 +472,20 @@ func (d *DockerDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle if authConfigurations, err = docker.NewAuthConfigurations(f); err != nil { return nil, fmt.Errorf("Failed to create docker auth object: %v", err) } - if authConfiguration, ok := authConfigurations.Configs[repo]; ok { + authConfigurationKey := "" + + if parsedUrl, err := url.Parse(repo); err == nil { + if parsedUrl.Scheme != "" { + authConfigurationKey += parsedUrl.Scheme + "://" + } + + authConfigurationKey += parsedUrl.Host + pullOptions.Repository = parsedUrl.Host + parsedUrl.Path + } else { + return nil, fmt.Errorf("Failed to parse image repo: %v", err) + } + + if authConfiguration, ok := authConfigurations.Configs[authConfigurationKey]; ok { authOptions = authConfiguration } } else { @@ -487,6 +501,8 @@ func (d *DockerDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle d.logger.Printf("[DEBUG] driver.docker: docker pull %s:%s succeeded", repo, tag) // Now that we have the image we can get the image id + driverConfig.ImageName = strings.Replace(driverConfig.ImageName, "https://", "", 1) + image = driverConfig.ImageName dockerImage, err = client.InspectImage(image) if err != nil { d.logger.Printf("[ERR] driver.docker: failed getting image id for %s: %s", image, err) From 2ae1f445c63a3bf9f77aa2746271627d3270f6d9 Mon Sep 17 00:00:00 2001 From: Erik Evenson Date: Sat, 27 Feb 2016 12:00:17 -0600 Subject: [PATCH 2/5] refactors --- client/driver/docker.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/client/driver/docker.go b/client/driver/docker.go index 8448f5d6b2e..7bbc71a994f 100644 --- a/client/driver/docker.go +++ b/client/driver/docker.go @@ -5,7 +5,6 @@ import ( "fmt" "log" "net" - "net/url" "os" "os/exec" "path/filepath" @@ -61,6 +60,7 @@ type DockerDriverConfig struct { LabelsRaw []map[string]string `mapstructure:"labels"` // Labels map[string]string `mapstructure:"-"` // Labels to set when the container starts up Auth []DockerDriverAuth `mapstructure:"auth"` // Authentication credentials for a private Docker registry + SSL bool `mapstructure:"ssl"` } func (c *DockerDriverConfig) Validate() error { @@ -409,6 +409,14 @@ func (d *DockerDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle if err := mapstructure.WeakDecode(task.Config, &driverConfig); err != nil { return nil, err } + + if strings.Contains(driverConfig.ImageName, "https://") { + driverConfig.SSL = true + driverConfig.ImageName = strings.Replace(driverConfig.ImageName, "https://", "", 1) + } else { + driverConfig.SSL = false + } + image := driverConfig.ImageName if err := driverConfig.Validate(); err != nil { @@ -472,19 +480,13 @@ func (d *DockerDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle if authConfigurations, err = docker.NewAuthConfigurations(f); err != nil { return nil, fmt.Errorf("Failed to create docker auth object: %v", err) } - authConfigurationKey := "" - - if parsedUrl, err := url.Parse(repo); err == nil { - if parsedUrl.Scheme != "" { - authConfigurationKey += parsedUrl.Scheme + "://" - } - authConfigurationKey += parsedUrl.Host - pullOptions.Repository = parsedUrl.Host + parsedUrl.Path - } else { - return nil, fmt.Errorf("Failed to parse image repo: %v", err) + authConfigurationKey := "" + if driverConfig.SSL { + authConfigurationKey += "https://" } + authConfigurationKey += strings.Split(driverConfig.ImageName, "/")[0] if authConfiguration, ok := authConfigurations.Configs[authConfigurationKey]; ok { authOptions = authConfiguration } @@ -501,8 +503,6 @@ func (d *DockerDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle d.logger.Printf("[DEBUG] driver.docker: docker pull %s:%s succeeded", repo, tag) // Now that we have the image we can get the image id - driverConfig.ImageName = strings.Replace(driverConfig.ImageName, "https://", "", 1) - image = driverConfig.ImageName dockerImage, err = client.InspectImage(image) if err != nil { d.logger.Printf("[ERR] driver.docker: failed getting image id for %s: %s", image, err) From bfbd4d6d88cb2d31620e874f58591ed1362c4c6b Mon Sep 17 00:00:00 2001 From: Erik Evenson Date: Sat, 27 Feb 2016 12:10:36 -0600 Subject: [PATCH 3/5] updates docs --- website/source/docs/drivers/docker.html.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/website/source/docs/drivers/docker.html.md b/website/source/docs/drivers/docker.html.md index cbf4edde72a..e21ed6eebaa 100644 --- a/website/source/docs/drivers/docker.html.md +++ b/website/source/docs/drivers/docker.html.md @@ -32,7 +32,7 @@ task "webservice" { The following options are available for use in the job specification. -* `image` - The Docker image to run. The image may include a tag or custom URL. +* `image` - The Docker image to run. The image may include a tag or custom URL and should include `https://` if required. By default it will be fetched from Docker Hub. * `command` - (Optional) The command to run when starting the container. @@ -248,7 +248,7 @@ The `docker` driver has the following host-level configuration options: location). * `docker.auth.config` - Allows an operator to specify a json file which is in - the dockercfg format containing authentication information for private registry. + the dockercfg format containing authentication information for private registry. * `docker.tls.cert` - Path to the server's certificate file (`.pem`). Specify this along with `docker.tls.key` and `docker.tls.ca` to use a TLS client to From d5142c25dcd26769aa85a6352fca37ebeb85f32f Mon Sep 17 00:00:00 2001 From: Erik Evenson Date: Mon, 29 Feb 2016 08:17:40 -0600 Subject: [PATCH 4/5] adds comments and removes redundant false flag setting --- client/driver/docker.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/client/driver/docker.go b/client/driver/docker.go index 7bbc71a994f..53247790ce8 100644 --- a/client/driver/docker.go +++ b/client/driver/docker.go @@ -60,7 +60,7 @@ type DockerDriverConfig struct { LabelsRaw []map[string]string `mapstructure:"labels"` // Labels map[string]string `mapstructure:"-"` // Labels to set when the container starts up Auth []DockerDriverAuth `mapstructure:"auth"` // Authentication credentials for a private Docker registry - SSL bool `mapstructure:"ssl"` + SSL bool `mapstructure:"ssl"` // Flag indicating repository is served via https } func (c *DockerDriverConfig) Validate() error { @@ -413,8 +413,6 @@ func (d *DockerDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle if strings.Contains(driverConfig.ImageName, "https://") { driverConfig.SSL = true driverConfig.ImageName = strings.Replace(driverConfig.ImageName, "https://", "", 1) - } else { - driverConfig.SSL = false } image := driverConfig.ImageName From d1f28431c40ecb7068ad2f85211b80210225ae2c Mon Sep 17 00:00:00 2001 From: Erik Evenson Date: Sun, 6 Mar 2016 19:00:40 -0600 Subject: [PATCH 5/5] moves transform to Init() --- client/driver/docker.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/client/driver/docker.go b/client/driver/docker.go index 0870485442b..e7d671c8add 100644 --- a/client/driver/docker.go +++ b/client/driver/docker.go @@ -72,6 +72,15 @@ type DockerDriverConfig struct { SSL bool `mapstructure:"ssl"` // Flag indicating repository is served via https } +func (c *DockerDriverConfig) Init() error { + if strings.Contains(c.ImageName, "https://") { + c.SSL = true + c.ImageName = strings.Replace(c.ImageName, "https://", "", 1) + } + + return nil +} + func (c *DockerDriverConfig) Validate() error { if c.ImageName == "" { return fmt.Errorf("Docker Driver needs an image name") @@ -412,9 +421,8 @@ func (d *DockerDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle return nil, err } - if strings.Contains(driverConfig.ImageName, "https://") { - driverConfig.SSL = true - driverConfig.ImageName = strings.Replace(driverConfig.ImageName, "https://", "", 1) + if err := driverConfig.Init(); err != nil { + return nil, err } image := driverConfig.ImageName