From a3d5842746421482d3d2ab0fb4590aa93c48edc7 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Tue, 25 Jun 2024 18:48:59 +0200 Subject: [PATCH] build API: accept platform comma separated The docker API uses only a single arg for platform and multiple platforms are given as comma separated list. Fixes #22071 Signed-off-by: Paul Holzinger --- pkg/api/handlers/compat/images_build.go | 7 ++++++- pkg/api/server/register_images.go | 1 + test/apiv2/10-images.at | 6 ++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pkg/api/handlers/compat/images_build.go b/pkg/api/handlers/compat/images_build.go index 207686c05c..19a5338791 100644 --- a/pkg/api/handlers/compat/images_build.go +++ b/pkg/api/handlers/compat/images_build.go @@ -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) diff --git a/pkg/api/server/register_images.go b/pkg/api/server/register_images.go index 63284b49cf..c592eec228 100644 --- a/pkg/api/server/register_images.go +++ b/pkg/api/server/register_images.go @@ -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 diff --git a/test/apiv2/10-images.at b/test/apiv2/10-images.at index cfed2dc411..8cd7ed2234 100644 --- a/test/apiv2/10-images.at +++ b/test/apiv2/10-images.at @@ -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: