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!: support OCI image fallback for oras push and oras attach #665

Merged
merged 4 commits into from
Nov 2, 2022

Conversation

qweeah
Copy link
Contributor

@qweeah qweeah commented Oct 26, 2022

Since oras-go will take care of fallback with tag schema if referrer API not supported, this PR provides OCI Image fallback when-and-only-when OCI artifact is not supported.

Resolves: #654

@qweeah qweeah marked this pull request as draft October 26, 2022 09:05
@codecov-commenter
Copy link

codecov-commenter commented Oct 31, 2022

Codecov Report

Merging #665 (bb0d8ba) into main (8c592f1) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main     #665   +/-   ##
=======================================
  Coverage   72.12%   72.12%           
=======================================
  Files          14       14           
  Lines         513      513           
=======================================
  Hits          370      370           
  Misses        114      114           
  Partials       29       29           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@qweeah qweeah marked this pull request as ready for review October 31, 2022 15:40
@qweeah qweeah force-pushed the oci-fallback branch 2 times, most recently from 9f673f7 to 83b48fd Compare November 1, 2022 02:29
@qweeah qweeah requested a review from Wwwsylvia November 1, 2022 11:58
Signed-off-by: Billy Zha <jinzha1@microsoft.com>
Signed-off-by: Billy Zha <jinzha1@microsoft.com>
Comment on lines 128 to 146
o.FindSuccessors = func(ctx context.Context, fetcher content.Fetcher, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
successors, err := findSuccessors(ctx, fetcher, desc)
if err != nil {
return nil, err
}
if !content.Equal(desc, root) {
return successors, nil
}

// skip subject to save one HEAD towards dst
j := len(successors) - 1
for i, s := range successors {
if content.Equal(s, subject) {
// swap subject to end and slice it off
successors[i] = successors[j]
return successors[:j], nil
}
}
return nil, fmt.Errorf("failed to find subject %v in the packed root %v", subject, root)
Copy link
Member

Choose a reason for hiding this comment

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

Can you help me to understand this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is to skip all successor but leaving packed config, refactored in the new code.

Signed-off-by: Billy Zha <jinzha1@microsoft.com>
Signed-off-by: Billy Zha <jinzha1@microsoft.com>
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

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

@shizhMSFT shizhMSFT merged commit ed9d584 into oras-project:main Nov 2, 2022
// As of November 2022, ECR is known to return UNSUPPORTED error when
// putting an OCI artifact manifest.
switch errCode.Code {
case errcode.ErrorCodeManifestInvalid, errcode.ErrorCodeUnsupported:
Copy link

Choose a reason for hiding this comment

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

Probably a non-issue, just curious how do we deal with the casing (upper-case/lower-case) here? (e.g., UNSUPPORTED vs Unsupported)

Error: PUT "https://080565210187.dkr.ecr.us-east-1.amazonaws.com/v2/utnubu/manifests/oras.unknown":
  unexpected status code 400: unsupported:
  Unsupported manifest type: "application/vnd.oci.artifact.manifest.v1+json"

vs

% git grep ErrorCodeUnsupported
registry/remote/errcode/errors.go:42:   ErrorCodeUnsupported         = "UNSUPPORTED"

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nima Can you help confirm if the fallback works for ECR? I notice that the in-body error message was not capitalized in ECR, shown as below:

unexpected status code 400: unsupported: Unsupported manifest type: "application/vnd.oci.artifact.manifest.v1+json"

You can make from source and run a oras attach based on ECR

return root, nil
}

func isArtifactUnsupported(err error) bool {
Copy link

Choose a reason for hiding this comment

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

Curious why we chose names that result in double-negatives? For example "is it not not-supported" vs "is it supported".

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 on IsArtifactSupported

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nima Nice catch! @shizhMSFT How about renaming it to NoFallbackToOciImage or something indicates that we should not retry with OCI Image?

The reason is both isArtifactUnsupported and isArtifactSupported is not accurate, we don't know if artifact is supported if the other HTTP error happens.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moving the disscusion to #672

TerryHowe pushed a commit to TerryHowe/oras that referenced this pull request Feb 2, 2023
…ras-project#665)

Since oras-go will take care of fallback with tag schema if referrer API
not supported, this PR provides OCI Image fallback when-and-only-when
OCI artifact is not supported.

Resolves: oras-project#654

Signed-off-by: Billy Zha <jinzha1@microsoft.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 OCI image fallback in oras attach and oras push
6 participants