-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
LCOW: CLI changes to add platform flag - pull, run, create and build #474
Conversation
cli/command/commands/commands.go
Outdated
@@ -87,6 +87,7 @@ func AddCommands(cmd *cobra.Command, dockerCli *command.DockerCli) { | |||
hide(container.NewLogsCommand(dockerCli)), | |||
hide(container.NewPauseCommand(dockerCli)), | |||
hide(container.NewPortCommand(dockerCli)), | |||
hide(image.NewPullCommand(dockerCli)), |
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.
looks like this moved for no reason? now it's not sorted
cli/command/container/run.go
Outdated
@@ -123,6 +128,7 @@ func runContainer(dockerCli *command.DockerCli, opts *runOptions, copts *contain | |||
hostConfig := containerConfig.HostConfig | |||
stdout, stderr := dockerCli.Out(), dockerCli.Err() | |||
client := dockerCli.Client() | |||
ociPlatform := system.ParsePlatform(opts.platform) |
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.
I think this should be parsed by the flag instead after flag parsing. To accomplish this you can create a new PlatformOpt
type in opts/platform.go
with a func Value() spec.Platform
to return the parsed type.
The field in the options struct will be a PlatformOpt
instead of a string
cli/command/container/run.go
Outdated
@@ -59,6 +61,9 @@ func NewRunCommand(dockerCli *command.DockerCli) *cobra.Command { | |||
flags.StringVar(&opts.name, "name", "", "Assign a name to the container") | |||
flags.StringVar(&opts.detachKeys, "detach-keys", "", "Override the key sequence for detaching a container") | |||
|
|||
flags.StringVar(&opts.platform, "platform", "", "Set platform if server is multi-platform capable") | |||
flags.SetAnnotation("platform", "version", []string{"1.32"}) |
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.
Since this is going to be repeated in a bunch of commands how about we move this to
func addPlatformFlag(flags *pflag.FlagSet, opt *PlatformOpt)
in cli/flags/common.go
There will also need to be another annotation for hiding based on the header:
flags.SetAnnotation("platform", "platform", nil)
The code to hide flags based on annotations is in cmd/docker/docker.go
cli/command/image/cmd.go
Outdated
NewPushCommand(dockerCli), | ||
NewPullCommand(dockerCli), |
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.
unsorted
cli/command/image/trust.go
Outdated
func imagePullPrivileged(ctx context.Context, cli command.Cli, authConfig types.AuthConfig, ref string, requestPrivilege types.RequestPrivilegeFunc, all bool) error { | ||
func imagePullPrivileged(ctx context.Context, cli command.Cli, authConfig types.AuthConfig, ref string, requestPrivilege types.RequestPrivilegeFunc, all bool, platform specs.Platform) error { | ||
if platform.OS == "" && os.Getenv("DOCKER_DEFAULT_PLATFORM") != "" { | ||
platform.OS = os.Getenv("DOCKER_DEFAULT_PLATFORM") |
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.
This should be handled somewhere else before it gets into the pull handling. Possibly as part of the PlatformOpt
type. It can be used as a default value for Value()
This will also remove the duplication.
5f89aff
to
03fb697
Compare
Rebased and reworked based on moby/moby#34642 and addressed most of the comments. Still a work in progress until 34642 is merged in moby/moby as the vendoring will remain hacked. |
03fb697
to
d186bc3
Compare
8f7375e
to
8abdeba
Compare
Codecov Report
@@ Coverage Diff @@
## master #474 +/- ##
==========================================
- Coverage 50.1% 49.54% -0.56%
==========================================
Files 216 211 -5
Lines 17700 17480 -220
==========================================
- Hits 8868 8661 -207
+ Misses 8388 8386 -2
+ Partials 444 433 -11
Continue to review full report at Codecov.
|
Rebased to address conflicts, and reworked to use two utility functions rather than replicate the same code in a few places. Ready for review, removed WIP from the title, updated the commit comment and the description of the PR. @vdemeester can this be moved to code review now? |
@johnstep PTAL too. Thanks. |
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.
Design LGTM
I still think we should hide this flag when the list of supported platforms returned by the API has a length of 1.
That would be handled by adding another field to ServerInfo
in cli/command/cli.go, and calling a new function from
hideUnsupportedFeatures()in
cmd/docker/docker.go`.
cli/command/utils.go
Outdated
|
||
// PlatformFromEnvironment sets the platform from an environment variable | ||
// if it isn't otherwise populated. | ||
func PlatformFromEnvironment(platform string) string { |
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.
Since this is effectively setting a default value for platform I think the environment variable should be read as the default value in AddPlatformFlag()
instead of exporting this function:
flags.StringVar(target, "platform", os.Getenv("DOCKER_DEFAULT_PLATFORM"), ...)
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.
That makes sense. Updated.
For hiding the flag, it is going to require getting consensus on moby/moby#34628 first, which I don't think there is among other maintainers yet.
8abdeba
to
a5e4e1d
Compare
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.
LGTM
This should probably be hidden for a daemon without experimental. |
Signed-off-by: John Howard <jhoward@microsoft.com> This is the CLI updates for the document discussed in moby/moby#34617 to support Linux Containers on Windows. It adds --platform= as CLI flags to the four commands listed above. Import still to be completed (needs daemon changes).
a5e4e1d
to
d8b7825
Compare
@johnstep - OK, added that annotation in utils.go::AddPlatformFlag() and verified it operates as expected. |
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.
LGTM
Is this OK to merge with 2 LGTM's? |
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.
LGTM 🐮
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.
LGTM
Signed-off-by: John Howard jhoward@microsoft.com
Replacement for #416. This adds the CLI flag changes to match those described in moby/moby#34617, and PR'd to moby/moby in moby/moby#34642.
It adds
--platform
topull
,run
,create
, andbuild
. Noteimport
requires further daemon changes so has not been done yet (will be in a further PR once the daemon has been updated).