Merge pull request #6588 from ipp-net/feature/add-latest-tag

add extra tags to every image dokku push when push-extra-tags are set
This commit is contained in:
Jose Diaz-Gonzalez authored and GitHub committed 2024-03-12 20:52:18 -04:00
commit 455c59a4b7
5 files changed
+94 -3

No files matched your search

@@ -135,3 +135,34 @@ dokku registry:set node-js-app push-on-release
# globally # globally
dokku registry:set --global push-on-release dokku registry:set --global push-on-release
``` ```
### Push extra tags
To push the image on release with extra tags, set the `push-extra-tags` to a comma-separated list of tags via the `registry:set` command. The default value for this property is empty. Setting the property will result in the image being tagged with extra tags every release.
```shell
# multiple-tags
dokku registry:set node-js-app push-extra-tags foo,bar
```
The `push-extra-tags` can be set to a single tag too.
```shell
# single tag
dokku registry:set node-js-app push-extra-tags foo
```
This property can be set for a single app or globally via the `--global` flag. When set globally, the app-specific value will always overide the global value. The default global value for this property is `false`.
```shell
dokku registry:set --global push-extra-tags foo,bar
```
Setting the property value to an empty string will reset the value to the system default. Resetting the value can be done per app or globally.
```shell
# per-app
dokku registry:set node-js-app push-extra-tags
# globally
dokku registry:set --global push-extra-tags
```
+29 -3
View File
@@ -79,6 +79,14 @@ func incrementTagVersion(appName string) (int, error) {
return version, nil return version, nil
} }
func getRegistryPushExtraTagsForApp(appName string) string {
value := common.PropertyGet("registry", appName, "push-extra-tags")
if value == "" {
value = common.PropertyGet("registry", "--global", "push-extra-tags")
}
return value
}
func pushToRegistry(appName string, tag int, imageID string, imageRepo string) error { func pushToRegistry(appName string, tag int, imageID string, imageRepo string) error {
common.LogVerboseQuiet("Retrieving image info for app") common.LogVerboseQuiet("Retrieving image info for app")
@@ -98,9 +106,27 @@ func pushToRegistry(appName string, tag int, imageID string, imageRepo string) e
return errors.New("Unable to tag image") return errors.New("Unable to tag image")
} }
// For the future, we should also add the ability to create the remote repository extraTags := getRegistryPushExtraTagsForApp(appName)
// This is only really important for registries that do not support creation on push if extraTags != "" {
// Examples include AWS and Quay.io 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))
}
defer func() {
common.LogVerboseQuiet(fmt.Sprintf("Untagging extra tag %s", extraTag))
if err := common.RemoveImages([]string{extraTagImage}); err != nil {
common.LogWarn(fmt.Sprintf("Unable to untag extra tag %s", extraTag, err.Error()))
}
}()
common.LogVerboseQuiet(fmt.Sprintf("Pushing %s", extraTagImage))
if !dockerPush(extraTagImage) {
return errors.New(fmt.Sprintf("Unable to push image with %s tag", extraTag))
}
}
}
common.LogVerboseQuiet(fmt.Sprintf("Pushing %s", fullImage)) common.LogVerboseQuiet(fmt.Sprintf("Pushing %s", fullImage))
if !dockerPush(fullImage) { if !dockerPush(fullImage) {
+2
View File
@@ -6,6 +6,7 @@ var (
"image-repo": "", "image-repo": "",
"push-on-release": "false", "push-on-release": "false",
"server": "", "server": "",
"push-extra-tags": "",
} }
// GlobalProperties is a map of all valid global registry properties // GlobalProperties is a map of all valid global registry properties
@@ -13,5 +14,6 @@ var (
"image-repo-template": true, "image-repo-template": true,
"push-on-release": true, "push-on-release": true,
"server": true, "server": true,
"push-extra-tags": true,
} }
) )
+5
View File
@@ -23,6 +23,7 @@ func ReportSingleApp(appName string, format string, infoFlag string) error {
"--registry-global-image-repo-template": reportGlobalImageRepoTemplate, "--registry-global-image-repo-template": reportGlobalImageRepoTemplate,
"--registry-server": reportServer, "--registry-server": reportServer,
"--registry-tag-version": reportTagVersion, "--registry-tag-version": reportTagVersion,
"--registry-push-extra-tags": reportPushExtraTags,
} }
flagKeys := []string{} flagKeys := []string{}
@@ -96,3 +97,7 @@ func reportTagVersion(appName string) string {
tagVersion := common.PropertyGet("registry", appName, "tag-version") tagVersion := common.PropertyGet("registry", appName, "tag-version")
return strings.TrimSpace(tagVersion) return strings.TrimSpace(tagVersion)
} }
func reportPushExtraTags(appName string) string {
return common.PropertyGet("registry", appName, "push-extra-tags")
}
+27
View File
@@ -294,3 +294,30 @@ teardown() {
echo "status: $status" echo "status: $status"
assert_success assert_success
} }
@test "(registry) registry:set push-extra-tags" {
if [[ -z "$DOCKERHUB_USERNAME" ]] || [[ -z "$DOCKERHUB_TOKEN" ]]; then
skip "skipping due to missing docker.io credentials DOCKERHUB_USERNAME:DOCKERHUB_TOKEN"
fi
run /bin/bash -c "dokku registry:set $TEST_APP push-on-release true"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku registry:set $TEST_APP image-repo dokku/test-app"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku registry:set $TEST_APP push-extra-tags foo"
echo "output: $output"
echo "status: $status"
assert_success
run deploy_app
echo "output: $output"
echo "status: $status"
assert_success
assert_output_contains "dokku/test-app:foo"
}