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

feat: add platform flag to cosign copy command #3234

Merged
merged 8 commits into from
Sep 16, 2023

Conversation

vishal-chdhry
Copy link
Contributor

@vishal-chdhry vishal-chdhry commented Sep 10, 2023

Signed-off-by: Vishal Choudhary sendtovishalchoudhary@gmail.com

Summary

Fixes: #2748

This PR adds a --platform flag to cosign copy. This allows copying images and signatures for specific platform/architecture.

/cc @imjasonh @znewman01 @cpanato

Before:

cosign copy alpine ttl.sh/test-cosign-copy:5m
Copying index.docker.io/library/alpine@sha256:5febc00b4d2a84af2a077bc34ea90659b6570110a54253f19c5dca8164b1dbf6 to ttl.sh/test-cosign-copy:sha256:5febc00b4d2a84af2a077bc34ea90659b6570110a54253f19c5dca8164b1dbf6...
Copying index.docker.io/library/alpine@sha256:b312e4b0e2c665d634602411fcb7c2699ba748c36f59324457bc17de485f36f6 to ttl.sh/test-cosign-copy:sha256:b312e4b0e2c665d634602411fcb7c2699ba748c36f59324457bc17de485f36f6...
Copying index.docker.io/library/alpine@sha256:f748290eb66ad6f938e25dd348acfb3527a422e280b7547b1cdfaf38d4492c4b to ttl.sh/test-cosign-copy:sha256:f748290eb66ad6f938e25dd348acfb3527a422e280b7547b1cdfaf38d4492c4b...
Copying index.docker.io/library/alpine@sha256:16e86b2388774982fbdf230101a72201691b1f97cb0066c2099abf30dd7e6d59 to ttl.sh/test-cosign-copy:sha256:16e86b2388774982fbdf230101a72201691b1f97cb0066c2099abf30dd7e6d59...
Copying index.docker.io/library/alpine@sha256:c75ede79e457d6454bca6fc51967a247a4b9daff9f31197cfbef69b1a651cada to ttl.sh/test-cosign-copy:sha256:c75ede79e457d6454bca6fc51967a247a4b9daff9f31197cfbef69b1a651cada...
Copying index.docker.io/library/alpine@sha256:7144f7bab3d4c2648d7e59409f15ec52a18006a128c733fcff20d3a4a54ba44a to ttl.sh/test-cosign-copy:sha256:7144f7bab3d4c2648d7e59409f15ec52a18006a128c733fcff20d3a4a54ba44a...
Copying index.docker.io/library/alpine@sha256:c5c5fda71656f28e49ac9c5416b3643eaa6a108a8093151d6d1afc9463be8e33 to ttl.sh/test-cosign-copy:sha256:c5c5fda71656f28e49ac9c5416b3643eaa6a108a8093151d6d1afc9463be8e33...
Copying index.docker.io/library/alpine@sha256:1fd62556954250bac80d601a196bb7fd480ceba7c10e94dd8fd4c6d1c08783d5 to ttl.sh/test-cosign-copy:sha256:1fd62556954250bac80d601a196bb7fd480ceba7c10e94dd8fd4c6d1c08783d5...
Copying index.docker.io/library/alpine@sha256:7144f7bab3d4c2648d7e59409f15ec52a18006a128c733fcff20d3a4a54ba44a to ttl.sh/test-cosign-copy:5m...

After:

go run ./cmd/cosign copy --platform=linux/amd64 alpine ttl.sh/test-cosign-copy-local:5m
Copying index.docker.io/library/alpine@sha256:c5c5fda71656f28e49ac9c5416b3643eaa6a108a8093151d6d1afc9463be8e33 to ttl.sh/test-cosign-copy-local:sha256-c5c5fda71656f28e49ac9c5416b3643eaa6a108a8093151d6d1afc9463be8e33...
Copying index.docker.io/library/alpine@sha256:c5c5fda71656f28e49ac9c5416b3643eaa6a108a8093151d6d1afc9463be8e33 to ttl.sh/test-cosign-copy-local:5m...

Release Note

Added --platform flag to cosign copy command

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>
Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>
Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>
Copy link
Contributor

@znewman01 znewman01 left a comment

Choose a reason for hiding this comment

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

Thank you very much for this change! I left some minor feedback

cmd/cosign/cli/common/platform.go Outdated Show resolved Hide resolved
cmd/cosign/cli/copy/copy_test.go Show resolved Hide resolved
cmd/cosign/cli/copy/copy.go Outdated Show resolved Hide resolved
cmd/cosign/cli/copy/copy.go Outdated Show resolved Hide resolved
cmd/cosign/cli/copy/copy.go Outdated Show resolved Hide resolved
Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>
@codecov
Copy link

codecov bot commented Sep 16, 2023

Codecov Report

Merging #3234 (dab95a2) into main (0d48aa1) will decrease coverage by 0.03%.
Report is 9 commits behind head on main.
The diff coverage is 15.38%.

@@            Coverage Diff             @@
##             main    #3234      +/-   ##
==========================================
- Coverage   30.37%   30.35%   -0.03%     
==========================================
  Files         155      155              
  Lines        9828     9845      +17     
==========================================
+ Hits         2985     2988       +3     
- Misses       6397     6410      +13     
- Partials      446      447       +1     
Files Changed Coverage Δ
cmd/cosign/cli/copy.go 0.00% <0.00%> (ø)
cmd/cosign/cli/options/copy.go 0.00% <0.00%> (ø)
cmd/cosign/cli/copy/copy.go 49.09% <40.00%> (-0.91%) ⬇️

... and 6 files with indirect coverage changes

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>
Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>
@vishal-chdhry
Copy link
Contributor Author

@znewman01 I have added a unit test as well as a example in pull request description. Can you please review it again

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>
Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>
@@ -19,6 +19,9 @@ cosign copy [flags]

# overwrite destination image and signatures
cosign copy -f example.com/src example.com/dest

# copy a container image and its signatures for a specific platform
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: can you dedent this line?

@znewman01 znewman01 merged commit 80def23 into sigstore:main Sep 16, 2023
28 checks passed
@github-actions github-actions bot added this to the v2.3.0 milestone Sep 16, 2023
lance pushed a commit to securesign/cosign that referenced this pull request Sep 25, 2023
* feat: add platform flag to copy

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: extract platformList to common package

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* add platform check to copycmd

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* refactor: add platform package in pkg/oci

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: add a unit test

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: add boilerplate

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: export platform list type

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* lint: fix linting errors

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

---------

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>
@cpanato cpanato modified the milestones: v2.3.0, v2.2.1 Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cosign copy multi arch/platform support
3 participants