Skip to content
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

Merged
merged 1 commit into from
Nov 7, 2017

Conversation

lowenna
Copy link
Contributor

@lowenna lowenna commented Aug 27, 2017

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 to pull, run, create, and build. Note import requires further daemon changes so has not been done yet (will be in a further PR once the daemon has been updated).

@@ -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)),
Copy link
Contributor

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

@@ -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)
Copy link
Contributor

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

@@ -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"})
Copy link
Contributor

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

NewPushCommand(dockerCli),
NewPullCommand(dockerCli),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unsorted

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")
Copy link
Contributor

@dnephin dnephin Aug 28, 2017

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.

@lowenna
Copy link
Contributor Author

lowenna commented Sep 19, 2017

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.

@lowenna lowenna force-pushed the jjh/apis-for-platform branch 5 times, most recently from 8f7375e to 8abdeba Compare October 30, 2017 18:44
@lowenna lowenna changed the title [WIP] - Pending moby/moby - LCOW: CLI changes to add platform flag. LCOW: CLI changes to add platform flag - pull, run, create and build Oct 30, 2017
@codecov-io
Copy link

codecov-io commented Oct 30, 2017

Codecov Report

Merging #474 into master will decrease coverage by 0.55%.
The diff coverage is 45.45%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
cli/command/container/run.go 0% <0%> (ø) ⬆️
cli/command/utils.go 0% <0%> (ø) ⬆️
cli/command/image/build.go 41.64% <100%> (+0.3%) ⬆️
cli/command/container/create.go 45.39% <50%> (+0.05%) ⬆️
cli/command/image/trust.go 21.78% <50%> (ø) ⬆️
cli/command/image/pull.go 77.08% <75%> (+0.99%) ⬆️
cli/compose/convert/service.go 35.41% <0%> (-1.69%) ⬇️
cli/compose/loader/loader.go 82.03% <0%> (-0.11%) ⬇️
cli/command/trust/cmd.go 0% <0%> (ø) ⬆️
cli/trust/trust.go 10% <0%> (ø) ⬆️
... and 11 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1dc89aa...d8b7825. Read the comment docs.

@lowenna
Copy link
Contributor Author

lowenna commented Oct 30, 2017

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?

@lowenna
Copy link
Contributor Author

lowenna commented Oct 30, 2017

@johnstep PTAL too. Thanks.

Copy link
Contributor

@dnephin dnephin left a 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()incmd/docker/docker.go`.


// PlatformFromEnvironment sets the platform from an environment variable
// if it isn't otherwise populated.
func PlatformFromEnvironment(platform string) string {
Copy link
Contributor

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"), ...)

Copy link
Contributor Author

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.

Copy link
Contributor

@dnephin dnephin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@johnstep
Copy link
Contributor

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).
@lowenna
Copy link
Contributor Author

lowenna commented Oct 31, 2017

@johnstep - OK, added that annotation in utils.go::AddPlatformFlag() and verified it operates as expected.

Copy link
Contributor

@johnstep johnstep left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lowenna
Copy link
Contributor Author

lowenna commented Nov 3, 2017

Is this OK to merge with 2 LGTM's?

Copy link
Collaborator

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🐮

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants