diff --git a/api/server/router/build/build_routes.go b/api/server/router/build/build_routes.go index 0dd2b1d8f9..52ba13216d 100644 --- a/api/server/router/build/build_routes.go +++ b/api/server/router/build/build_routes.go @@ -72,12 +72,12 @@ func newImageBuildOptions(ctx context.Context, r *http.Request) (*types.ImageBui options.RemoteContext = r.FormValue("remote") if versions.GreaterThanOrEqualTo(version, "1.32") { apiPlatform := r.FormValue("platform") - if len(strings.TrimSpace(apiPlatform)) != 0 { + if apiPlatform != "" { sp, err := platforms.Parse(apiPlatform) if err != nil { return nil, err } - options.Platform = sp + options.Platform = &sp } } diff --git a/api/server/router/image/image_routes.go b/api/server/router/image/image_routes.go index f359df27f8..42db0a14e7 100644 --- a/api/server/router/image/image_routes.go +++ b/api/server/router/image/image_routes.go @@ -44,7 +44,7 @@ func (s *imageRouter) postImagesCreate(ctx context.Context, w http.ResponseWrite version := httputils.VersionFromContext(ctx) if versions.GreaterThanOrEqualTo(version, "1.32") { apiPlatform := r.FormValue("platform") - if len(strings.TrimSpace(apiPlatform)) != 0 { + if apiPlatform != "" { sp, err := platforms.Parse(apiPlatform) if err != nil { return err diff --git a/api/types/client.go b/api/types/client.go index cc10a98a58..33bc98e0bb 100644 --- a/api/types/client.go +++ b/api/types/client.go @@ -181,7 +181,7 @@ type ImageBuildOptions struct { ExtraHosts []string // List of extra hosts Target string SessionID string - Platform specs.Platform + Platform *specs.Platform // Version specifies the version of the unerlying builder to use Version BuilderVersion // BuildID is an optional identifier that can be passed together with the diff --git a/builder/dockerfile/copy.go b/builder/dockerfile/copy.go index 17d2b5bde9..37ee4006df 100644 --- a/builder/dockerfile/copy.go +++ b/builder/dockerfile/copy.go @@ -73,7 +73,7 @@ type copier struct { source builder.Source pathCache pathCache download sourceDownloader - platform specs.Platform + platform *specs.Platform // for cleanup. TODO: having copier.cleanup() is error prone and hard to // follow. Code calling performCopy should manage the lifecycle of its params. // Copier should take override source as input, not imageMount. diff --git a/client/image_build.go b/client/image_build.go index dff19b989f..e5013176a2 100644 --- a/client/image_build.go +++ b/client/image_build.go @@ -8,8 +8,8 @@ import ( "net/http" "net/url" "strconv" - "strings" + "github.com/containerd/containerd/platforms" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" ) @@ -30,11 +30,11 @@ func (cli *Client) ImageBuild(ctx context.Context, buildContext io.Reader, optio } headers.Add("X-Registry-Config", base64.URLEncoding.EncodeToString(buf)) - if options.Platform != "" { + if options.Platform != nil { if err := cli.NewVersionError("1.32", "platform"); err != nil { return types.ImageBuildResponse{}, err } - query.Set("platform", options.Platform) + query.Set("platform", platforms.Format(*options.Platform)) } headers.Set("Content-Type", "application/x-tar") @@ -130,8 +130,8 @@ func (cli *Client) imageBuildOptionsToQuery(options types.ImageBuildOptions) (ur if options.SessionID != "" { query.Set("session", options.SessionID) } - if options.Platform != "" { - query.Set("platform", strings.ToLower(options.Platform)) + if options.Platform != nil { + query.Set("platform", platforms.Format(*options.Platform)) } if options.BuildID != "" { query.Set("buildid", options.BuildID)