images/create: handle tag/digest if Tag specified

Podman handles /images/create better when fromImage and Tag are
specified. Now the tag/digest value provided in Tag will replace the one
in fromImage

Fixes: https://github.com/containers/podman/issues/23938

Signed-off-by: Nicola Sella <nsella@redhat.com>
This commit is contained in:
Nicola Sella 2024-10-07 11:59:55 +02:00
parent 8d5ec11d0b
commit 1778a90876
2 changed files with 8 additions and 0 deletions

View File

@ -45,6 +45,11 @@ func mergeNameAndTagOrDigest(name, tagOrDigest string) string {
// We have a digest, so let's change the separator. // We have a digest, so let's change the separator.
separator = "@" separator = "@"
} }
// if both name and tagOrDigest are defined we try to use the tagOrDigest image part and override the tag/digest
if len(name) > 0 && strings.Contains(name, separator) {
index := strings.LastIndex(name, separator)
return fmt.Sprintf("%s%s%s", name[:index], separator, tagOrDigest)
}
return fmt.Sprintf("%s%s%s", name, separator, tagOrDigest) return fmt.Sprintf("%s%s%s", name, separator, tagOrDigest)
} }

View File

@ -112,6 +112,9 @@ fi
t POST "/images/create?fromImage=quay.io/idonotexist/idonotexist:dummy" $expect_code \ t POST "/images/create?fromImage=quay.io/idonotexist/idonotexist:dummy" $expect_code \
.message="$expect_msg" .message="$expect_msg"
# compat api pull image with fromImage and Tag
t GET "/images/create?fromImage=alpine:latest&tag=latest" 200 .error~null .status~".*Download complete.*"
# Export an image on the local # Export an image on the local
t GET libpod/images/nonesuch/get 404 t GET libpod/images/nonesuch/get 404
t GET libpod/images/$iid/get?format=foo 500 t GET libpod/images/$iid/get?format=foo 500