From 5b07ef5ffe9d27b62a2071b4c9546d053a34c11a Mon Sep 17 00:00:00 2001 From: Kirill Zaitsev Date: Sat, 20 Dec 2014 17:26:33 +0300 Subject: [PATCH] Automatically detect ENV variables --- cli/build.go | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/cli/build.go b/cli/build.go index 5dd6f77f..c14fb09f 100644 --- a/cli/build.go +++ b/cli/build.go @@ -43,17 +43,17 @@ func NewBuildCommand() cli.Command { }, cli.StringFlag{ Name: "docker-host", - Value: "", + Value: getHost(), Usage: "docker daemon address", }, cli.StringFlag{ Name: "docker-cert", - Value: "", + Value: getCert(), Usage: "docker daemon tls certificate", }, cli.StringFlag{ Name: "docker-key", - Value: "", + Value: getKey(), Usage: "docker daemon tls key", }, }, @@ -204,3 +204,23 @@ func run(path, identity, dockerhost, dockercert, dockerkey string, publish, depl return builder.BuildState.ExitCode, nil } + +func getHost() string { + return os.Getenv("DOCKER_HOST") +} + +func getCert() string { + if os.Getenv("DOCKER_CERT_PATH") != "" && os.Getenv("DOCKER_TLS_VERIFY") == "1" { + return filepath.Join(os.Getenv("DOCKER_CERT_PATH"), "cert.pem") + } else { + return "" + } +} + +func getKey() string { + if os.Getenv("DOCKER_CERT_PATH") != "" && os.Getenv("DOCKER_TLS_VERIFY") == "1" { + return filepath.Join(os.Getenv("DOCKER_CERT_PATH"), "key.pem") + } else { + return "" + } +}