Commit c0174309 authored by Matthew McKeen's avatar Matthew McKeen

docker-push: add code to handle seperate registry, push a specific repository/tag #774

parent 358b0078
...@@ -10,6 +10,8 @@ import ( ...@@ -10,6 +10,8 @@ import (
type Config struct { type Config struct {
common.PackerConfig `mapstructure:",squash"` common.PackerConfig `mapstructure:",squash"`
Repository string `mapstructure:"repository"`
Tag string `mapstructure:"tag"`
Registry string `mapstructure:"registry"` Registry string `mapstructure:"registry"`
Username string `mapstructure:"username"` Username string `mapstructure:"username"`
Password string `mapstructure:"password"` Password string `mapstructure:"password"`
...@@ -40,6 +42,7 @@ func (p *PostProcessor) Configure(raws ...interface{}) error { ...@@ -40,6 +42,7 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
templates := map[string]*string{ templates := map[string]*string{
"username": &p.config.Username, "username": &p.config.Username,
"password": &p.config.Password, "password": &p.config.Password,
"repository": &p.config.Repository,
} }
for key, ptr := range templates { for key, ptr := range templates {
...@@ -123,11 +126,23 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac ...@@ -123,11 +126,23 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
} }
} }
cmd := exec.Command("docker", "push", id) if p.config.Tag != "" {
cmd := exec.Command("docker", "push", p.config.Repository+":"+p.config.Tag)
if err := cmd.Run(); err != nil {
ui.Say("Failed to push image: " + id)
return nil, false, err
}
} else {
cmd := exec.Command("docker", "push", p.config.Repository)
if err := cmd.Run(); err != nil { if err := cmd.Run(); err != nil {
ui.Say("Failed to push image: " + id) ui.Say("Failed to push image: " + id)
return nil, false, err return nil, false, err
} }
}
return nil, false, nil return nil, false, nil
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment