Browse code

client: remove containerd "platform" dependency

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2021/07/12 19:27:30
Showing 1 changed files
... ...
@@ -4,8 +4,8 @@ import (
4 4
 	"context"
5 5
 	"encoding/json"
6 6
 	"net/url"
7
+	"path"
7 8
 
8
-	"github.com/containerd/containerd/platforms"
9 9
 	"github.com/docker/docker/api/types/container"
10 10
 	"github.com/docker/docker/api/types/network"
11 11
 	"github.com/docker/docker/api/types/versions"
... ...
@@ -37,8 +37,8 @@ func (cli *Client) ContainerCreate(ctx context.Context, config *container.Config
37 37
 	}
38 38
 
39 39
 	query := url.Values{}
40
-	if platform != nil {
41
-		query.Set("platform", platforms.Format(*platform))
40
+	if p := formatPlatform(platform); p != "" {
41
+		query.Set("platform", p)
42 42
 	}
43 43
 
44 44
 	if containerName != "" {
... ...
@@ -60,3 +60,15 @@ func (cli *Client) ContainerCreate(ctx context.Context, config *container.Config
60 60
 	err = json.NewDecoder(serverResp.body).Decode(&response)
61 61
 	return response, err
62 62
 }
63
+
64
+// formatPlatform returns a formatted string representing platform (e.g. linux/arm/v7).
65
+//
66
+// Similar to containerd's platforms.Format(), but does allow components to be
67
+// omitted (e.g. pass "architecture" only, without "os":
68
+// https://github.com/containerd/containerd/blob/v1.5.2/platforms/platforms.go#L243-L263
69
+func formatPlatform(platform *specs.Platform) string {
70
+	if platform == nil {
71
+		return ""
72
+	}
73
+	return path.Join(platform.OS, platform.Architecture, platform.Variant)
74
+}