Merge pull request #981 from vaijab/docker-login

publish/docker: login should happen early
This commit is contained in:
Brad Rydzewski 2015-05-15 09:57:25 -07:00
commit 09b26bf784

View file

@ -66,6 +66,21 @@ func (d *Docker) Write(f *buildfile.Buildfile) {
d.DockerVersion + ".tgz |sudo tar zxf - -C /") 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 := "." dockerPath := "."
if len(d.Dockerfile) != 0 { if len(d.Dockerfile) != 0 {
dockerPath = fmt.Sprintf("- < %s", d.Dockerfile) dockerPath = fmt.Sprintf("- < %s", d.Dockerfile)
@ -86,24 +101,9 @@ func (d *Docker) Write(f *buildfile.Buildfile) {
// There is always at least 1 tag // There is always at least 1 tag
buildImageTag := d.Tags[0] buildImageTag := d.Tags[0]
// Export docker host once
f.WriteCmd("export DOCKER_HOST=" + d.DockerHost)
// Build the image // Build the image
f.WriteCmd(fmt.Sprintf("docker build --pull -t %s:%s %s", d.ImageName, buildImageTag, dockerPath)) 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 // Tag and push all tags
for _, tag := range d.Tags { for _, tag := range d.Tags {
if tag != buildImageTag { if tag != buildImageTag {