Merge pull request #269 from Koma-Andrea/master [ci skip]

Added docker configuration
This commit is contained in:
Brad Rydzewski 2020-03-24 13:43:43 -07:00 committed by GitHub
commit cc112b3ed0
Signed by: GitHub
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 11 deletions

@ -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.config",
Usage: "docker json dockerconfig content",
EnvVar: "PLUGIN_CONFIG",
},
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"),
DockerConfig: c.String("docker.config"),
}, },
Build: docker.Build{ Build: docker.Build{
Remote: c.String("remote.url"), Remote: c.String("remote.url"),

@ -9,6 +9,7 @@ import (
const dockerExe = "/usr/local/bin/docker" const dockerExe = "/usr/local/bin/docker"
const dockerdExe = "/usr/local/bin/dockerd" const dockerdExe = "/usr/local/bin/dockerd"
const dockerrootconfdir = "/root/.docker/"
func (p Plugin) startDaemon() { func (p Plugin) startDaemon() {
cmd := commandDaemon(p.Daemon) cmd := commandDaemon(p.Daemon)

@ -4,6 +4,7 @@ package docker
const dockerExe = "C:\\bin\\docker.exe" const dockerExe = "C:\\bin\\docker.exe"
const dockerdExe = "" const dockerdExe = ""
const dockerrootconfdir = "C:\\ProgramData\\docker\"
func (p Plugin) startDaemon() { func (p Plugin) startDaemon() {
// this is a no-op on windows // this is a no-op on windows

@ -6,6 +6,7 @@ import (
"os/exec" "os/exec"
"strings" "strings"
"time" "time"
"io/ioutil"
) )
type ( type (
@ -28,10 +29,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
DockerConfig string // Docker Auth Config
} }
// Build defines Docker build parameters. // Build defines Docker build parameters.
@ -83,6 +85,22 @@ func (p Plugin) Exec() error {
time.Sleep(time.Second * 1) 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 // login to the Docker registry
if p.Login.Password != "" { if p.Login.Password != "" {
cmd := commandLogin(p.Login) cmd := commandLogin(p.Login)
@ -90,10 +108,12 @@ func (p Plugin) Exec() error {
if err != nil { if err != nil {
return fmt.Errorf("Error authenticating: %s", err) 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 { if p.Build.Squash && !p.Daemon.Experimental {
fmt.Println("Squash build flag is only available when Docker deamon is started with experimental flag. Ignoring...") fmt.Println("Squash build flag is only available when Docker deamon is started with experimental flag. Ignoring...")
p.Build.Squash = false p.Build.Squash = false