diff --git a/config.go b/config.go index 0056dae2e..7ebdcef66 100644 --- a/config.go +++ b/config.go @@ -43,7 +43,7 @@ const defaultConfig = ` "post-processors": { "vagrant": "packer-post-processor-vagrant", "vsphere": "packer-post-processor-vsphere", - "docker": "packer-post-processor-docker" + "docker-push": "packer-post-processor-docker-push" }, "provisioners": { diff --git a/plugin/post-processor-docker/main.go b/plugin/post-processor-docker-push/main.go similarity index 58% rename from plugin/post-processor-docker/main.go rename to plugin/post-processor-docker-push/main.go index 1e83f47f4..eb45b13bd 100644 --- a/plugin/post-processor-docker/main.go +++ b/plugin/post-processor-docker-push/main.go @@ -2,7 +2,7 @@ package main import ( "github.com/mitchellh/packer/packer/plugin" - "github.com/mitchellh/packer/post-processor/docker" + "github.com/mitchellh/packer/post-processor/docker-push" ) func main() { @@ -10,6 +10,6 @@ func main() { if err != nil { panic(err) } - server.RegisterPostProcessor(new(docker.PostProcessor)) + server.RegisterPostProcessor(new(dockerpush.PostProcessor)) server.Serve() } diff --git a/plugin/post-processor-docker/main_test.go b/plugin/post-processor-docker-push/main_test.go similarity index 100% rename from plugin/post-processor-docker/main_test.go rename to plugin/post-processor-docker-push/main_test.go diff --git a/post-processor/docker/post-processor.go b/post-processor/docker-push/post-processor.go similarity index 59% rename from post-processor/docker/post-processor.go rename to post-processor/docker-push/post-processor.go index a1698b238..64f893e6c 100644 --- a/post-processor/docker/post-processor.go +++ b/post-processor/docker-push/post-processor.go @@ -1,7 +1,6 @@ -package docker +package dockerpush import ( - "bytes" "errors" "github.com/mitchellh/mapstructure" "github.com/mitchellh/packer/packer" @@ -38,18 +37,38 @@ func (p *PostProcessor) Configure(raw ...interface{}) error { return nil } + func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (packer.Artifact, bool, error) { id := artifact.Id() - ui.Say("Pushing imgage: " + id) + ui.Say("Pushing image: " + id) + + if p.config.Email == "" { + cmd := exec.Command("docker", "login", + "-u=\""+p.config.Username+"\"", + "-p=\""+p.config.Password+"\"") + + if err := cmd.Run(); err != nil { + ui.Say("Login to the registry " + p.config.Registry + " failed") + return nil, false, err + } - // TODO: docker login + } else { + cmd := exec.Command("docker", + "login", + "-u=\""+p.config.Username+"\"", + "-p=\""+p.config.Password+"\"", + "-e=\""+p.config.Email+"\"") - stdout := new(bytes.Buffer) + if err := cmd.Run(); err != nil { + ui.Say("Login to the registry " + p.config.Registry + " failed") + return nil, false, err + } + + } cmd := exec.Command("docker", "push", id) - cmd.Stdout = stdout if err := cmd.Run(); err != nil { ui.Say("Failed to push image: " + id) - return nil, true, err + return nil, false, err } return nil, true, nil