compat,build: pull must accept string

`pull` parameter in `build` must accept string just like docker.

Ref: https://docs.docker.com/engine/api/v1.42/#tag/Image/operation/ImageBuild

Closes: https://github.com/containers/podman/issues/17778

Signed-off-by: Aditya R <arajan@redhat.com>
This commit is contained in:
Aditya R
2023-05-16 16:09:04 +05:30
parent e2d1ad1fb2
commit 5b148a0a68
3 changed files with 22 additions and 6 deletions

View File

@ -121,7 +121,7 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
OSVersion string `schema:"osversion"`
OutputFormat string `schema:"outputformat"`
Platform []string `schema:"platform"`
Pull bool `schema:"pull"`
Pull string `schema:"pull"`
PullPolicy string `schema:"pullpolicy"`
Quiet bool `schema:"q"`
Registry string `schema:"registry"`
@ -578,8 +578,19 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
pullPolicy = buildahDefine.PolicyMap[query.PullPolicy]
} else {
if _, found := r.URL.Query()["pull"]; found {
if query.Pull {
switch strings.ToLower(query.Pull) {
case "false":
pullPolicy = buildahDefine.PullIfMissing
case "true":
pullPolicy = buildahDefine.PullAlways
default:
policyFromMap, foundPolicy := buildahDefine.PolicyMap[query.Pull]
if foundPolicy {
pullPolicy = policyFromMap
} else {
utils.BadRequest(w, "pull", query.Pull, fmt.Errorf("invalid pull policy: %q", query.Pull))
return
}
}
}
}

View File

@ -546,8 +546,8 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error {
// (As of version 1.xx)
// - in: query
// name: pull
// type: boolean
// default: false
// type: string
// default:
// description: |
// Attempt to pull the image even if an older image exists locally
// (As of version 1.xx)
@ -1453,8 +1453,8 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error {
// (As of version 1.xx)
// - in: query
// name: pull
// type: boolean
// default: false
// type: string
// default:
// description: |
// Attempt to pull the image even if an older image exists locally
// (As of version 1.xx)

View File

@ -226,6 +226,11 @@ t POST "build?dockerfile=containerfile" $CONTAINERFILE_TAR application/json 200
response_headers=$(cat "$WORKDIR/curl.headers.out")
like "$response_headers" ".*application/json.*" "header does not contain application/json"
# Build api response header must contain Content-type: application/json
t POST "build?dockerfile=containerfile&pull=never" $CONTAINERFILE_TAR application/json 200
response_headers=$(cat "$WORKDIR/curl.headers.out")
like "$response_headers" ".*application/json.*" "header does not contain application/json"
# PR #12091: output from compat API must now include {"aux":{"ID":"sha..."}}
t POST "build?dockerfile=containerfile" $CONTAINERFILE_TAR 200 \
'.aux|select(has("ID")).ID~^sha256:[0-9a-f]\{64\}$'