publish/docker: login should happen early

This fixes an issue where base image which drone is using to build an
image for publishing comes from a private repo.
This commit is contained in:
Vaidas Jablonskis 2015-04-17 16:21:09 +01:00
parent af9c1e9bd7
commit 009e8a1dce

View file

@ -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)
@ -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 {