From dff13a8f1b33e88e6e015db739b8ceccac77d338 Mon Sep 17 00:00:00 2001 From: Krzysztof Taraszka Date: Wed, 14 Feb 2024 18:29:49 +0100 Subject: [PATCH] push based on push-extra-tags list of tags --- plugins/registry/functions.go | 34 +++++++++++++++++++++++----------- plugins/registry/registry.go | 2 ++ plugins/registry/report.go | 5 +++++ 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/plugins/registry/functions.go b/plugins/registry/functions.go index 9da8c1d1b..c88639edf 100644 --- a/plugins/registry/functions.go +++ b/plugins/registry/functions.go @@ -81,6 +81,15 @@ func incrementTagVersion(appName string) (int, error) { return version, nil } +func getRegistryPushExtraTagsForApp(appName string) string { + value := common.PropertyGet("registry", appName, "push-extra-tags") + common.LogVerboseQuiet(fmt.Sprintf("VALUE IS: %s", value)) + if value == "" { + value = common.PropertyGet("registry", "--global", "push-extra-tags") + } + return value +} + func pushToRegistry(appName string, tag int, imageID string, imageRepo string) error { common.LogVerboseQuiet("Retrieving image info for app") @@ -88,7 +97,6 @@ func pushToRegistry(appName string, tag int, imageID string, imageRepo string) e imageTag, _ := common.GetRunningImageTag(appName, "") fullImage := fmt.Sprintf("%s%s:%d", registryServer, imageRepo, tag) - latestImage := fmt.Sprintf("%s%s:latest", registryServer, imageRepo) common.LogVerboseQuiet(fmt.Sprintf("Tagging %s:%d in registry format", imageRepo, tag)) if !dockerTag(imageID, fullImage) { @@ -101,10 +109,20 @@ func pushToRegistry(appName string, tag int, imageID string, imageRepo string) e return errors.New("Unable to tag image") } - // Tagging the image as latest - common.LogVerboseQuiet(fmt.Sprintf("Tagging %s as latest in registry format", imageRepo)) - if !dockerTag(imageID, latestImage) { - return errors.New("Unable to tag image as latest") + extraTags := getRegistryPushExtraTagsForApp(appName) + if extraTags != "" { + extraTagsArray := strings.Split(extraTags, ",") + for _, extraTag := range extraTagsArray { + extraTagImage := fmt.Sprintf("%s%s:%s", registryServer, imageRepo, extraTag) + common.LogVerboseQuiet(fmt.Sprintf("Tagging %s as %s in registry format", imageRepo, extraTag)) + if !dockerTag(imageID, extraTagImage) { + return errors.New(fmt.Sprintf("Unable to tag image as %s", extraTag)) + } + common.LogVerboseQuiet(fmt.Sprintf("Pushing %s", extraTagImage)) + if !dockerPush(extraTagImage) { + return errors.New(fmt.Sprintf("Unable to push image with %s tag", tag)) + } + } } common.LogVerboseQuiet(fmt.Sprintf("Pushing %s", fullImage)) @@ -113,12 +131,6 @@ func pushToRegistry(appName string, tag int, imageID string, imageRepo string) e return errors.New("Unable to push image") } - // Pushing the latest tag - common.LogVerboseQuiet(fmt.Sprintf("Pushing %s", latestImage)) - if !dockerPush(latestImage) { - return errors.New("Unable to push image with latest tag") - } - // Only clean up when the scheduler is not docker-local // other schedulers do not retire local images if common.GetAppScheduler(appName) != "docker-local" { diff --git a/plugins/registry/registry.go b/plugins/registry/registry.go index abea76773..420960bd3 100644 --- a/plugins/registry/registry.go +++ b/plugins/registry/registry.go @@ -6,6 +6,7 @@ var ( "image-repo": "", "push-on-release": "false", "server": "", + "push-extra-tags": "", } // GlobalProperties is a map of all valid global registry properties @@ -13,5 +14,6 @@ var ( "image-repo-template": true, "push-on-release": true, "server": true, + "push-extra-tags": true, } ) diff --git a/plugins/registry/report.go b/plugins/registry/report.go index 710719f32..9d1fe3251 100644 --- a/plugins/registry/report.go +++ b/plugins/registry/report.go @@ -23,6 +23,7 @@ func ReportSingleApp(appName string, format string, infoFlag string) error { "--registry-global-image-repo-template": reportGlobalImageRepoTemplate, "--registry-server": reportServer, "--registry-tag-version": reportTagVersion, + "--registry-push-extra-tags": reportPushExtraTags, } flagKeys := []string{} @@ -96,3 +97,7 @@ func reportTagVersion(appName string) string { tagVersion := common.PropertyGet("registry", appName, "tag-version") return strings.TrimSpace(tagVersion) } + +func reportPushExtraTags(appName string) string { + return common.PropertyGet("registry", appName, "push-extra-tags") +}