-
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
c8d: Add --platform
flag to history, save and load
#5331
Conversation
2ee583e
to
b3139f5
Compare
b3139f5
to
8f20d2e
Compare
cli/command/image/history.go
Outdated
If the platform is not specified, the host platform is preferred if it's available, otherwise any available platform is used. | ||
|
||
Format: os[/arch[/variant]] | ||
Example: "linux/amd64"`) |
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.
How about including the full cmd?
Example: "linux/amd64"`) | |
Example: "docker image history --platform linux/amd64"`) |
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 (somewhat) assume that this was done to allow defining a global const
for these flags and for them to be shared (similar to what we did for --format
🤔), but I need to check if they differ in other ways
cli/command/image/load.go
Outdated
`Pick a single-platform to be loaded if the image is multi-platform. | ||
Full multi-platform image will be load if not specified. | ||
|
||
Format: os[/arch[/variant]] | ||
Example: "linux/amd64"`) |
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.
`Pick a single-platform to be loaded if the image is multi-platform. | |
Full multi-platform image will be load if not specified. | |
Format: os[/arch[/variant]] | |
Example: "linux/amd64"`) | |
`Specify a platform from a multi-platform image to load. | |
If a platform is not specified, and the image is a multi-platform image, all platforms are loaded. | |
Format: os[/arch[/variant]] | |
Example: "docker image load --platform linux/amd64"`) |
cli/command/image/save.go
Outdated
`Pick a single-platform to be saved if the image is multi-platform. | ||
Full multi-platform image will be saved if not specified. | ||
|
||
Format: os[/arch[/variant]] | ||
Example: "linux/amd64"`) |
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.
`Pick a single-platform to be saved if the image is multi-platform. | |
Full multi-platform image will be saved if not specified. | |
Format: os[/arch[/variant]] | |
Example: "linux/amd64"`) | |
`Specify a platform from a multi-platform image to save. | |
If a platform is not specified, and the image is a multi-platform image, all platform variants are saved. | |
Format: os[/arch[/variant]] | |
Example: "docker image save --platform linux/amd64"`) |
8f20d2e
to
400f5f0
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #5331 +/- ##
==========================================
+ Coverage 60.63% 60.67% +0.04%
==========================================
Files 345 345
Lines 23462 23488 +26
==========================================
+ Hits 14226 14252 +26
Misses 8263 8263
Partials 973 973 |
400f5f0
to
8ebf4cf
Compare
cli/command/image/history.go
Outdated
`Specify a platform from a multi-platform image to show the history for. | ||
If the platform is not specified, the host platform is preferred if it's available, otherwise any available platform is used. |
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.
@dvdksn I applied your suggestions; I'm slightly wondering if we should / could condense the information a bit; for example;
Specify a platform
-> Platform from a multi-platform image ...
(I don't think we generally add Specify ....
as that's a bit implicit for options?)
The "format" could possibly be included in the first line, something like;
Platform from a multi-platform image to show the history for (format: "os[/arch[/variant]]")
By default, the daemon's native platform is preferred, otherwise any available platform is used.
(wondering if the host platform
is ambiguous, and if we need to emphasise daemon
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 also think we should probably change "any available platform is used" to something more precise.. what does "any" mean in this context? the first available platform in alphabetical order?
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.
@thaJeztah your suggestion sgtm. Coming back to this I realize that multi-line flag descriptions are kinda exotic - we don't use them a lot. Maybe we should instead create sections in the respective .md
files for the platform
flag, like we usually do, to show examples.
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.
IMO, if there is a specific behavior we've decide is part of the contract "i.e. it's always the first alphabetical one", then we should make that explicit. On the other hand, if we explicitly don't want to make any future guarantees about which platform is used, then any is fine. I honestly kind of would rather just return an error if there's no platform for the given image, but 🤷♀️ it's not a big deal either way, especially for history
.
8ebf4cf
to
3b97d52
Compare
I had a thought while looking at this again today – I think it would be really nice if we had a main .md file/doc with a general explanation about multi-platform images – i.e. "this is a new feature available on docker if the containerd store integration is enabled, it's kind of like the old images but now each image is actually an index and may contain multiple "images" for different platforms, etc.,". We could link there from a lot of other places, and we could also have a little table with the different commands that take a parameter to specify a platform if relevant, and I think it'd tie a lot of things together that we're kind of leaving implied/are spread out through a lot of different places/docs right now. Kind of like the multi-platform build doc for Build. cc @thaJeztah @dvdksn |
@laurazard the multi-platform builds page has some of that. I agree it would be nice with a general "what's an image, actually" primer. We should probably consider OCI the typical format by now — buildx will default to them more often than not, and with containerd becoming the default storage, it feels like the transition is coming sooner rather than later. Single-platform manifests is a legacy format in my world. |
3b97d52
to
7731583
Compare
@dvdksn @laurazard I rewrote the PR to have a short description for the flags, and move the description to the docs. There's still some issues/bugs to fix on the daemon side (as I found some issues while working on the docs; moby/moby#48589) |
Oh! Should mention that I didn't squash / cleanup commits yet; will do so before merging if this looks good. |
7731583
to
5412e96
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.
overall LGTM, just left a few nits in the long-form docs
The `--platform` option allows you to specify which platform-variant to show | ||
history for if multiple platforms are present. By default, `docker history` | ||
shows the history for the daemon's native platform or if not present, the | ||
first available 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.
the first available platform found in alphabetical order?
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.
Yeah, I think this relates a bit to the other comments above; I kept it somewhat "on the surface here" because I also didn't want to document it as a strict behavior. We need to define some of that in more details; "first available" may also be "best match", which may not be "alphabetical", i.e., if amd64
and arm64
are present, this should pick arm64
as a default (on arm), and amd64
(on x86).
So perhaps even "first available" is wrong already.
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.
Sounds good to me if we want to define this a bit better somewhere else (or leave the road open to a better definition at a later point, without adding to user expectations)
`--platform` option selects which variant to show the history for. An error | ||
is produced if the given platform is not present in the local image cache. | ||
|
||
The platform option takes the `os[/arch[/variant]]` format, for example, |
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.
nit
The platform option takes the `os[/arch[/variant]]` format, for example, | |
The platform option takes the `os[/arch[/variant]]` format, for example |
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.
Let me check with the grammar police (@dvdksn 🙏 ), but I think it's recommended to always follow for example
with a comma. Perhaps it should start with a new sentence here though (format. For example, ...
)
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.
the word man! anyway these were just my 2 cents, so feel free to merge whenever 😄
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.
And, answering myself, because I noticed I copy/pasted parts of the flag descriptions and used e.g.
without a comma; https://english.stackexchange.com/a/16173
E.g. (exempli gratia in Latin, meaning “for example”) should be generally followed by a list of examples. Thus, adhering to proper English style usually requires commas to follow e.g. to delimit the beginning of that list.
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.
If the "For example" starts the sentence, I agree with having the comma after it. As is, when reading the sentence it feel strange to pause both before and after "for example", because it makes it sound like the example came before (causing some confusion, at least to myself 😄).
Definitely minutia though
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.
Yeah; these are hard. I basically tried to avoid ending up with "3 word sentences" because that also felt a bit silly (which is why I used the comma before example
). I updated to use a semicolon instead, but not sure if that's 100% grammatically correct either 🥹
The following examples pulls an `alpine` image for the daemon's native platform, | ||
and shows the history, then provides a custom platform, which fails until the | ||
given platform-variant is pulled; |
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.
nit:
The following examples pulls an `alpine` image for the daemon's native platform, | |
and shows the history, then provides a custom platform, which fails until the | |
given platform-variant is pulled; | |
The following example: | |
- pulls an `alpine` image for the daemon's native platform (because `--platform` is omitted); | |
- shows the history (also for the default platform, because `--platform` is omitted); | |
- tries to show the history for the image while providing a custom `--platform` value, which fails until the given platform-variant is pulled; |
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! Forgot to reply on these; I've been going back and forth a bit if this approach would be making things better (much more in depth) or if it would be "too much".
Happy to hear from others though. Also happy to make changes along these lines in a follow up.
The following examples pulls an `alpine` image for the daemon's native platform, | ||
then provides a custom platform, which fails until the given platform-variant | ||
is pulled; |
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.
nit:
The following examples pulls an `alpine` image for the daemon's native platform, | |
then provides a custom platform, which fails until the given platform-variant | |
is pulled; | |
The following example: | |
- pulls an `alpine` image for the daemon's native platform (because `--platform` is omitted); | |
- tries to save the image while providing a custom `--platform` value, which fails until the given platform-variant is pulled; |
5412e96
to
d30d61a
Compare
d30d61a
to
c656e2e
Compare
let me start cleaning up the commit history on this one to bring it in a mergable state |
cli/command/image/load.go
Outdated
_, _ = fmt.Fprintf(dockerCli.Err(), "Invalid platform %s", opts.platform) | ||
return err |
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 just realised that this isn't correct; it tries to both print something as well as returning an error. The printed message is without a newline. But also, because the error is returned, both the printed message and the error get printed;
docker image save -o image-amd64.tar --platform in:valid/foo:bar alpine:latest
Invalid platform in:valid/foo:bar"in:valid" is an invalid OS component of "in:valid/foo:bar": OSAndVersion specifier component must match "^([A-Za-z0-9_-]+)(?:\\(([A-Za-z0-9_.-]*)\\))?$": invalid argument
I wondered if this was perhaps done for cases where no output file is specified (so the tar output would be redirected), but the same happens in that case;
docker image save --platform in:valid/foo:bar alpine:latest > file.tar
Invalid platform in:valid/foo:bar"in:valid" is an invalid OS component of "in:valid/foo:bar": OSAndVersion specifier component must match "^([A-Za-z0-9_-]+)(?:\\(([A-Za-z0-9_.-]*)\\))?$": invalid argument
So I think this should just wrap the error and return it.
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.
Updated these to just return the error
LOL, and there I thought "let me add some basic unit-tests" and scratching my head "why doesn't it fail??" |
c656e2e
to
c7cc278
Compare
OK; this should probably be ready for review / merge now;
|
Oops, meant to comment/hit the other button. Just had found some typos/suggestions, otherwise it looks good. |
c7cc278
to
6acec20
Compare
Updated! I think I got them all, @laurazard |
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: Paweł Gronowski <[email protected]> Signed-off-by: Sebastiaan van Stijn <[email protected]> Signed-off-by: Sebastiaan van Stijn <[email protected]>
Signed-off-by: Paweł Gronowski <[email protected]> Signed-off-by: Sebastiaan van Stijn <[email protected]>
Signed-off-by: Paweł Gronowski <[email protected]> Signed-off-by: Sebastiaan van Stijn <[email protected]>
6acec20
to
d085e24
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 🚀
platform
parameter to history, save and load moby/moby#48295Add
--platform
flag to history, save and load.- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)