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

fix: only fallback to OCI image when current media type is OCI artifact #673

Merged
merged 6 commits into from
Nov 4, 2022
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions cmd/oras/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func pushArtifact(dst *remote.Repository, pack packFunc, packOpts *oras.PackOpti
return root, nil
}

if !copyRootAttempted || !isArtifactUnsupported(err) {
if !copyRootAttempted || skipFallbackToImageManifest(root, err) {
return ocispec.Descriptor{}, err
}

Expand Down Expand Up @@ -276,22 +276,25 @@ func pushArtifact(dst *remote.Repository, pack packFunc, packOpts *oras.PackOpti
return root, nil
}

func isArtifactUnsupported(err error) bool {
func skipFallbackToImageManifest(root ocispec.Descriptor, err error) bool {
qweeah marked this conversation as resolved.
Show resolved Hide resolved
if root.MediaType != ocispec.MediaTypeArtifactManifest {
return true
}
shizhMSFT marked this conversation as resolved.
Show resolved Hide resolved
var errResp *errcode.ErrorResponse
if !errors.As(err, &errResp) || errResp.StatusCode != http.StatusBadRequest {
return false
return true
}

var errCode errcode.Error
if !errors.As(errResp, &errCode) {
return false
return true
}

// 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:
return true
return false
}
return false
return true
}