Skip to content

Commit

Permalink
Merge pull request #858 from ErikEvenson/prs/fix-aws-ecr
Browse files Browse the repository at this point in the history
Fix AWS ECR private repository usage
  • Loading branch information
diptanu committed Mar 8, 2016
2 parents 8588b6c + d1f2843 commit 677b92d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
24 changes: 23 additions & 1 deletion client/driver/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ 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"` // 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 {
Expand Down Expand Up @@ -410,6 +420,11 @@ func (d *DockerDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle
if err := mapstructure.WeakDecode(task.Config, &driverConfig); err != nil {
return nil, err
}

if err := driverConfig.Init(); err != nil {
return nil, err
}

image := driverConfig.ImageName

if err := driverConfig.Validate(); err != nil {
Expand Down Expand Up @@ -473,7 +488,14 @@ 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 driverConfig.SSL {
authConfigurationKey += "https://"
}

authConfigurationKey += strings.Split(driverConfig.ImageName, "/")[0]
if authConfiguration, ok := authConfigurations.Configs[authConfigurationKey]; ok {
authOptions = authConfiguration
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions website/source/docs/drivers/docker.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 677b92d

Please sign in to comment.