2017-08-27 19:27:28 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"path"
|
2020-08-05 15:28:21 +00:00
|
|
|
|
|
|
|
"github.com/joho/godotenv"
|
2017-08-27 19:27:28 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2020-08-05 15:28:21 +00:00
|
|
|
// Load env-file if it exists first
|
|
|
|
if env := os.Getenv("PLUGIN_ENV_FILE"); env != "" {
|
|
|
|
godotenv.Load(env)
|
|
|
|
}
|
|
|
|
|
2017-08-27 19:27:28 +00:00
|
|
|
var (
|
|
|
|
registry = "registry.heroku.com"
|
2017-08-27 19:57:23 +00:00
|
|
|
process = getenv("PLUGIN_PROCESS_TYPE")
|
|
|
|
app = getenv("PLUGIN_APP")
|
|
|
|
email = getenv("PLUGIN_EMAIL", "HEROKU_EMAIL")
|
|
|
|
key = getenv("PLUGIN_API_KEY", "HEROKU_API_KEY")
|
2017-08-27 19:27:28 +00:00
|
|
|
)
|
|
|
|
|
2017-08-27 19:57:23 +00:00
|
|
|
if process == "" {
|
|
|
|
process = "web"
|
2017-08-27 19:27:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
os.Setenv("PLUGIN_REGISTRY", registry)
|
|
|
|
os.Setenv("PLUGIN_REPO", path.Join(registry, app, process))
|
|
|
|
|
|
|
|
os.Setenv("DOCKER_PASSWORD", key)
|
|
|
|
os.Setenv("DOCKER_USERNAME", email)
|
|
|
|
os.Setenv("DOCKER_EMAIL", email)
|
|
|
|
|
|
|
|
cmd := exec.Command("drone-docker")
|
|
|
|
cmd.Stdout = os.Stdout
|
|
|
|
cmd.Stderr = os.Stderr
|
|
|
|
err := cmd.Run()
|
|
|
|
if err != nil {
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|
2017-08-27 19:57:23 +00:00
|
|
|
|
|
|
|
func getenv(key ...string) (s string) {
|
|
|
|
for _, k := range key {
|
|
|
|
s = os.Getenv(k)
|
|
|
|
if s != "" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|