@@ -79,8 +79,10 @@ func (cli *Client) ContainerCreate(ctx context.Context, config *container.Config |
79 | 79 | } |
80 | 80 |
|
81 | 81 | query := url.Values{} |
82 | | - if p := formatPlatform(platform); p != "" { |
83 | | - query.Set("platform", p) |
| 82 | + if platform != nil { |
| 83 | + if p := formatPlatform(*platform); p != "unknown" { |
| 84 | + query.Set("platform", p) |
| 85 | + } |
84 | 86 | } |
85 | 87 |
|
86 | 88 | if containerName != "" { |
@@ -103,14 +105,16 @@ func (cli *Client) ContainerCreate(ctx context.Context, config *container.Config |
103 | 105 | return response, err |
104 | 106 | } |
105 | 107 |
|
106 | | -// formatPlatform returns a formatted string representing platform (e.g. linux/arm/v7). |
| 108 | +// formatPlatform returns a formatted string representing platform (e.g., "linux/arm/v7"). |
| 109 | +// |
| 110 | +// It is a fork of [platforms.Format], and does not yet support "os.version", |
| 111 | +// as [[platforms.FormatAll] does. |
107 | 112 | // |
108 | | -// Similar to containerd's platforms.Format(), but does allow components to be |
109 | | -// omitted (e.g. pass "architecture" only, without "os": |
110 | | -// https://github.com/containerd/containerd/blob/v1.5.2/platforms/platforms.go#L243-L263 |
111 | | -func formatPlatform(platform *ocispec.Platform) string { |
112 | | - if platform == nil { |
113 | | - return "" |
| 113 | +// [platforms.Format]: https://github.com/containerd/platforms/blob/v1.0.0-rc.1/platforms.go#L309-L316 |
| 114 | +// [platforms.FormatAll]: https://github.com/containerd/platforms/blob/v1.0.0-rc.1/platforms.go#L318-L330 |
| 115 | +func formatPlatform(platform ocispec.Platform) string { |
| 116 | + if platform.OS == "" { |
| 117 | + return "unknown" |
114 | 118 | } |
115 | 119 | return path.Join(platform.OS, platform.Architecture, platform.Variant) |
116 | 120 | } |
@@ -134,8 +138,10 @@ const allCapabilities = "ALL" |
134 | 138 | // normalizeCapabilities normalizes capabilities to their canonical form, |
135 | 139 | // removes duplicates, and sorts the results. |
136 | 140 | // |
137 | | -// It is similar to [github.com/docker/docker/oci/caps.NormalizeLegacyCapabilities], |
| 141 | +// It is similar to [caps.NormalizeLegacyCapabilities], |
138 | 142 | // but performs no validation based on supported capabilities. |
| 143 | +// |
| 144 | +// [caps.NormalizeLegacyCapabilities]: https://github.com/moby/moby/blob/v28.3.2/oci/caps/utils.go#L56 |
139 | 145 | func normalizeCapabilities(caps []string) []string { |
140 | 146 | var normalized []string |
141 | 147 |
|
|