From b33f3c7802ac4308c10ca3fdbeec8a3fc46c3c97 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 12 Jul 2021 12:20:19 +0200 Subject: [PATCH 1/2] client: remove unused Platform field from configWrapper This field was added in 7a9cb29fb980c0ab3928272cdc24c7089b2fcf64, but appears to be unused, so removing it. Signed-off-by: Sebastiaan van Stijn --- client/container_create.go | 1 - 1 file changed, 1 deletion(-) diff --git a/client/container_create.go b/client/container_create.go index cfae96a6f5..905b99044c 100644 --- a/client/container_create.go +++ b/client/container_create.go @@ -16,7 +16,6 @@ type configWrapper struct { *container.Config HostConfig *container.HostConfig NetworkingConfig *network.NetworkingConfig - Platform *specs.Platform } // ContainerCreate creates a new container based on the given configuration. From 5f0703c549935d2cfec42b468b858d822b58a27e Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 12 Jul 2021 12:27:30 +0200 Subject: [PATCH 2/2] client: remove containerd "platform" dependency Signed-off-by: Sebastiaan van Stijn --- client/container_create.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/client/container_create.go b/client/container_create.go index 905b99044c..47d15c2bbd 100644 --- a/client/container_create.go +++ b/client/container_create.go @@ -4,8 +4,8 @@ import ( "context" "encoding/json" "net/url" + "path" - "github.com/containerd/containerd/platforms" "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/network" "github.com/docker/docker/api/types/versions" @@ -37,8 +37,8 @@ func (cli *Client) ContainerCreate(ctx context.Context, config *container.Config } query := url.Values{} - if platform != nil { - query.Set("platform", platforms.Format(*platform)) + if p := formatPlatform(platform); p != "" { + query.Set("platform", p) } if containerName != "" { @@ -60,3 +60,15 @@ func (cli *Client) ContainerCreate(ctx context.Context, config *container.Config err = json.NewDecoder(serverResp.body).Decode(&response) return response, err } + +// formatPlatform returns a formatted string representing platform (e.g. linux/arm/v7). +// +// Similar to containerd's platforms.Format(), but does allow components to be +// omitted (e.g. pass "architecture" only, without "os": +// https://github.com/containerd/containerd/blob/v1.5.2/platforms/platforms.go#L243-L263 +func formatPlatform(platform *specs.Platform) string { + if platform == nil { + return "" + } + return path.Join(platform.OS, platform.Architecture, platform.Variant) +}