api: fix platform type

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
Tonis Tiigi 2018-06-26 13:04:35 -07:00
parent 48b93419dc
commit 81f862a1fe
5 changed files with 10 additions and 10 deletions

View File

@ -72,12 +72,12 @@ func newImageBuildOptions(ctx context.Context, r *http.Request) (*types.ImageBui
options.RemoteContext = r.FormValue("remote") options.RemoteContext = r.FormValue("remote")
if versions.GreaterThanOrEqualTo(version, "1.32") { if versions.GreaterThanOrEqualTo(version, "1.32") {
apiPlatform := r.FormValue("platform") apiPlatform := r.FormValue("platform")
if len(strings.TrimSpace(apiPlatform)) != 0 { if apiPlatform != "" {
sp, err := platforms.Parse(apiPlatform) sp, err := platforms.Parse(apiPlatform)
if err != nil { if err != nil {
return nil, err return nil, err
} }
options.Platform = sp options.Platform = &sp
} }
} }

View File

@ -44,7 +44,7 @@ func (s *imageRouter) postImagesCreate(ctx context.Context, w http.ResponseWrite
version := httputils.VersionFromContext(ctx) version := httputils.VersionFromContext(ctx)
if versions.GreaterThanOrEqualTo(version, "1.32") { if versions.GreaterThanOrEqualTo(version, "1.32") {
apiPlatform := r.FormValue("platform") apiPlatform := r.FormValue("platform")
if len(strings.TrimSpace(apiPlatform)) != 0 { if apiPlatform != "" {
sp, err := platforms.Parse(apiPlatform) sp, err := platforms.Parse(apiPlatform)
if err != nil { if err != nil {
return err return err

View File

@ -181,7 +181,7 @@ type ImageBuildOptions struct {
ExtraHosts []string // List of extra hosts ExtraHosts []string // List of extra hosts
Target string Target string
SessionID string SessionID string
Platform specs.Platform Platform *specs.Platform
// Version specifies the version of the unerlying builder to use // Version specifies the version of the unerlying builder to use
Version BuilderVersion Version BuilderVersion
// BuildID is an optional identifier that can be passed together with the // BuildID is an optional identifier that can be passed together with the

View File

@ -73,7 +73,7 @@ type copier struct {
source builder.Source source builder.Source
pathCache pathCache pathCache pathCache
download sourceDownloader download sourceDownloader
platform specs.Platform platform *specs.Platform
// for cleanup. TODO: having copier.cleanup() is error prone and hard to // for cleanup. TODO: having copier.cleanup() is error prone and hard to
// follow. Code calling performCopy should manage the lifecycle of its params. // follow. Code calling performCopy should manage the lifecycle of its params.
// Copier should take override source as input, not imageMount. // Copier should take override source as input, not imageMount.

View File

@ -8,8 +8,8 @@ import (
"net/http" "net/http"
"net/url" "net/url"
"strconv" "strconv"
"strings"
"github.com/containerd/containerd/platforms"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container" "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)) 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 { if err := cli.NewVersionError("1.32", "platform"); err != nil {
return types.ImageBuildResponse{}, err return types.ImageBuildResponse{}, err
} }
query.Set("platform", options.Platform) query.Set("platform", platforms.Format(*options.Platform))
} }
headers.Set("Content-Type", "application/x-tar") headers.Set("Content-Type", "application/x-tar")
@ -130,8 +130,8 @@ func (cli *Client) imageBuildOptionsToQuery(options types.ImageBuildOptions) (ur
if options.SessionID != "" { if options.SessionID != "" {
query.Set("session", options.SessionID) query.Set("session", options.SessionID)
} }
if options.Platform != "" { if options.Platform != nil {
query.Set("platform", strings.ToLower(options.Platform)) query.Set("platform", platforms.Format(*options.Platform))
} }
if options.BuildID != "" { if options.BuildID != "" {
query.Set("buildid", options.BuildID) query.Set("buildid", options.BuildID)