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

add shell-completion for --platform flags #5516

Merged
merged 3 commits into from
Oct 8, 2024

Conversation

thaJeztah
Copy link
Member

cli/command/completion: add Platforms

Add a utility for completing platform strings.

Platforms offers completion for platform-strings. It provides a non-exhaustive
list of platforms to be used for completion. Platform-strings are based on
[runtime.GOOS] and [runtime.GOARCH], but with (optional) variants added. A
list of recognised os/arch combinations from the Go runtime can be obtained
through "go tool dist list".

Some noteworthy exclusions from this list:

  • arm64 images ("windows/arm64", "windows/arm64/v8") do not yet exist for windows.
  • we don't (yet) include os-variant for completion (as can be used for Windows images)
  • we don't (yet) include platforms for which we don't build binaries, such as
    BSD platforms (freebsd, netbsd, openbsd), android, macOS (darwin).
  • we currently exclude architectures that may have unofficial builds,
    but don't have wide adoption (and no support), such as loong64, mipsXXX,
    ppc64 (non-le) to prevent confusion.

cli/command/container: add shell completion for --platform flags

With this patch, completion is provided for --platform flags:

docker run --platform<TAB>
linux           linux/amd64     linux/arm/v5    linux/arm/v7    linux/arm64/v8  linux/riscv64   wasip1          windows
linux/386       linux/arm       linux/arm/v6    linux/arm64     linux/ppc64le   linux/s390x     wasip1/wasm     windows/amd64

cli/command/image: add shell completion for --platform flags

With this patch, completion is provided for --platform flags:

docker pull --platform<TAB>
linux           linux/amd64     linux/arm/v5    linux/arm/v7    linux/arm64/v8  linux/riscv64   wasip1          windows
linux/386       linux/arm       linux/arm/v6    linux/arm64     linux/ppc64le   linux/s390x     wasip1/wasm     windows/amd64

Note that docker buildx build (with BuildKit) does not yet provide completion;
it's provided through buildx, and uses a different format (accepting multiple
comma-separated platforms). Interestingly, tab-completion for docker build
currently uses completion for non-buildkit, and has some other issues that may
have to be looked into.

- How to verify it

- Description for the changelog

add shell-completion for --platform flags

- A picture of a cute animal (not mandatory but encouraged)

Add a utility for completing platform strings.

Platforms offers completion for platform-strings. It provides a non-exhaustive
list of platforms to be used for completion. Platform-strings are based on
[runtime.GOOS] and [runtime.GOARCH], but with (optional) variants added. A
list of recognised os/arch combinations from the Go runtime can be obtained
through "go tool dist list".

Some noteworthy exclusions from this list:

  - arm64 images ("windows/arm64", "windows/arm64/v8") do not yet exist for windows.
  - we don't (yet) include `os-variant` for completion (as can be used for Windows images)
  - we don't (yet) include platforms for which we don't build binaries, such as
    BSD platforms (freebsd, netbsd, openbsd), android, macOS (darwin).
  - we currently exclude architectures that may have unofficial builds,
    but don't have wide adoption (and no support), such as loong64, mipsXXX,
    ppc64 (non-le) to prevent confusion.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
With this patch, completion is provided for `--platform` flags:

    docker run --platform<TAB>
    linux           linux/amd64     linux/arm/v5    linux/arm/v7    linux/arm64/v8  linux/riscv64   wasip1          windows
    linux/386       linux/arm       linux/arm/v6    linux/arm64     linux/ppc64le   linux/s390x     wasip1/wasm     windows/amd64

Signed-off-by: Sebastiaan van Stijn <[email protected]>
With this patch, completion is provided for `--platform` flags:

    docker pull --platform<TAB>
    linux           linux/amd64     linux/arm/v5    linux/arm/v7    linux/arm64/v8  linux/riscv64   wasip1          windows
    linux/386       linux/arm       linux/arm/v6    linux/arm64     linux/ppc64le   linux/s390x     wasip1/wasm     windows/amd64

Note that `docker buildx build` (with BuildKit) does not yet provide completion;
it's provided through buildx, and uses a different format (accepting multiple
comma-separated platforms). Interestingly, tab-completion for `docker build`
currently uses completion for non-buildkit, and has some other issues that may
have to be looked into.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
@codecov-commenter
Copy link

codecov-commenter commented Oct 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 60.25%. Comparing base (55ae7d7) to head (d42cf96).
Report is 50 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5516      +/-   ##
==========================================
- Coverage   60.26%   60.25%   -0.02%     
==========================================
  Files         345      345              
  Lines       23448    23456       +8     
==========================================
+ Hits        14132    14134       +2     
- Misses       8341     8351      +10     
+ Partials      975      971       -4     

//
// - arm64 images ("windows/arm64", "windows/arm64/v8") do not yet exist for windows.
// - we don't (yet) include `os-variant` for completion (as can be used for Windows images)
// - we don't (yet) include platforms for which we don't build binaries, such as
Copy link
Contributor

Choose a reason for hiding this comment

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

regarding these values, could they still be found in some image manifest?

If we don't provide builds for these archs, i assume we don't support executing them either, is that correct? Just thinking if there are scenarios in which we could execute an image but the platform wouldn't show up because we don't support building them

Copy link
Member Author

Choose a reason for hiding this comment

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

Technically, these could be "anything". i.e., I can push an image with platform hello/world and I would be able to pull it. The engine would also try to run it, but depending on what's in it, it may fail.

I mostly here tried to provide a list of "here's probably what you may be looking for" options; with the assumption that tab-completions are really "to assist" but the user can still pass any value they'd want that's not included in the list.

@thaJeztah
Copy link
Member Author

Thanks! I'll bring this one in, and update #5331 to also provide completion for the new flags added there.

@thaJeztah thaJeztah merged commit eb53046 into docker:master Oct 8, 2024
110 checks passed
@thaJeztah thaJeztah deleted the complete_platforms branch October 8, 2024 13:26
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.

4 participants