Compare commits

...

7 Commits

Author SHA1 Message Date
Brad Rydzewski f2aeb0f7fc fix docker home path on windows 2020-03-24 14:34:54 -07:00
Brad Rydzewski 9488d3352e fix docker home const for windows 2020-03-24 14:15:07 -07:00
Brad Rydzewski 528dc0a7b3 update config.json messaging 2020-03-24 13:49:10 -07:00
Brad Rydzewski cc112b3ed0 Merge pull request #269 from Koma-Andrea/master [ci skip]
Added docker configuration
2020-03-24 13:43:43 -07:00
Brad Rydzewski 122443b3e6 minor variable name change 2020-03-24 13:40:35 -07:00
Andrea Cervesato 063f479004 Using more generic configuration & respecting win 2020-03-24 21:00:24 +01:00
Andrea Cervesato 18c4e995d3 Added AuthConfig to login to multiple registry 2020-03-24 19:20:52 +01:00
4 changed files with 33 additions and 4 deletions
+7 -1
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 (
@@ -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"),
Config: c.String("docker.config"),
},
Build: docker.Build{
Remote: c.String("remote.url"),
+2 -1
View File
@@ -9,6 +9,7 @@ import (
const dockerExe = "/usr/local/bin/docker"
const dockerdExe = "/usr/local/bin/dockerd"
const dockerHome = "/root/.docker/"
func (p Plugin) startDaemon() {
cmd := commandDaemon(p.Daemon)
@@ -23,4 +24,4 @@ func (p Plugin) startDaemon() {
trace(cmd)
cmd.Run()
}()
}
}
+1
View File
@@ -4,6 +4,7 @@ package docker
const dockerExe = "C:\\bin\\docker.exe"
const dockerdExe = ""
const dockerHome = "C:\\ProgramData\\docker\\"
func (p Plugin) startDaemon() {
// this is a no-op on windows
+23 -2
View File
@@ -2,8 +2,10 @@ package docker
import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"strings"
"time"
)
@@ -32,6 +34,7 @@ type (
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.
@@ -83,6 +86,17 @@ func (p Plugin) Exec() error {
time.Sleep(time.Second * 1)
}
// Create Auth Config File
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)
}
}
// login to the Docker registry
if p.Login.Password != "" {
cmd := commandLogin(p.Login)
@@ -90,8 +104,15 @@ 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.")
}
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 {