mirror of
https://github.com/thegeeklab/wp-docker-buildx.git
synced 2024-11-29 14:40:35 +00:00
Merge pull request #269 from Koma-Andrea/master [ci skip]
Added docker configuration
This commit is contained in:
commit
cc112b3ed0
@ -208,6 +208,11 @@ func main() {
|
||||
Usage: "docker email",
|
||||
EnvVar: "PLUGIN_EMAIL,DOCKER_EMAIL",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "docker.config",
|
||||
Usage: "docker json dockerconfig content",
|
||||
EnvVar: "PLUGIN_CONFIG",
|
||||
},
|
||||
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"),
|
||||
DockerConfig: c.String("docker.config"),
|
||||
},
|
||||
Build: docker.Build{
|
||||
Remote: c.String("remote.url"),
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
|
||||
const dockerExe = "/usr/local/bin/docker"
|
||||
const dockerdExe = "/usr/local/bin/dockerd"
|
||||
const dockerrootconfdir = "/root/.docker/"
|
||||
|
||||
func (p Plugin) startDaemon() {
|
||||
cmd := commandDaemon(p.Daemon)
|
||||
|
@ -4,6 +4,7 @@ package docker
|
||||
|
||||
const dockerExe = "C:\\bin\\docker.exe"
|
||||
const dockerdExe = ""
|
||||
const dockerrootconfdir = "C:\\ProgramData\\docker\"
|
||||
|
||||
func (p Plugin) startDaemon() {
|
||||
// this is a no-op on windows
|
||||
|
24
docker.go
24
docker.go
@ -6,6 +6,7 @@ import (
|
||||
"os/exec"
|
||||
"strings"
|
||||
"time"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
type (
|
||||
@ -32,6 +33,7 @@ type (
|
||||
Username string // Docker registry username
|
||||
Password string // Docker registry password
|
||||
Email string // Docker registry email
|
||||
DockerConfig string // Docker Auth Config
|
||||
}
|
||||
|
||||
// Build defines Docker build parameters.
|
||||
@ -83,6 +85,22 @@ func (p Plugin) Exec() error {
|
||||
time.Sleep(time.Second * 1)
|
||||
}
|
||||
|
||||
// Create Auth Config File
|
||||
if p.Login.DockerConfig != "" {
|
||||
fmt.Println("DockerConfig provided.")
|
||||
err_mkdir := os.MkdirAll(dockerrootconfdir, 0600)
|
||||
if err_mkdir != nil {
|
||||
fmt.Println("Error creating root's docker auth config directory: ")
|
||||
fmt.Println(err_mkdir)
|
||||
}
|
||||
conffile := fmt.Sprintf("%s%s", dockerrootconfdir, "config.json")
|
||||
err_mkconf := ioutil.WriteFile(conffile, []byte(p.Login.DockerConfig), 0600)
|
||||
if err_mkconf != nil {
|
||||
fmt.Println("Error creating root's docker auth configuration: ")
|
||||
fmt.Println(err_mkconf)
|
||||
}
|
||||
}
|
||||
|
||||
// login to the Docker registry
|
||||
if p.Login.Password != "" {
|
||||
cmd := commandLogin(p.Login)
|
||||
@ -90,8 +108,10 @@ func (p Plugin) Exec() error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error authenticating: %s", err)
|
||||
}
|
||||
} else {
|
||||
fmt.Println("Registry credentials not provided. Guest mode enabled.")
|
||||
}
|
||||
|
||||
if p.Login.Password != "" && p.Login.DockerConfig != "" {
|
||||
fmt.Println("Registry credentials or Docker config not provided. Guest mode enabled.")
|
||||
}
|
||||
|
||||
if p.Build.Squash && !p.Daemon.Experimental {
|
||||
|
Loading…
Reference in New Issue
Block a user