0
0
mirror of https://github.com/thegeeklab/wp-docker-buildx.git synced 2024-11-25 09:10:39 +00:00

enable fallback secret names [ci skip]

This commit is contained in:
Brad Rydzewski 2017-08-27 12:57:23 -07:00
parent da903e4d81
commit f25b013937
2 changed files with 38 additions and 20 deletions

View File

@ -8,12 +8,19 @@ import (
"strings"
)
// gcr default username
const username = "_json_key"
func main() {
var (
username = "_json_key"
password = os.Getenv("GCR_TOKEN")
registry = os.Getenv("PLUGIN_REGISTRY")
repo = os.Getenv("PLUGIN_REPO")
repo = getenv("PLUGIN_REPO")
registry = getenv("PLUGIN_REGISTRY")
password = getenv(
"PLUGIN_JSON_KEY",
"GCR_JSON_KEY",
"GOOGLE_CREDENTIALS",
"GOOGLE_APPLICATION_CREDENTIALS",
)
)
// decode the token if base64 encoded
@ -32,9 +39,9 @@ func main() {
// should prepend.
if !strings.HasPrefix(repo, registry) {
repo = path.Join(registry, repo)
os.Setenv("PLUGIN_REPO", repo)
}
os.Setenv("PLUGIN_REPO", repo)
os.Setenv("PLUGIN_REGISTRY", registry)
os.Setenv("DOCKER_USERNAME", username)
os.Setenv("DOCKER_PASSWORD", password)
@ -48,3 +55,13 @@ func main() {
os.Exit(1)
}
}
func getenv(key ...string) (s string) {
for _, k := range key {
s = os.Getenv(k)
if s != "" {
return
}
}
return
}

View File

@ -9,22 +9,14 @@ import (
func main() {
var (
registry = "registry.heroku.com"
process = os.Getenv("PLUGIN_PROCESS_TYPE")
app = os.Getenv("PLUGIN_APP")
email = os.Getenv("PLUGIN_EMAIL")
key = os.Getenv("PLUGIN_API_KEY")
process = getenv("PLUGIN_PROCESS_TYPE")
app = getenv("PLUGIN_APP")
email = getenv("PLUGIN_EMAIL", "HEROKU_EMAIL")
key = getenv("PLUGIN_API_KEY", "HEROKU_API_KEY")
)
// if the heroku email is provided as a named secret
// then we should use it.
if os.Getenv("HEROKU_EMAIL") != "" {
email = os.Getenv("HEROKU_EMAIL")
}
// if the heroku api key is provided as a named secret
// then we should use it.
if os.Getenv("HEROKU_API_KEY") != "" {
key = os.Getenv("HEROKU_API_KEY")
if process == "" {
process = "web"
}
os.Setenv("PLUGIN_REGISTRY", registry)
@ -34,7 +26,6 @@ func main() {
os.Setenv("DOCKER_USERNAME", email)
os.Setenv("DOCKER_EMAIL", email)
// invoke the base docker plugin binary
cmd := exec.Command("drone-docker")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
@ -43,3 +34,13 @@ func main() {
os.Exit(1)
}
}
func getenv(key ...string) (s string) {
for _, k := range key {
s = os.Getenv(k)
if s != "" {
return
}
}
return
}