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

cli/push: Add platform switch #4984

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

vvoland
Copy link
Contributor

@vvoland vvoland commented Apr 4, 2024

- What I did
Added a platform switch to docker image push.

- How I did it

- How to verify it

$ docker pull --platform linux/arm64 busybox
$ docker tag busybox myimage
$ docker push --platform linux/arm64 myimage

- Description for the changelog

containerd image store: Add `--platform` switch to `docker image push`.

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

@codecov-commenter
Copy link

codecov-commenter commented Apr 5, 2024

Codecov Report

Attention: Patch coverage is 26.92308% with 19 lines in your changes are missing coverage. Please review.

Project coverage is 61.04%. Comparing base (6c70360) to head (cd1d450).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4984      +/-   ##
==========================================
- Coverage   61.09%   61.04%   -0.05%     
==========================================
  Files         298      295       -3     
  Lines       20675    20692      +17     
==========================================
+ Hits        12631    12632       +1     
- Misses       7147     7161      +14     
- Partials      897      899       +2     

@@ -84,6 +86,7 @@ func RunPush(ctx context.Context, dockerCli command.Cli, opts pushOptions) error
All: opts.all,
RegistryAuth: encodedAuth,
PrivilegeFunc: requestPrivilege,
Platform: opts.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.

Warn that it will strip attestations (suggested by @thaJeztah)

@vvoland vvoland marked this pull request as ready for review April 9, 2024 16:08
@vvoland vvoland requested a review from thaJeztah as a code owner April 9, 2024 16:08

return cmd
}

// RunPush performs a push against the engine based on the specified options
func RunPush(ctx context.Context, dockerCli command.Cli, opts pushOptions) error {
if opts.platform != "" {
if _, isTty := term.GetFdInfo(dockerCli.Err()); isTty {
_, _ = fmt.Fprint(dockerCli.Err(), "\x1b[1;37m\x1b[1;46m[ NOTE ]\x1b[0m\x1b[0m ")
Copy link
Member

Choose a reason for hiding this comment

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

There is no need to repeat the reset here, only one is enough: \x1b[0m\x1b[0m -> \x1b[0m

Copy link
Member

Choose a reason for hiding this comment

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

Do we really want to add the cyan background color here? Why not \x1b[36m to just color the text?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah good catch, no idea how that second one sneaked in there!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No strong opinions on the colors, I just went with a colored background to make it more visible:

image

It could look wildly different on other terminals/color schemes, so perhaps a text color would be a safer option.

Comment on lines 73 to 74
_, _ = fmt.Fprintln(dockerCli.Err(), `Selecting a single platform for the push operation will push the image manifest for that platform only.
This won't push the image index/manifest list which means that other components like Buildkit attestations won't be pushed.
Copy link
Member

Choose a reason for hiding this comment

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

Thinking about the wording here, we are talking about image manifests, index, manifest list, do we really need to be this specific? Shouldn't we have a more user-friendly terms like "single-platform image" and "multi-platform image"?

No one really wants to know the difference between an index and a manifest list :)

}
_, _ = fmt.Fprintln(dockerCli.Err(), `Selecting a single platform for the push operation will push the image manifest for that platform only.
This won't push the image index/manifest list which means that other components like Buildkit attestations won't be pushed.
If you want to only push a single platform while preserving the attestations, please build an image with only that platform and push it instead.`)
Copy link
Member

Choose a reason for hiding this comment

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

Related to the above, after talking about manifests manifest lists and indexes we say "single 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.

The problem is that "single platform" isn't always a 1:1 mapping between an index and a single manifest.

Is the index below a single platform image or a multi-platform image?

{
  "schemaVersion": 2,
  "mediaType": "application/vnd.oci.image.index.v1+json",
  "manifests": [
    {
      "mediaType": "application/vnd.oci.image.manifest.v1+json",
      "digest": "sha256:34b7d4a2f050f8a9077fd435b3b1778e091af743f0f4c8c47d109cfda47b0c48",
      "size": 480,
      "platform": {
        "architecture": "arm64",
        "os": "linux"
      }
    },
    {
      "mediaType": "application/vnd.oci.image.manifest.v1+json",
      "digest": "sha256:a7931924962b793438f641b320d496ebca34968e850f7b8d7a5ea59dc88283cc",
      "size": 565,
      "annotations": {
        "vnd.docker.reference.digest": "sha256:34b7d4a2f050f8a9077fd435b3b1778e091af743f0f4c8c47d109cfda47b0c48",
        "vnd.docker.reference.type": "attestation-manifest"
      },
      "platform": {
        "architecture": "unknown",
        "os": "unknown"
      }
    }
  ]
}

@vvoland vvoland force-pushed the c8d-multiplatform-push branch 3 times, most recently from 9e024b2 to 13ffd29 Compare May 10, 2024 14:17
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Signatures of these functions were changed in 80d92fd45007b6395dc2db5f93def3b159dacd7f

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
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.

None yet

3 participants