Added AuthConfig to login to multiple registry
This commit is contained in:
parent
1f0cfcc3ef
commit
18c4e995d3
@ -208,6 +208,11 @@ func main() {
|
|||||||
Usage: "docker email",
|
Usage: "docker email",
|
||||||
EnvVar: "PLUGIN_EMAIL,DOCKER_EMAIL",
|
EnvVar: "PLUGIN_EMAIL,DOCKER_EMAIL",
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "docker.authconfig",
|
||||||
|
Usage: "docker json authconfig content",
|
||||||
|
EnvVar: "PLUGIN_AUTHCONFIG,DOCKER_AUTHCONFIG",
|
||||||
|
},
|
||||||
cli.BoolTFlag{
|
cli.BoolTFlag{
|
||||||
Name: "docker.purge",
|
Name: "docker.purge",
|
||||||
Usage: "docker should cleanup images",
|
Usage: "docker should cleanup images",
|
||||||
@ -240,10 +245,11 @@ func run(c *cli.Context) error {
|
|||||||
Dryrun: c.Bool("dry-run"),
|
Dryrun: c.Bool("dry-run"),
|
||||||
Cleanup: c.BoolT("docker.purge"),
|
Cleanup: c.BoolT("docker.purge"),
|
||||||
Login: docker.Login{
|
Login: docker.Login{
|
||||||
Registry: c.String("docker.registry"),
|
Registry: c.String("docker.registry"),
|
||||||
Username: c.String("docker.username"),
|
Username: c.String("docker.username"),
|
||||||
Password: c.String("docker.password"),
|
Password: c.String("docker.password"),
|
||||||
Email: c.String("docker.email"),
|
Email: c.String("docker.email"),
|
||||||
|
AuthConfig: c.String("docker.authconfig"),
|
||||||
},
|
},
|
||||||
Build: docker.Build{
|
Build: docker.Build{
|
||||||
Remote: c.String("remote.url"),
|
Remote: c.String("remote.url"),
|
||||||
|
38
docker.go
38
docker.go
@ -28,10 +28,11 @@ type (
|
|||||||
|
|
||||||
// Login defines Docker login parameters.
|
// Login defines Docker login parameters.
|
||||||
Login struct {
|
Login struct {
|
||||||
Registry string // Docker registry address
|
Registry string // Docker registry address
|
||||||
Username string // Docker registry username
|
Username string // Docker registry username
|
||||||
Password string // Docker registry password
|
Password string // Docker registry password
|
||||||
Email string // Docker registry email
|
Email string // Docker registry email
|
||||||
|
AuthConfig string // Docker Auth Config
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build defines Docker build parameters.
|
// Build defines Docker build parameters.
|
||||||
@ -83,6 +84,35 @@ func (p Plugin) Exec() error {
|
|||||||
time.Sleep(time.Second * 1)
|
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
|
// login to the Docker registry
|
||||||
if p.Login.Password != "" {
|
if p.Login.Password != "" {
|
||||||
cmd := commandLogin(p.Login)
|
cmd := commandLogin(p.Login)
|
||||||
|
Loading…
Reference in New Issue
Block a user