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 option to push command #1500

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

TerryHowe
Copy link
Member

@TerryHowe TerryHowe commented Sep 16, 2024

What this PR does / why we need it:

Add the platform option to the push command for example:

oras push --plain-http localhost:15000/oras:darwin,arm64  --artifact-platform darwin/arm64 --artifact-type 'application/vnd.oci.image.config.v1+json'  bin/darwin/arm64/oras:application/x-elf

Create the manifest for example:

oras manifest index create localhost:15000/oras:v1 sha256:ed3691788db69623790c46256dd11d8d6edc31be6e4762b53c74dfc3bb6792cf

The results

% oras manifest fetch --pretty localhost:15000/oras@sha256:c9e54542075ad502900d11b9b5d5bdb4b974ad580842515684d3fbb4849e2bb1
{
  "schemaVersion": 2,
  "mediaType": "application/vnd.oci.image.manifest.v1+json",
  "artifactType": "application/vnd.oci.image.config.v1+json",
  "config": {
    "mediaType": "application/vnd.unknown.config.v1+json",
    "digest": "sha256:e9302bbb2fb8f6c2df866d3c4e41917849442f89a575f36f43366a7279804f70",
    "size": 38
  },
  "layers": [
    {
      "mediaType": "application/x-elf",
      "digest": "sha256:69c16b8386b7949fe37ff2356296b6331c1e6d5fbbc3e616192cc10ece55ea8d",
      "size": 11673840,
      "annotations": {
        "org.opencontainers.image.title": "bin/darwin/amd64/oras"
      }
    }
  ],
  "annotations": {
    "org.opencontainers.image.created": "2024-09-16T16:54:48Z"
  }
}
% oras manifest fetch-config --pretty localhost:15000/oras@sha256:c9e54542075ad502900d11b9b5d5bdb4b974ad580842515684d3fbb4849e2bb1
{
  "architecture": "amd64",
  "os": "darwin"
}

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Closes #1066
Partial #1053

Please check the following list:

  • Does the affected code have corresponding tests, e.g. unit test, E2E test?
  • Does this change require a documentation update?
  • Does this introduce breaking changes that would require an announcement or bumping the major version?
  • Do all new files have an appropriate license header?

Copy link

codecov bot commented Sep 16, 2024

Codecov Report

Attention: Patch coverage is 62.96296% with 10 lines in your changes missing coverage. Please review.

Project coverage is 85.87%. Comparing base (1d60e22) to head (4b2321a).

Files with missing lines Patch % Lines
cmd/oras/root/push.go 54.54% 7 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1500      +/-   ##
==========================================
- Coverage   85.97%   85.87%   -0.10%     
==========================================
  Files         118      118              
  Lines        4228     4255      +27     
==========================================
+ Hits         3635     3654      +19     
- Misses        354      359       +5     
- Partials      239      242       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@TerryHowe TerryHowe force-pushed the feature-push-platform branch 4 times, most recently from 641cbba to 7e915b1 Compare September 17, 2024 13:56
cmd/oras/root/push.go Outdated Show resolved Hide resolved
cmd/oras/root/push.go Outdated Show resolved Hide resolved
cmd/oras/root/push.go Outdated Show resolved Hide resolved
@shizhMSFT shizhMSFT changed the title feature: add platform option to push command feat: add platform option to push command Sep 18, 2024
Comment on lines 202 to 208
desc := ocispec.Descriptor{
MediaType: oras.MediaTypeUnknownConfig,
Digest: digest.FromBytes(blob),
Size: int64(len(blob)),
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: This part can be replaced by func NewDescriptorFromBytes(mediaType string, content []byte) ocispec.Descriptor of oras-go. Reference: NewDescriptorFromBytes

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

cmd/oras/root/push.go Outdated Show resolved Hide resolved
cmd/oras/root/push.go Outdated Show resolved Hide resolved
Comment on lines 146 to 151
if opts.Platform.Platform != nil && opts.artifactType != "" {
return errors.New("--artifact-type and --platform cannot both be provided for 1.0 OCI image")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

They can be used together, can't they?

Copy link
Member

Choose a reason for hiding this comment

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

Indeed they can be used together. We can populate the artifactType as mediaType into the config descriptor.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

return err
}
desc := ocispec.Descriptor{
MediaType: oras.MediaTypeUnknownConfig,
Copy link
Contributor

Choose a reason for hiding this comment

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

This value depends on the image-spec version.

Copy link
Member

Choose a reason for hiding this comment

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

If the image-spec version is v1.0. The media type can also be the value of --artifact-type.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@TerryHowe TerryHowe force-pushed the feature-push-platform branch 6 times, most recently from 3038b7b to fafd301 Compare September 23, 2024 14:28
Copy link
Member

@Wwwsylvia Wwwsylvia left a comment

Choose a reason for hiding this comment

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

LGTM with nit, but I am not a maintainer.

Comment on lines 203 to 204
if opts.Flag == option.ImageSpecV1_0 {
if opts.artifactType != "" {
Copy link
Member

Choose a reason for hiding this comment

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

nit: how about

Suggested change
if opts.Flag == option.ImageSpecV1_0 {
if opts.artifactType != "" {
if opts.Flag == option.ImageSpecV1_0 && opts.artifactType != "" {

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

@sabre1041 sabre1041 left a comment

Choose a reason for hiding this comment

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

LGTM

cmd/oras/root/push.go Outdated Show resolved Hide resolved
cmd/oras/root/push.go Outdated Show resolved Hide resolved
cmd/oras/internal/option/platform.go Outdated Show resolved Hide resolved
@TerryHowe TerryHowe force-pushed the feature-push-platform branch 2 times, most recently from 8d4062e to 35fe5b7 Compare September 30, 2024 16:19
cmd/oras/root/push.go Outdated Show resolved Hide resolved
cmd/oras/root/push.go Outdated Show resolved Hide resolved
cmd/oras/root/push.go Outdated Show resolved Hide resolved
@TerryHowe TerryHowe force-pushed the feature-push-platform branch 4 times, most recently from 76c1ad3 to 45456d0 Compare October 15, 2024 14:35
cmd/oras/root/push.go Outdated Show resolved Hide resolved
Copy link
Contributor

@qweeah qweeah left a comment

Choose a reason for hiding this comment

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

LGTM with minor suggestion

@TerryHowe TerryHowe force-pushed the feature-push-platform branch 2 times, most recently from 956c7e3 to 1334a8d Compare October 15, 2024 16:34
@qweeah
Copy link
Contributor

qweeah commented Oct 16, 2024

Sorry merging 55cf426 is not intended, I was playing with the PR locally and the upstream is accidentally set to this PR.

@TerryHowe
Copy link
Member Author

Sorry merging 55cf426 is not intended, I was playing with the PR locally and the upstream is accidentally set to this PR.

reverted

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.

support --platform in oras push and oras attach
6 participants