-
Notifications
You must be signed in to change notification settings - Fork 18.9k
Remove containerd "platform" dependency from client #42623
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -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. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -38,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 != "" { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -61,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 "" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let me call out here that containerd's format would return
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, buildkit supports just setting arch... weird that we'd return empty for empty OS.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any thoughts on this?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looked up the parsing on the daemon side, and looks indeed that that should be supported; if only moby/vendor/github.com/containerd/containerd/platforms/platforms.go Lines 182 to 206 in ada51d6
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return path.Join(platform.OS, platform.Architecture, platform.Variant) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like we really want
path.Join(platform.OS, platform.Arch....)This will handle empty values as desired, even for empty values.
https://play.golang.org/p/ztICsyudOrB
Not sure if you want to validate that is always arch is set if variant is also set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, nice! TIL
path.Joinskips the empty values (I assumed it would keep those in). Yes, I like that.Yeah, perhaps stop at the first empty value (in which case
path.Joinwould not be needed 🤔). We could keep it "simple" (for now), and just let the daemon handle this; wdyt?I was writing down notes on serializing / deserialising and normalising of oci.Platform (to start a discussion on the OCI spec), because currently it looks like there's no standard approach anywhere.
So add to the "silliness"; I was looking at the CLI code YesterdayI: https://github.com/docker/cli/blob/v20.10.7/cli/command/container/create.go#L244-L249
So, we:
--platformflag)oci.Platform{}oci.Platform{}Looking at that, I think we should consider to either have the client (and cli) to not bother with
oci.Platform{}at all (pass a string, and let the daemon deal with it), or make the API accept aoci.Platform{}(or equivalent) in the request.