From 88cbae2a6de6d45562b88e773c3f54f2705f2b3e Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Fri, 19 Mar 2021 16:50:32 -0400 Subject: [PATCH] feat: implement more of the registry plugin --- plugins/registry/functions.go | 19 ++++++++++++++++++ plugins/registry/report.go | 11 +---------- plugins/registry/src/triggers/triggers.go | 6 ++++++ plugins/registry/triggers.go | 24 ++++++++++++++++++++++- 4 files changed, 49 insertions(+), 11 deletions(-) diff --git a/plugins/registry/functions.go b/plugins/registry/functions.go index 99c1dbce1..c3495f109 100644 --- a/plugins/registry/functions.go +++ b/plugins/registry/functions.go @@ -3,10 +3,29 @@ package registry import ( "fmt" "strconv" + "strings" "github.com/dokku/dokku/plugins/common" ) +func getRegistryServerForApp(appName string) string { + value := common.PropertyGet("registry", appName, "server") + if value == "" { + value = common.PropertyGet("registry", "--global", "server") + } + + if value == "" { + value = DefaultProperties["server"] + } + + value = strings.TrimSuffix(value, "/") + "/" + if value == "hub.docker.com/" || value == "docker.io/" { + value = "" + } + + return value +} + func isPushEnabled(appName string) bool { return reportComputedPushOnRelease(appName) == "true" } diff --git a/plugins/registry/report.go b/plugins/registry/report.go index 61d4232cb..b2789ea95 100644 --- a/plugins/registry/report.go +++ b/plugins/registry/report.go @@ -82,16 +82,7 @@ func reportPushOnRelease(appName string) string { } func reportComputedServer(appName string) string { - value := reportServer(appName) - if value == "" { - value = reportGlobalServer(appName) - } - - if value == "" { - value = DefaultProperties["server"] - } - - return value + return getRegistryServerForApp(appName) } func reportGlobalServer(appName string) string { diff --git a/plugins/registry/src/triggers/triggers.go b/plugins/registry/src/triggers/triggers.go index 028fbb2eb..85211a403 100644 --- a/plugins/registry/src/triggers/triggers.go +++ b/plugins/registry/src/triggers/triggers.go @@ -18,6 +18,12 @@ func main() { var err error switch trigger { + case "deployed-app-image-repo": + appName := flag.Arg(0) + err = registry.TriggerDeployedAppImageRepo(appName) + case "deployed-app-image-tag": + appName := flag.Arg(0) + err = registry.TriggerDeployedAppImageTag(appName) case "deployed-app-repository": appName := flag.Arg(0) err = registry.TriggerDeployedAppRepository(appName) diff --git a/plugins/registry/triggers.go b/plugins/registry/triggers.go index 55050b96d..c6ecda4bf 100644 --- a/plugins/registry/triggers.go +++ b/plugins/registry/triggers.go @@ -6,9 +6,31 @@ import ( "github.com/dokku/dokku/plugins/common" ) +// TriggerDeployedAppImageRepo outputs the associated image repo to stdout +func TriggerDeployedAppImageRepo(appName string) error { + imageRepo := common.PropertyGet("registry", appName, "image-repo") + if imageRepo == "" { + imageRepo = common.GetAppImageRepo(appName) + } + + fmt.Println(imageRepo) + return nil +} + +// TriggerDeployedAppImageTag outputs the associated image tag to stdout +func TriggerDeployedAppImageTag(appName string) error { + tagVersion := common.PropertyGet("registry", appName, "tag-version") + if tagVersion == "" { + tagVersion = "1" + } + + fmt.Println(tagVersion) + return nil +} + // TriggerDeployedAppRepository outputs the associated registry repository to stdout func TriggerDeployedAppRepository(appName string) error { - // TODO + fmt.Println(getRegistryServerForApp(appName)) return nil }