Browse Source

api: fix platform type

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
Tonis Tiigi 7 years ago
parent
commit
81f862a1fe

+ 2 - 2
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
 		}
 	}
 

+ 1 - 1
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

+ 1 - 1
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

+ 1 - 1
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.

+ 5 - 5
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)