Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

images/create: handle tag/digest if Tag specified #24184

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkg/api/handlers/compat/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ func mergeNameAndTagOrDigest(name, tagOrDigest string) string {
// We have a digest, so let's change the 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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the contains is unnecessary, LastIndex already tells you if it contains or not so we only need to walk the string once not twice

index := strings.LastIndex(name, separator)
return fmt.Sprintf("%s%s%s", name[:index], separator, tagOrDigest)
}
return fmt.Sprintf("%s%s%s", name, separator, tagOrDigest)
}

Expand Down
3 changes: 3 additions & 0 deletions test/apiv2/10-images.at
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ fi
t POST "/images/create?fromImage=quay.io/idonotexist/idonotexist:dummy" $expect_code \
.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
t GET libpod/images/nonesuch/get 404
t GET libpod/images/$iid/get?format=foo 500
Expand Down