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/sirupsen/logrus"
"github.com/urfave/cli" "github.com/urfave/cli"
"github.com/drone-plugins/drone-docker" docker "github.com/drone-plugins/drone-docker"
) )
var ( var (
@ -245,11 +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"), Config: c.String("docker.config"),
}, },
Build: docker.Build{ Build: docker.Build{
Remote: c.String("remote.url"), Remote: c.String("remote.url"),

View File

@ -9,7 +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/" const dockerHome = "/root/.docker/"
func (p Plugin) startDaemon() { func (p Plugin) startDaemon() {
cmd := commandDaemon(p.Daemon) cmd := commandDaemon(p.Daemon)

View File

@ -2,11 +2,12 @@ package docker
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
"path/filepath"
"strings" "strings"
"time" "time"
"io/ioutil"
) )
type ( type (
@ -29,11 +30,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 Config string // Docker Auth Config
} }
// Build defines Docker build parameters. // Build defines Docker build parameters.
@ -86,18 +87,13 @@ func (p Plugin) Exec() error {
} }
// Create Auth Config File // Create Auth Config File
if p.Login.DockerConfig != "" { if p.Login.Config != "" {
fmt.Println("DockerConfig provided.") os.MkdirAll(dockerHome, 0600)
err_mkdir := os.MkdirAll(dockerrootconfdir, 0600)
if err_mkdir != nil { path := filepath.Join(dockerHome, "config.json")
fmt.Println("Error creating root's docker auth config directory: ") err := ioutil.WriteFile(path, []byte(p.Login.Config), 0600)
fmt.Println(err_mkdir) if err != nil {
} return fmt.Errorf("Error writeing config.json: %s", err)
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)
} }
} }
@ -110,7 +106,12 @@ func (p Plugin) Exec() error {
} }
} }
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.") fmt.Println("Registry credentials or Docker config not provided. Guest mode enabled.")
} }