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,10 +10,12 @@ import ( ...@@ -10,10 +10,12 @@ import (
type Config struct { type Config struct {
common.PackerConfig `mapstructure:",squash"` common.PackerConfig `mapstructure:",squash"`
Registry string `mapstructure:"registry"` Repository string `mapstructure:"repository"`
Username string `mapstructure:"username"` Tag string `mapstructure:"tag"`
Password string `mapstructure:"password"` Registry string `mapstructure:"registry"`
Email string `mapstructure:"email"` Username string `mapstructure:"username"`
Password string `mapstructure:"password"`
Email string `mapstructure:"email"`
tpl *packer.ConfigTemplate tpl *packer.ConfigTemplate
} }
...@@ -38,8 +40,9 @@ func (p *PostProcessor) Configure(raws ...interface{}) error { ...@@ -38,8 +40,9 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
errs := new(packer.MultiError) errs := new(packer.MultiError)
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,10 +126,22 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac ...@@ -123,10 +126,22 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
} }
} }
cmd := exec.Command("docker", "push", id) if p.config.Tag != "" {
if err := cmd.Run(); err != nil {
ui.Say("Failed to push image: " + id) cmd := exec.Command("docker", "push", p.config.Repository+":"+p.config.Tag)
return nil, false, err 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 {
ui.Say("Failed to push image: " + id)
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