push based on push-extra-tags list of tags

This commit is contained in:
Krzysztof Taraszka
2024-02-14 18:29:49 +01:00
parent c8897f42e4
commit dff13a8f1b
3 changed files with 30 additions and 11 deletions

View File

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

View File

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

View File

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