feat: implement more of the registry plugin

This commit is contained in:
Jose Diaz-Gonzalez
2021-03-19 16:50:32 -04:00
parent 3848b467a2
commit 88cbae2a6d
4 changed files with 49 additions and 11 deletions

View File

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

View File

@@ -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 {

View File

@@ -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)

View File

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