Skip to content

Commit

Permalink
Merge pull request harness#981 from vaijab/docker-login
Browse files Browse the repository at this point in the history
publish/docker: login should happen early
  • Loading branch information
bradrydzewski committed May 15, 2015
2 parents 039daa2 + 009e8a1 commit 09b26bf
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions plugin/publish/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ func (d *Docker) Write(f *buildfile.Buildfile) {
d.DockerVersion + ".tgz |sudo tar zxf - -C /")
}

// Export docker host once
f.WriteCmd("export DOCKER_HOST=" + d.DockerHost)

// Login?
if d.RegistryLogin == true {
// If email is unspecified, pass in -e ' ' to avoid having
// registry URL interpreted as email, which will fail cryptically.
emailOpt := "' '"
if d.Email != "" {
emailOpt = d.Email
}
f.WriteCmdSilent(fmt.Sprintf("docker login -u %s -p %s -e %s %s",
d.Username, d.Password, emailOpt, d.RegistryLoginUrl))
}

dockerPath := "."
if len(d.Dockerfile) != 0 {
dockerPath = fmt.Sprintf("- < %s", d.Dockerfile)
Expand All @@ -86,24 +101,9 @@ func (d *Docker) Write(f *buildfile.Buildfile) {
// There is always at least 1 tag
buildImageTag := d.Tags[0]

// Export docker host once
f.WriteCmd("export DOCKER_HOST=" + d.DockerHost)

// Build the image
f.WriteCmd(fmt.Sprintf("docker build --pull -t %s:%s %s", d.ImageName, buildImageTag, dockerPath))

// Login?
if d.RegistryLogin == true {
// If email is unspecified, pass in -e ' ' to avoid having
// registry URL interpreted as email, which will fail cryptically.
emailOpt := "' '"
if d.Email != "" {
emailOpt = d.Email
}
f.WriteCmdSilent(fmt.Sprintf("docker login -u %s -p %s -e %s %s",
d.Username, d.Password, emailOpt, d.RegistryLoginUrl))
}

// Tag and push all tags
for _, tag := range d.Tags {
if tag != buildImageTag {
Expand Down

0 comments on commit 09b26bf

Please sign in to comment.