0
0
mirror of https://github.com/thegeeklab/wp-docker-buildx.git synced 2024-11-12 16:20:41 +00:00

Added AuthConfig to login to multiple registry

This commit is contained in:
Andrea Cervesato 2020-03-24 19:20:52 +01:00
parent 1f0cfcc3ef
commit 18c4e995d3
2 changed files with 45 additions and 9 deletions

View File

@ -208,6 +208,11 @@ func main() {
Usage: "docker email",
EnvVar: "PLUGIN_EMAIL,DOCKER_EMAIL",
},
cli.StringFlag{
Name: "docker.authconfig",
Usage: "docker json authconfig content",
EnvVar: "PLUGIN_AUTHCONFIG,DOCKER_AUTHCONFIG",
},
cli.BoolTFlag{
Name: "docker.purge",
Usage: "docker should cleanup images",
@ -240,10 +245,11 @@ func run(c *cli.Context) error {
Dryrun: c.Bool("dry-run"),
Cleanup: c.BoolT("docker.purge"),
Login: docker.Login{
Registry: c.String("docker.registry"),
Username: c.String("docker.username"),
Password: c.String("docker.password"),
Email: c.String("docker.email"),
Registry: c.String("docker.registry"),
Username: c.String("docker.username"),
Password: c.String("docker.password"),
Email: c.String("docker.email"),
AuthConfig: c.String("docker.authconfig"),
},
Build: docker.Build{
Remote: c.String("remote.url"),

View File

@ -28,10 +28,11 @@ type (
// Login defines Docker login parameters.
Login struct {
Registry string // Docker registry address
Username string // Docker registry username
Password string // Docker registry password
Email string // Docker registry email
Registry string // Docker registry address
Username string // Docker registry username
Password string // Docker registry password
Email string // Docker registry email
AuthConfig string // Docker Auth Config
}
// Build defines Docker build parameters.
@ -83,6 +84,35 @@ func (p Plugin) Exec() error {
time.Sleep(time.Second * 1)
}
// Create Auth Config File
if p.Login.AuthConfig != "" {
fmt.Println("AuthConfig provided.")
err_mkdir := os.MkdirAll("/root/.docker", 0600)
if err_mkdir != nil {
fmt.Println("Error creating root's docker auth config directory: ")
fmt.Println(err_mkdir)
}
cfile, err_create := os.Create("/root/.docker/config.json")
if err_create != nil {
fmt.Println("Error creating root's docker auth config file: ")
fmt.Println(err_create)
cfile.Close()
}
err_chmod := os.Chmod("/root/.docker/config.json", 0600)
if err_chmod != nil {
fmt.Println("Error setting permissions on root's docker auth config file: ")
fmt.Println(err_chmod)
}
_, err_str := cfile.WriteString(p.Login.AuthConfig)
if err_str != nil {
fmt.Println("Error filling root's docker auth config file: ")
fmt.Println(err_str)
} else {
cfile.Close()
}
}
// login to the Docker registry
if p.Login.Password != "" {
cmd := commandLogin(p.Login)
@ -93,7 +123,7 @@ func (p Plugin) Exec() error {
} else {
fmt.Println("Registry credentials not provided. Guest mode enabled.")
}
if p.Build.Squash && !p.Daemon.Experimental {
fmt.Println("Squash build flag is only available when Docker deamon is started with experimental flag. Ignoring...")
p.Build.Squash = false