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",
@ -244,6 +249,7 @@ func run(c *cli.Context) error {
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

@ -32,6 +32,7 @@ type (
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)