Skip to content

Commit

Permalink
Revert "compat,build: pull must accept string"
Browse files Browse the repository at this point in the history
This reverts commit 5b148a0.

Reverting to treating the `pull` query parameter as a boolean.
Because of deceiving Docker API documentation it was assumed that the
parameter is pull-policy, however that is not true. Docker does treat
`pull` as a boolean. What is interesting is that Docker indeed accepts
strings like `always` or `never` however Docekr both of these strings
treat as `true`, not as pull-policy. As matter of the fact it seems
there is no such a thing as pull-policy in Docker.

More context containers#17778 (comment)

Signed-off-by: Matej Vasek <[email protected]>
  • Loading branch information
matejvasek committed Aug 14, 2023
1 parent a60bafe commit 4cb2d48
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 22 deletions.
15 changes: 2 additions & 13 deletions pkg/api/handlers/compat/images_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 string `schema:"pull"`
Pull bool `schema:"pull"`
PullPolicy string `schema:"pullpolicy"`
Quiet bool `schema:"q"`
Registry string `schema:"registry"`
Expand Down Expand Up @@ -580,19 +580,8 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
pullPolicy = buildahDefine.PolicyMap[query.PullPolicy]
} else {
if _, found := r.URL.Query()["pull"]; found {
switch strings.ToLower(query.Pull) {
case "false":
pullPolicy = buildahDefine.PullIfMissing
case "true":
if query.Pull {
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
}
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/api/server/register_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,8 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error {
// (As of version 1.xx)
// - in: query
// name: pull
// type: string
// default:
// type: boolean
// default: false
// description: |
// Attempt to pull the image even if an older image exists locally
// (As of version 1.xx)
Expand Down Expand Up @@ -1453,8 +1453,8 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error {
// (As of version 1.xx)
// - in: query
// name: pull
// type: string
// default:
// type: boolean
// default: false
// description: |
// Attempt to pull the image even if an older image exists locally
// (As of version 1.xx)
Expand Down
5 changes: 0 additions & 5 deletions test/apiv2/10-images.at
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,6 @@ 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\}$'
Expand Down

0 comments on commit 4cb2d48

Please sign in to comment.