update config.json messaging

This commit is contained in:
Brad Rydzewski 2020-03-24 13:49:10 -07:00
parent cc112b3ed0
commit 528dc0a7b3
3 changed files with 30 additions and 29 deletions

View File

@ -7,7 +7,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"github.com/drone-plugins/drone-docker"
docker "github.com/drone-plugins/drone-docker"
)
var (
@ -245,11 +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"),
DockerConfig: c.String("docker.config"),
Registry: c.String("docker.registry"),
Username: c.String("docker.username"),
Password: c.String("docker.password"),
Email: c.String("docker.email"),
Config: c.String("docker.config"),
},
Build: docker.Build{
Remote: c.String("remote.url"),

View File

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

View File

@ -2,11 +2,12 @@ package docker
import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"strings"
"time"
"io/ioutil"
)
type (
@ -29,11 +30,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
DockerConfig string // Docker Auth Config
Registry string // Docker registry address
Username string // Docker registry username
Password string // Docker registry password
Email string // Docker registry email
Config string // Docker Auth Config
}
// Build defines Docker build parameters.
@ -86,18 +87,13 @@ func (p Plugin) Exec() error {
}
// 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)
if p.Login.Config != "" {
os.MkdirAll(dockerHome, 0600)
path := filepath.Join(dockerHome, "config.json")
err := ioutil.WriteFile(path, []byte(p.Login.Config), 0600)
if err != nil {
return fmt.Errorf("Error writeing config.json: %s", err)
}
}
@ -108,12 +104,17 @@ func (p Plugin) Exec() error {
if err != nil {
return fmt.Errorf("Error authenticating: %s", err)
}
}
}
if p.Login.Password != "" && p.Login.DockerConfig != "" {
switch {
case p.Login.Password != "":
fmt.Println("Detected registry credentials")
case p.Login.Config != "":
fmt.Println("Detected registry credentials file")
default:
fmt.Println("Registry credentials or Docker config 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