Merge pull request #5511 from hashicorp/fix5507
remove login_email from docker
This commit is contained in:
commit
0172a5c82b
|
@ -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"`
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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",
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.`
|
||||
}
|
|
@ -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 {
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
Loading…
Reference in New Issue