added --insecure-registry flag

This commit is contained in:
Brad Rydzewski 2015-09-02 22:14:57 -07:00
parent b95a703ab3
commit be274cf2e9

40
main.go
View File

@ -14,6 +14,7 @@ import (
type Docker struct { type Docker struct {
Storage string `json:"storage_driver"` Storage string `json:"storage_driver"`
Registry string `json:"registry"` Registry string `json:"registry"`
Insecure bool `json:"insecure"`
Username string `json:"username"` Username string `json:"username"`
Password string `json:"password"` Password string `json:"password"`
Email string `json:"email"` Email string `json:"email"`
@ -54,7 +55,13 @@ func main() {
cmd.Stderr = ioutil.Discard cmd.Stderr = ioutil.Discard
cmd.Run() cmd.Run()
cmd = exec.Command("docker", "-d", "-s", vargs.Storage) args := []string{"-d", "-s", vargs.Storage}
if vargs.Insecure && len(vargs.Registry) != 0 {
args = append(args, "--insecure-registry", vargs.Registry)
}
cmd = exec.Command("docker", args...)
cmd.Stdout = ioutil.Discard cmd.Stdout = ioutil.Discard
cmd.Stderr = ioutil.Discard cmd.Stderr = ioutil.Discard
trace(cmd) trace(cmd)
@ -73,29 +80,28 @@ func main() {
vargs.File = "." vargs.File = "."
} }
// Set the Tag value // Set the Tag value
switch vargs.Tag { if len(vargs.Tag) == 0 {
case "$DRONE_BRANCH":
vargs.Tag = build.Commit.Branch
case "$DRONE_COMMIT":
vargs.Tag = build.Commit.Sha
case "":
vargs.Tag = "latest" vargs.Tag = "latest"
} }
vargs.Repo = fmt.Sprintf("%s:%s", vargs.Repo, vargs.Tag) vargs.Repo = fmt.Sprintf("%s:%s", vargs.Repo, vargs.Tag)
// Login to Docker // Login to Docker
cmd := exec.Command("docker", "login", "-u", vargs.Username, "-p", vargs.Password, "-e", vargs.Email, vargs.Registry) if len(vargs.Username) != 0 {
cmd.Dir = workspace.Path cmd := exec.Command("docker", "login", "-u", vargs.Username, "-p", vargs.Password, "-e", vargs.Email, vargs.Registry)
cmd.Stdout = os.Stdout cmd.Dir = workspace.Path
cmd.Stderr = os.Stderr cmd.Stdout = os.Stdout
err := cmd.Run() cmd.Stderr = os.Stderr
if err != nil { err := cmd.Run()
stop() if err != nil {
os.Exit(1) stop()
os.Exit(1)
}
} else {
fmt.Printf("A username was not specified. Assuming anoynmous publishing.\n")
} }
// Docker environment info // Docker environment info
cmd = exec.Command("docker", "version") cmd := exec.Command("docker", "version")
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr
trace(cmd) trace(cmd)
@ -112,7 +118,7 @@ func main() {
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr
trace(cmd) trace(cmd)
err = cmd.Run() err := cmd.Run()
if err != nil { if err != nil {
stop() stop()
os.Exit(1) os.Exit(1)