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

Merged
merged 1 commit into from
Oct 17, 2024

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

Project coverage is 85.95%. Comparing base (1d60e22) to head (0a9eb54).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
cmd/oras/root/push.go 77.77% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1500      +/-   ##
==========================================
- Coverage   85.97%   85.95%   -0.02%     
==========================================
  Files         118      118              
  Lines        4228     4251      +23     
==========================================
+ Hits         3635     3654      +19     
- Misses        354      356       +2     
- Partials      239      241       +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
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
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
cmd/oras/root/push.go Outdated Show resolved Hide resolved
@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.

cmd/oras/root/push.go Outdated Show resolved Hide resolved
@TerryHowe TerryHowe force-pushed the feature-push-platform branch from fafd301 to a8a6a36 Compare September 25, 2024 14:38
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
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 TerryHowe force-pushed the feature-push-platform branch from 55cf426 to 1334a8d Compare October 16, 2024 00:47
@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

@TerryHowe TerryHowe force-pushed the feature-push-platform branch 5 times, most recently from 0788180 to 657c32b Compare October 16, 2024 14:22
Copy link
Contributor

@shizhMSFT shizhMSFT left a comment

Choose a reason for hiding this comment

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

In fact, I have a more fundamental question: How do I specify both artifactType and config.mediaType? It seems not possible for image-spec 1.1 in the current PR.

We need the ability to set config.mediaType to application/vnd.oci.image.config.v1+json when --artifact-platform is set in order to support OCI volumes. /cc @FeynmanZhou

cmd/oras/internal/option/platform.go Show resolved Hide resolved
cmd/oras/root/push.go Outdated Show resolved Hide resolved
@TerryHowe
Copy link
Member Author

In fact, I have a more fundamental question: How do I specify both artifactType and config.mediaType? It seems not possible for image-spec 1.1 in the current PR.

This is out of the scope for this PR and I don't think that was possible before this PR.

@shizhMSFT
Copy link
Contributor

This is out of the scope for this PR and I don't think that was possible before this PR.

Can you mark the flag --artifact-platform as [Experimental] or [Preview] so that we can complete it in next few iterations / PRs?

@TerryHowe TerryHowe force-pushed the feature-push-platform branch from 657c32b to 0a9eb54 Compare October 16, 2024 17:08
Copy link
Contributor

@shizhMSFT shizhMSFT left a comment

Choose a reason for hiding this comment

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

LGTM

@qweeah
Copy link
Contributor

qweeah commented Oct 17, 2024

In fact, I have a more fundamental question: How do I specify both artifactType and config.mediaType? It seems not possible for image-spec 1.1 in the current PR.

Through oras push --artifact-type $ARTIFACT_TYPE --config $CONFIG_PATH:$CONFIG_TYPE. It's by design --artifact-platform cannot be used to customize any media type.

@qweeah
Copy link
Contributor

qweeah commented Oct 17, 2024

We need the ability to set config.mediaType to application/vnd.oci.image.config.v1+json when --artifact-platform is set in order to support OCI volumes. /cc @FeynmanZhou

In that case --image-spec v1.0 --artifact-type application/vnd.oci.image.config.v1+json --artifact-platform xxx/xxx

@shizhMSFT
Copy link
Contributor

We need the ability to set config.mediaType to application/vnd.oci.image.config.v1+json when --artifact-platform is set in order to support OCI volumes. /cc @FeynmanZhou

In that case --image-spec v1.0 --artifact-type application/vnd.oci.image.config.v1+json --artifact-platform xxx/xxx

This workaround should work.

@TerryHowe TerryHowe merged commit 0fd725a into oras-project:main Oct 17, 2024
8 checks passed
@qweeah
Copy link
Contributor

qweeah commented Oct 22, 2024

We need the ability to set config.mediaType to application/vnd.oci.image.config.v1+json when --artifact-platform is set in order to support OCI volumes. /cc @FeynmanZhou

In that case --image-spec v1.0 --artifact-type application/vnd.oci.image.config.v1+json --artifact-platform xxx/xxx

This workaround should work.

It just came to me that if application/vnd.oci.image.config.v1 is a critical scenario that oras push --artifact-platform need to support for v1.0 image, why not making it default?

This default media type switch will only happen when --artifact-platform being used and thus is not breaking.

@TerryHowe
Copy link
Member Author

This default media type switch will only happen when --artifact-platform being used and thus is not breaking.

I'm not 100% following here, maybe create an issue if you think there is something. If --artifact-platform is used, it creates a 1.1 image right now. Without specifying the image version, it creates a 1.0 imager

@qweeah
Copy link
Contributor

qweeah commented Oct 23, 2024

@TerryHowe What I am thinking is to use application/vnd.oci.image.config.v1 instead of application/vnd.unknown.config.v1+json as default config media type.

Actually, it requires oras to extra work on baking the config blob to meet below spec: https://github.com/opencontainers/image-spec/blob/da92727e9c8761ec087890466b8756b755aefd37/manifest.md#L68-73

   When the `config.mediaType` is set to `application/vnd.oci.image.config.v1+json`, the following additional restrictions apply:

  - The array MUST have the base layer at index 0.
  - Subsequent layers MUST then follow in stack order (i.e. from `layers[0]` to `layers[len(layers)-1]`).
  - The final filesystem layout MUST match the result of [applying](layer.md#applying-changesets) the layers to an empty directory.
  - The [ownership, mode, and other attributes](layer.md#file-attributes) of the initial empty directory are unspecified

This work goes below the scope of oras so what I am thinking is not doable for now.

@Wwwsylvia
Copy link
Member

Just realized that the config media type has to be application/vnd.oci.image.config.v1, otherwise the end-to-end workflow won't work. See #1517 for details.

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