Skip to content

Commit

Permalink
build API: accept platform comma separated
Browse files Browse the repository at this point in the history
The docker API uses only a single arg for platform and multiple
platforms are given as comma separated list.

Fixes containers#22071

Signed-off-by: Paul Holzinger <[email protected]>
  • Loading branch information
Luap99 committed Jun 25, 2024
1 parent f62c3ec commit a3d5842
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/api/handlers/compat/images_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,12 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
UnsetLabels: query.UnsetLabels,
}

for _, platformSpec := range query.Platform {
platforms := query.Platform
if len(platforms) == 1 {
// Docker API uses comma sperated platform arg so match this here
platforms = strings.Split(query.Platform[0], ",")
}
for _, platformSpec := range platforms {
os, arch, variant, err := parse.Platform(platformSpec)
if err != nil {
utils.BadRequest(w, "platform", platformSpec, err)
Expand Down
1 change: 1 addition & 0 deletions pkg/api/server/register_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,7 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error {
// default:
// description: |
// Platform format os[/arch[/variant]]
// Can be comma separated list for multi arch builds.
// (As of version 1.xx)
// - in: query
// name: target
Expand Down
6 changes: 6 additions & 0 deletions test/apiv2/10-images.at
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,12 @@ else
_show_ok 1 "compat quiet build"
fi

# Do not try a real build here to tests the comma separated syntax as emulation
# is slow and may not work everywhere, checking the error is good enough to know
# we parsed it correctly on the server I would say
t POST "/build?q=1&dockerfile=containerfile&platform=linux/amd64,test" $CONTAINERFILE_WITH_ERR_TAR 400 \
.message="failed to parse query parameter 'platform': \"test\": invalid platform syntax for --platform=\"test\": \"test\": unknown operating system or architecture: invalid argument"

cleanBuildTest

# compat API vs libpod API event differences:
Expand Down

0 comments on commit a3d5842

Please sign in to comment.