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 84.00000% with 4 lines in your changes missing coverage. Please review.

Project coverage is 86.08%. Comparing base (8dc05a7) to head (a8a6a36).

Files with missing lines Patch % Lines
cmd/oras/root/push.go 78.94% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1500      +/-   ##
==========================================
- Coverage   86.10%   86.08%   -0.02%     
==========================================
  Files         118      118              
  Lines        4224     4248      +24     
==========================================
+ Hits         3637     3657      +20     
- Misses        350      352       +2     
- Partials      237      239       +2     

☔ 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
@@ -97,6 +101,9 @@ Example - Push repository with manifest annotations:
Example - Push repository with manifest annotation file:
oras push --annotation-file annotation.json localhost:5000/hello:v1

Example - Push repository with platform:
oras push --platform linux/arm/v5 localhost:5000/hello:v1
Copy link
Contributor

Choose a reason for hiding this comment

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

CC @FeynmanZhou for the flag naming. attach already using it so better call the new one --config-platform

Copy link
Contributor

Choose a reason for hiding this comment

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

It is a good point that --platform means differently in oras push and oras attach. We need a better flag name.

Copy link
Contributor

Choose a reason for hiding this comment

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

--config-platform does not sound like a good name. Would it be better to name it --artifact-platform? That will be consistent with --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

Copy link
Member Author

Choose a reason for hiding this comment

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

This does mean pull will use --platform and push --artifact-platform though which does seem a bit inconsistent to me.

Copy link
Contributor

@qweeah qweeah Sep 29, 2024

Choose a reason for hiding this comment

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

It's hard to choose a good flag name.

Some historical view on this: --platform was firstly introduced to oras manifest fetch to select an image with specific platform from a multi-arch image. Then the same UX was applied to oras discover and oras attach for selecting a platform-specific subject artifact.

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 203
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

@@ -97,6 +101,9 @@ Example - Push repository with manifest annotations:
Example - Push repository with manifest annotation file:
oras push --annotation-file annotation.json localhost:5000/hello:v1

Example - Push repository with platform:
oras push --platform linux/arm/v5 localhost:5000/hello:v1
Copy link
Contributor

Choose a reason for hiding this comment

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

It is a good point that --platform means differently in oras push and oras attach. We need a better flag name.

@@ -97,6 +101,9 @@ Example - Push repository with manifest annotations:
Example - Push repository with manifest annotation file:
oras push --annotation-file annotation.json localhost:5000/hello:v1

Example - Push repository with platform:
oras push --platform linux/arm/v5 localhost:5000/hello:v1
Copy link
Contributor

Choose a reason for hiding this comment

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

--config-platform does not sound like a good name. Would it be better to name it --artifact-platform? That will be consistent with --artifact-type.

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

Comment on lines 165 to 168
configAndPlatform := []string{"config", "artifact-platform"}
if err := oerrors.CheckMutuallyExclusiveFlags(cmd.Flags(), configAndPlatform...); err != nil {
return err
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be done in PreRunE before option.Parse

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

@@ -116,7 +122,7 @@ Example - Push file "hi.txt" into an OCI image layout folder 'layout-dir' with t
return err
}

if opts.manifestConfigRef != "" && opts.artifactType == "" {
if (opts.manifestConfigRef != "" || opts.Platform.Platform != nil) && opts.artifactType == "" {
Copy link
Contributor

@qweeah qweeah Sep 29, 2024

Choose a reason for hiding this comment

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

This block handles oras push --config xxx ... without using --artifact-type xxx:

  • For v1.1 artifacts, this usage invalid.
  • Otherwise give best-effort try to pack v1.0 artifacts.

Since --artifact-platform cannot be used with --config, there is no need to change this code block.

Copy link
Contributor

Choose a reason for hiding this comment

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

Only need to make sure: --artifact-platform is not used for v1.0 artifact in the below opts.PackVersion switching block.

Copy link
Member Author

Choose a reason for hiding this comment

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

Made the change I think you requested. I do need to think about this some more though.

cmd/oras/internal/option/platform.go Outdated Show resolved Hide resolved
Signed-off-by: Terry Howe <terrylhowe@gmail.com>
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