Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically detect ENV variables #765

Merged
merged 1 commit into from
Dec 27, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Automatically detect ENV variables
  • Loading branch information
kzaitsev committed Dec 27, 2014
commit 5b07ef5ffe9d27b62a2071b4c9546d053a34c11a
26 changes: 23 additions & 3 deletions cli/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
Expand Down Expand Up @@ -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")
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be simplified to the following:

func getHost() string {
   return os.Getenv("DOCKER_HOST")
}

since Getenv will return an empty string if the environment variable doesn't exist :)


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 ""
}
}