From 1e86d0a75b9db7fe8b342c4f0bc9561d27ce0c24 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Wed, 17 May 2023 11:34:26 +0200 Subject: [PATCH] compat: accept tag in /images/create?fromSrc Accept a tag in the compat api endpoint. For the fromImage param we already parse it but for fromSrc we did not. Fixes #18597 Signed-off-by: Paul Holzinger --- pkg/api/handlers/compat/images.go | 5 +++-- test/apiv2/10-images.at | 7 +++++++ test/apiv2/test-apiv2 | 4 ++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/pkg/api/handlers/compat/images.go b/pkg/api/handlers/compat/images.go index 4e5662c845..e3e97ce89b 100644 --- a/pkg/api/handlers/compat/images.go +++ b/pkg/api/handlers/compat/images.go @@ -181,7 +181,8 @@ func CreateImageFromSrc(w http.ResponseWriter, r *http.Request) { FromSrc string `schema:"fromSrc"` Message string `schema:"message"` Platform string `schema:"platform"` - Repo string `shchema:"repo"` + Repo string `schema:"repo"` + Tag string `schema:"tag"` }{ // This is where you can override the golang default value for one of fields } @@ -208,7 +209,7 @@ func CreateImageFromSrc(w http.ResponseWriter, r *http.Request) { reference := query.Repo if query.Repo != "" { - possiblyNormalizedName, err := utils.NormalizeToDockerHub(r, reference) + possiblyNormalizedName, err := utils.NormalizeToDockerHub(r, mergeNameAndTagOrDigest(reference, query.Tag)) if err != nil { utils.Error(w, http.StatusInternalServerError, fmt.Errorf("normalizing image: %w", err)) return diff --git a/test/apiv2/10-images.at b/test/apiv2/10-images.at index 5136328ba7..a4abe79a9b 100644 --- a/test/apiv2/10-images.at +++ b/test/apiv2/10-images.at @@ -66,6 +66,13 @@ podman untag docker.io/library/alpine:latest t POST "images/create?fromImage=quay.io/libpod/alpine&tag=sha256:fa93b01658e3a5a1686dc3ae55f170d8de487006fb53a28efcd12ab0710a2e5f" 200 +# create image from source with tag +# Note the "-" is used to use an empty body and not "{}" which is the default. +t POST "images/create?fromSrc=-&repo=myimage&tag=mytag" - 200 +t GET "images/myimage:mytag/json" 200 \ + .Id~'^sha256:[0-9a-f]\{64\}$' \ + .RepoTags[0]="docker.io/library/myimage:mytag" + # Display the image history t GET libpod/images/nonesuch/history 404 diff --git a/test/apiv2/test-apiv2 b/test/apiv2/test-apiv2 index 8132e6432e..cd56747065 100755 --- a/test/apiv2/test-apiv2 +++ b/test/apiv2/test-apiv2 @@ -255,6 +255,10 @@ function t() { for arg; do case "$arg" in + # This is just some hack to avoid adding `-d {}` to curl for endpoints where we really need an empty body. + # --disable makes curl not lookup the curlrc file, it't should't effect the tests in any way. + -) curl_args+=(--disable); + shift;; *=*) post_args+=("$arg"); shift;; *.json) _add_curl_args $arg;