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

compat,build: pull must accept string #18583

Merged
Merged
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
15 changes: 13 additions & 2 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 bool `schema:"pull"`
Pull string `schema:"pull"`
PullPolicy string `schema:"pullpolicy"`
Quiet bool `schema:"q"`
Registry string `schema:"registry"`
Expand Down Expand Up @@ -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))
Copy link
Member

Choose a reason for hiding this comment

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

missing return statement, and just guessing but I think the linter would love to see a switch case here but CI will tell you that anyway.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes linter was unhappy and suggested a switch case here, amend and repushed.

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: boolean
// default: false
// type: string
// default:
// 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: boolean
// default: false
// type: string
// default:
// description: |
// Attempt to pull the image even if an older image exists locally
// (As of version 1.xx)
Expand Down
5 changes: 5 additions & 0 deletions test/apiv2/10-images.at
Original file line number Diff line number Diff line change
Expand Up @@ -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\}$'
Expand Down