Skip to content

LCOW: CLI changes to add platform flag - pull, run, create and build - #474

Merged
thaJeztah merged 1 commit into
docker:masterfrom
lowenna:jjh/apis-for-platform
Nov 7, 2017
Merged

LCOW: CLI changes to add platform flag - pull, run, create and build#474
thaJeztah merged 1 commit into
docker:masterfrom
lowenna:jjh/apis-for-platform

Conversation

@lowenna

@lowennalowenna commented Aug 27, 2017

Copy link
Copy Markdown
Contributor

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

Comment threadcli/command/commands/commands.go Outdated
hide(container.NewLogsCommand(dockerCli)),
hide(container.NewPauseCommand(dockerCli)),
hide(container.NewPortCommand(dockerCli)),
hide(image.NewPullCommand(dockerCli)),

Copy link
Copy Markdown
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

Comment threadcli/command/container/run.go Outdated
hostConfig := containerConfig.HostConfig
stdout, stderr := dockerCli.Out(), dockerCli.Err()
client := dockerCli.Client()
ociPlatform := system.ParsePlatform(opts.platform)

Copy link
Copy Markdown
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

Comment threadcli/command/container/run.go Outdated
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
Copy Markdown
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

funcaddPlatformFlag(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

NewLoadCommand(dockerCli),
NewPullCommand(dockerCli),
NewPushCommand(dockerCli),
NewPullCommand(dockerCli),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

unsorted

Comment threadcli/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")

@dnephindnephinAug 28, 2017

Copy link
Copy Markdown
Contributor

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
lowennaforce-pushed the jjh/apis-for-platform branch from 5f89aff to 03fb697CompareSeptember 13, 2017 20:07
@lowenna

Copy link
Copy Markdown
ContributorAuthor

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
lowennaforce-pushed the jjh/apis-for-platform branch from 03fb697 to d186bc3CompareSeptember 19, 2017 01:46
@lowenna
lowennaforce-pushed the jjh/apis-for-platform branch 5 times, most recently from 8f7375e to 8abdebaCompareOctober 30, 2017 18:44
@lowennalowenna 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 buildOct 30, 2017
@codecov-io

codecov-io commented Oct 30, 2017

Copy link
Copy Markdown

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 FilesCoverage Δ
cli/command/container/run.go0% <0%> (ø)⬆️
cli/command/utils.go0% <0%> (ø)⬆️
cli/command/image/build.go41.64% <100%> (+0.3%)⬆️
cli/command/container/create.go45.39% <50%> (+0.05%)⬆️
cli/command/image/trust.go21.78% <50%> (ø)⬆️
cli/command/image/pull.go77.08% <75%> (+0.99%)⬆️
cli/compose/convert/service.go35.41% <0%> (-1.69%)⬇️
cli/compose/loader/loader.go82.03% <0%> (-0.11%)⬇️
cli/command/trust/cmd.go0% <0%> (ø)⬆️
cli/trust/trust.go10% <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
Copy Markdown
ContributorAuthor

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
Copy Markdown
ContributorAuthor

@johnstep PTAL too. Thanks.

@dnephindnephin left a comment

Copy link
Copy Markdown
Contributor

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`.

Comment threadcli/command/utils.go Outdated

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

Copy link
Copy Markdown
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
Copy Markdown
ContributorAuthor

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.

@lowenna
lowennaforce-pushed the jjh/apis-for-platform branch from 8abdeba to a5e4e1dCompareOctober 30, 2017 20:59

@dnephindnephin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@johnstep

Copy link
Copy Markdown
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
lowennaforce-pushed the jjh/apis-for-platform branch from a5e4e1d to d8b7825CompareOctober 31, 2017 16:50
@lowenna

Copy link
Copy Markdown
ContributorAuthor

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

@johnstepjohnstep left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@lowenna

Copy link
Copy Markdown
ContributorAuthor

Is this OK to merge with 2 LGTM's?

@vdemeestervdemeester left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM 🐮

@thaJeztahthaJeztah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

Sign up for freeto 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

@lowenna@codecov-io@johnstep@vdemeester@dnephin@thaJeztah@GordonTheTurtle