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

c8d: Add --platform flag to history, save and load #5331

Merged
merged 3 commits into from
Oct 10, 2024

Conversation

vvoland
Copy link
Collaborator

@vvoland vvoland commented Aug 8, 2024

Add --platform flag to history, save and load.

- Description for the changelog

containerd image store: `docker load` and `docker save` now support a `--platform` flag allowing to choose a specific single-platform image to load/save if the image is multi-platform
containerd image store: `docker history` now supports a `--platform` flag allowing to choose a specific platform to show the history for.

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

@vvoland vvoland added impact/changelog area/api area/ux containerd-integration Issues and PRs related to containerd integration labels Aug 8, 2024
@vvoland vvoland added this to the 28.0.0 milestone Aug 8, 2024
@vvoland vvoland requested review from a team and dvdksn August 8, 2024 11:22
@vvoland vvoland force-pushed the c8d-saveload-platform branch from 2ee583e to b3139f5 Compare August 8, 2024 13:45
@vvoland vvoland self-assigned this Sep 6, 2024
@thaJeztah thaJeztah force-pushed the c8d-saveload-platform branch from b3139f5 to 8f20d2e Compare September 24, 2024 11:48
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"`)
Copy link
Contributor

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?

Suggested change
Example: "linux/amd64"`)
Example: "docker image history --platform linux/amd64"`)

Copy link
Member

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

Comment on lines 47 to 52
`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"`)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
`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"`)

Comment on lines 45 to 49
`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"`)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
`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"`)

@thaJeztah thaJeztah force-pushed the c8d-saveload-platform branch from 8f20d2e to 400f5f0 Compare September 24, 2024 14:32
@codecov-commenter
Copy link

codecov-commenter commented Sep 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 60.67%. Comparing base (6a78e92) to head (d085e24).
Report is 4 commits behind head on master.

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              

@thaJeztah thaJeztah force-pushed the c8d-saveload-platform branch from 400f5f0 to 8ebf4cf Compare September 24, 2024 15:19
@thaJeztah thaJeztah marked this pull request as ready for review September 24, 2024 15:19
@thaJeztah thaJeztah requested a review from a team as a code owner September 24, 2024 15:19
Comment on lines 52 to 53
`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.
Copy link
Member

@thaJeztah thaJeztah Sep 24, 2024

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)

Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Member

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.

@laurazard
Copy link
Member

laurazard commented Oct 4, 2024

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

@dvdksn
Copy link
Contributor

dvdksn commented Oct 4, 2024

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

@thaJeztah
Copy link
Member

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

@thaJeztah
Copy link
Member

Oh! Should mention that I didn't squash / cleanup commits yet; will do so before merging if this looks good.

@thaJeztah thaJeztah force-pushed the c8d-saveload-platform branch from 7731583 to 5412e96 Compare October 8, 2024 13:36
Copy link
Contributor

@krissetto krissetto left a 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.
Copy link
Contributor

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?

Copy link
Member

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.

Copy link
Contributor

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

Choose a reason for hiding this comment

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

nit

Suggested change
The platform option takes the `os[/arch[/variant]]` format, for example,
The platform option takes the `os[/arch[/variant]]` format, for example

Copy link
Member

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

Copy link
Contributor

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 😄

Copy link
Member

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.

Copy link
Contributor

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

Copy link
Member

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 🥹

Comment on lines 96 to 98
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;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
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;

Copy link
Member

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.

docs/reference/commandline/image_load.md Outdated Show resolved Hide resolved
docs/reference/commandline/image_load.md Outdated Show resolved Hide resolved
docs/reference/commandline/image_save.md Outdated Show resolved Hide resolved
Comment on lines 76 to 78
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;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
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;

@thaJeztah thaJeztah force-pushed the c8d-saveload-platform branch from 5412e96 to d30d61a Compare October 8, 2024 14:48
@thaJeztah thaJeztah force-pushed the c8d-saveload-platform branch from d30d61a to c656e2e Compare October 8, 2024 14:54
@thaJeztah
Copy link
Member

let me start cleaning up the commit history on this one to bring it in a mergable state

Comment on lines 80 to 81
_, _ = fmt.Fprintf(dockerCli.Err(), "Invalid platform %s", opts.platform)
return err
Copy link
Member

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.

Copy link
Member

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

@thaJeztah
Copy link
Member

LOL, and there I thought "let me add some basic unit-tests" and scratching my head "why doesn't it fail??"

@thaJeztah thaJeztah force-pushed the c8d-saveload-platform branch from c656e2e to c7cc278 Compare October 8, 2024 18:37
@thaJeztah
Copy link
Member

OK; this should probably be ready for review / merge now;

docs/reference/commandline/image_history.md Outdated Show resolved Hide resolved
docs/reference/commandline/image_history.md Outdated Show resolved Hide resolved
docs/reference/commandline/image_history.md Outdated Show resolved Hide resolved
docs/reference/commandline/image_load.md Outdated Show resolved Hide resolved
docs/reference/commandline/image_save.md Outdated Show resolved Hide resolved
docs/reference/commandline/image_save.md Outdated Show resolved Hide resolved
@laurazard
Copy link
Member

Oops, meant to comment/hit the other button. Just had found some typos/suggestions, otherwise it looks good.

@thaJeztah thaJeztah force-pushed the c8d-saveload-platform branch from c7cc278 to 6acec20 Compare October 10, 2024 12:59
@thaJeztah
Copy link
Member

Updated! I think I got them all, @laurazard

Copy link
Member

@laurazard laurazard left a comment

Choose a reason for hiding this comment

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

LGTM

docs/reference/commandline/image_save.md Outdated Show resolved Hide resolved
docs/reference/commandline/image_save.md Outdated Show resolved Hide resolved
docs/reference/commandline/image_load.md Outdated Show resolved Hide resolved
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]>
@thaJeztah thaJeztah force-pushed the c8d-saveload-platform branch from 6acec20 to d085e24 Compare October 10, 2024 15:00
Copy link
Contributor

@dvdksn dvdksn 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
Labels
area/api area/ux containerd-integration Issues and PRs related to containerd integration impact/changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants