diff --git a/builder/docker/config.go b/builder/docker/config.go index fee08929d..6116a995b 100644 --- a/builder/docker/config.go +++ b/builder/docker/config.go @@ -42,7 +42,6 @@ type Config struct { // This is used to login to dockerhub to pull a private base container. For // pushing to dockerhub, see the docker post-processors Login bool - LoginEmail string `mapstructure:"login_email"` LoginPassword string `mapstructure:"login_password"` LoginServer string `mapstructure:"login_server"` LoginUsername string `mapstructure:"login_username"` diff --git a/builder/docker/driver.go b/builder/docker/driver.go index 0eda0a604..09da054f3 100644 --- a/builder/docker/driver.go +++ b/builder/docker/driver.go @@ -28,7 +28,7 @@ type Driver interface { // Login. This will lock the driver from performing another Login // until Logout is called. Therefore, any users MUST call Logout. - Login(repo, email, username, password string) error + Login(repo, username, password string) error // Logout. This can only be called if Login succeeded. Logout(repo string) error diff --git a/builder/docker/driver_docker.go b/builder/docker/driver_docker.go index 61c5ad93e..c3db3dda6 100644 --- a/builder/docker/driver_docker.go +++ b/builder/docker/driver_docker.go @@ -147,13 +147,10 @@ func (d *DockerDriver) IPAddress(id string) (string, error) { return strings.TrimSpace(stdout.String()), nil } -func (d *DockerDriver) Login(repo, email, user, pass string) error { +func (d *DockerDriver) Login(repo, user, pass string) error { d.l.Lock() args := []string{"login"} - if email != "" { - args = append(args, "-e", email) - } if user != "" { args = append(args, "-u", user) } diff --git a/builder/docker/driver_mock.go b/builder/docker/driver_mock.go index 57a02b691..5193f21ee 100644 --- a/builder/docker/driver_mock.go +++ b/builder/docker/driver_mock.go @@ -29,7 +29,6 @@ type MockDriver struct { IPAddressErr error LoginCalled bool - LoginEmail string LoginUsername string LoginPassword string LoginRepo string @@ -115,10 +114,9 @@ func (d *MockDriver) IPAddress(id string) (string, error) { return d.IPAddressResult, d.IPAddressErr } -func (d *MockDriver) Login(r, e, u, p string) error { +func (d *MockDriver) Login(r, u, p string) error { d.LoginCalled = true d.LoginRepo = r - d.LoginEmail = e d.LoginUsername = u d.LoginPassword = p return d.LoginErr diff --git a/builder/docker/step_pull.go b/builder/docker/step_pull.go index 9e38f7b49..6b1ac8935 100644 --- a/builder/docker/step_pull.go +++ b/builder/docker/step_pull.go @@ -2,9 +2,10 @@ package docker import ( "fmt" + "log" + "github.com/hashicorp/packer/packer" "github.com/mitchellh/multistep" - "log" ) type StepPull struct{} @@ -40,7 +41,6 @@ func (s *StepPull) Run(state multistep.StateBag) multistep.StepAction { ui.Message("Logging in...") err := driver.Login( config.LoginServer, - config.LoginEmail, config.LoginUsername, config.LoginPassword) if err != nil { diff --git a/fix/fixer.go b/fix/fixer.go index 938a7160f..5ca0b3a18 100644 --- a/fix/fixer.go +++ b/fix/fixer.go @@ -33,6 +33,7 @@ func init() { "manifest-filename": new(FixerManifestFilename), "amazon-shutdown_behavior": new(FixerAmazonShutdownBehavior), "amazon-enhanced-networking": new(FixerAmazonEnhancedNetworking), + "docker-email": new(FixerDockerEmail), } FixerOrder = []string{ @@ -49,5 +50,6 @@ func init() { "manifest-filename", "amazon-shutdown_behavior", "amazon-enhanced-networking", + "docker-email", } } diff --git a/fix/fixer_docker_email.go b/fix/fixer_docker_email.go new file mode 100644 index 000000000..d1402d3bd --- /dev/null +++ b/fix/fixer_docker_email.go @@ -0,0 +1,45 @@ +package fix + +import "github.com/mitchellh/mapstructure" + +type FixerDockerEmail struct{} + +func (FixerDockerEmail) Fix(input map[string]interface{}) (map[string]interface{}, error) { + // Our template type we'll use for this fixer only + type template struct { + Builders []map[string]interface{} + PostProcessors []map[string]interface{} `mapstructure:"post-processors"` + } + + // Decode the input into our structure, if we can + var tpl template + if err := mapstructure.Decode(input, &tpl); err != nil { + return nil, err + } + + // Go through each builder and delete `docker_login` if present + for _, builder := range tpl.Builders { + _, ok := builder["login_email"] + if !ok { + continue + } + delete(builder, "login_email") + } + + // Go through each post-processor and delete `docker_login` if present + for _, pp := range tpl.PostProcessors { + _, ok := pp["login_email"] + if !ok { + continue + } + delete(pp, "login_email") + } + + input["builders"] = tpl.Builders + input["post-processors"] = tpl.PostProcessors + return input, nil +} + +func (FixerDockerEmail) Synopsis() string { + return `Removes "login_email" from the Docker builder.` +} diff --git a/post-processor/docker-push/post-processor.go b/post-processor/docker-push/post-processor.go index 5d44cecf0..f0fee00ca 100644 --- a/post-processor/docker-push/post-processor.go +++ b/post-processor/docker-push/post-processor.go @@ -16,7 +16,6 @@ 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"` @@ -81,7 +80,6 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac ui.Message("Logging in...") err := driver.Login( p.config.LoginServer, - p.config.LoginEmail, p.config.LoginUsername, p.config.LoginPassword) if err != nil { diff --git a/website/source/docs/builders/docker.html.md b/website/source/docs/builders/docker.html.md index 951860971..13c43da60 100644 --- a/website/source/docs/builders/docker.html.md +++ b/website/source/docs/builders/docker.html.md @@ -185,8 +185,6 @@ You must specify (only) one of `commit`, `discard`, or `export_path`. order to pull the image. The builder only logs in for the duration of the pull. It always logs out afterwards. For log into ECR see `ecr_login`. -- `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. diff --git a/website/source/docs/post-processors/docker-push.html.md b/website/source/docs/post-processors/docker-push.html.md index 5400cb56a..f151c30ff 100644 --- a/website/source/docs/post-processors/docker-push.html.md +++ b/website/source/docs/post-processors/docker-push.html.md @@ -43,16 +43,14 @@ This post-processor has only optional configuration: - `login` (boolean) - Defaults to false. If true, the post-processor will login prior to pushing. For log into ECR see `ecr_login`. -- `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. -Note: When using *Docker Hub* or *Quay* registry servers, `login` must to be -set to `true` and `login_email`, `login_username`, **and** `login_password` +-> **Note:** When using *Docker Hub* or *Quay* registry servers, `login` must to be +set to `true` and `login_username`, **and** `login_password` must to be set to your registry credentials. When using Docker Hub, `login_server` can be omitted.