Commit 56d22ac9 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

post-processor/docker-push: can login [GH-1243]

parent d32b4b4f
......@@ -23,6 +23,7 @@ FEATURES:
* builder/vmware: VMware Player 6 is now supported. [GH-1168]
* builder/vmware-vmx: Boot commands and the HTTP server are supported.
[GH-1169]
* post-processor/docker-push: Can now specify login credentials. [GH-1243]
IMPROVEMENTS:
......
......@@ -32,10 +32,12 @@ sudo apt-get install -y curl git-core zip
SCRIPT
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "chef/ubuntu-14.04"
config.vm.box = "chef/ubuntu-12.04"
config.vm.provision "shell", inline: $script
config.vm.synced_folder ".", "/vagrant", disabled: true
["vmware_fusion", "vmware_workstation"].each do |p|
config.vm.provider "p" do |v|
v.vmx["memsize"] = "2048"
......
......@@ -12,6 +12,12 @@ import (
type Config struct {
common.PackerConfig `mapstructure:",squash"`
Login bool
LoginEmail string `mapstructure:"login_email"`
LoginUsername string `mapstructure:"login_username"`
LoginPassword string `mapstructure:"login_password"`
LoginServer string `mapstructure:"login_server"`
tpl *packer.ConfigTemplate
}
......@@ -35,6 +41,24 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
// Accumulate any errors
errs := new(packer.MultiError)
// Process templates
templates := map[string]*string{
"login_email": &p.config.LoginEmail,
"login_username": &p.config.LoginUsername,
"login_password": &p.config.LoginPassword,
"login_server": &p.config.LoginServer,
}
for n, ptr := range templates {
var err error
*ptr, err = p.config.tpl.Process(*ptr, nil)
if err != nil {
errs = packer.MultiErrorAppend(
errs, fmt.Errorf("Error processing %s: %s", n, err))
}
}
if len(errs.Errors) > 0 {
return errs
}
......@@ -56,6 +80,26 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
driver = &docker.DockerDriver{Tpl: p.config.tpl, Ui: ui}
}
if p.config.Login {
ui.Message("Logging in...")
err := driver.Login(
p.config.LoginServer,
p.config.LoginEmail,
p.config.LoginUsername,
p.config.LoginPassword)
if err != nil {
return nil, false, fmt.Errorf(
"Error logging in to Docker: %s", err)
}
defer func() {
ui.Message("Logging out...")
if err := driver.Logout(p.config.LoginServer); err != nil {
ui.Error(fmt.Sprintf("Error logging out: %s", err))
}
}()
}
// Get the name. We strip off any tags from the name because the
// push doesn't use those.
name := artifact.Id()
......
......@@ -19,8 +19,18 @@ for you, but for now you must manually do this.
## Configuration
This post-processor has no configuration! Simply add it to your chain
of post-processors and the image will be uploaded.
This post-processor has only optional configuration:
* `login` (boolean) - Defaults to false. If true, the post-processor will
login prior to pushing.
* `login_email` (string) - The email to use to authenticate to login.
* `login_username` (string) - The username to use to authenticate to login.
* `login_password` (string) - The password to use to authenticate to login.
* `login_server` (string) - The server address to login to.
## Example
......
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