2019-03-28 11:20:36 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"strings"
|
2020-08-05 17:28:21 +02:00
|
|
|
|
|
|
|
"github.com/joho/godotenv"
|
2022-01-12 18:02:57 +01:00
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
|
|
|
|
docker "github.com/drone-plugins/drone-docker"
|
2019-03-28 11:20:36 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2020-08-05 17:28:21 +02:00
|
|
|
// Load env-file if it exists first
|
|
|
|
if env := os.Getenv("PLUGIN_ENV_FILE"); env != "" {
|
|
|
|
godotenv.Load(env)
|
|
|
|
}
|
|
|
|
|
2019-03-28 11:20:36 +01:00
|
|
|
var (
|
|
|
|
repo = getenv("PLUGIN_REPO")
|
|
|
|
registry = getenv("PLUGIN_REGISTRY")
|
|
|
|
username = getenv("SERVICE_PRINCIPAL_CLIENT_ID")
|
|
|
|
password = getenv("SERVICE_PRINCIPAL_CLIENT_SECRET")
|
|
|
|
)
|
|
|
|
|
|
|
|
// default registry value
|
|
|
|
if registry == "" {
|
|
|
|
registry = "azurecr.io"
|
|
|
|
}
|
|
|
|
|
|
|
|
// must use the fully qualified repo name. If the
|
|
|
|
// repo name does not have the registry prefix we
|
|
|
|
// should prepend.
|
|
|
|
if !strings.HasPrefix(repo, registry) {
|
|
|
|
repo = fmt.Sprintf("%s/%s", registry, repo)
|
|
|
|
}
|
|
|
|
|
|
|
|
os.Setenv("PLUGIN_REPO", repo)
|
|
|
|
os.Setenv("PLUGIN_REGISTRY", registry)
|
|
|
|
os.Setenv("DOCKER_USERNAME", username)
|
|
|
|
os.Setenv("DOCKER_PASSWORD", password)
|
|
|
|
|
|
|
|
// invoke the base docker plugin binary
|
2022-01-12 18:02:57 +01:00
|
|
|
cmd := exec.Command(docker.GetDroneDockerExecCmd())
|
2019-03-28 11:20:36 +01:00
|
|
|
cmd.Stdout = os.Stdout
|
|
|
|
cmd.Stderr = os.Stderr
|
|
|
|
err := cmd.Run()
|
|
|
|
if err != nil {
|
2022-01-12 18:02:57 +01:00
|
|
|
logrus.Fatal(err)
|
2019-03-28 11:20:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func getenv(key ...string) (s string) {
|
|
|
|
for _, k := range key {
|
|
|
|
s = os.Getenv(k)
|
|
|
|
if s != "" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|