Merge branch 'master' into master

This commit is contained in:
Thomas Boerger 2020-04-16 09:24:34 +02:00 committed by GitHub
commit 65bb87f497
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 4 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 (
@ -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"),

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)

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

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 {