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!: implement artifact manifest handler in the storage package #30

Merged
merged 6 commits into from
Nov 3, 2022
Merged

feat!: implement artifact manifest handler in the storage package #30

merged 6 commits into from
Nov 3, 2022

Conversation

wangxiaoxuan273
Copy link

@wangxiaoxuan273 wangxiaoxuan273 commented Oct 24, 2022

Implemented artifact manifest handler related changes for the storage package, unit tests included.

Part 3 of #21

Signed-off-by: wangxiaoxuan273 [email protected]

@wangxiaoxuan273 wangxiaoxuan273 changed the title feat!: implemented artifact handler in the storage package feat!: implement artifact handler in the storage package Oct 24, 2022
@wangxiaoxuan273 wangxiaoxuan273 changed the title feat!: implement artifact handler in the storage package feat!: implement artifact manifest handler in the storage package Oct 24, 2022
@oras-project oras-project deleted a comment from m5i-work Nov 1, 2022
Comment on lines 128 to 130
if versioned.MediaType == v1.MediaTypeArtifactManifest {
return ms.ociartifactHandler.Unmarshal(ctx, dgst, content)
}

Choose a reason for hiding this comment

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

This should go to case 0.

Copy link
Author

@wangxiaoxuan273 wangxiaoxuan273 Nov 2, 2022

Choose a reason for hiding this comment

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

Added mediaType check before the schema number check, according to our offline discussion.

Copy link

Choose a reason for hiding this comment

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

Should only check MediaType before switching and comment the spec link(https://github.com/opencontainers/image-spec/blob/v1.1.0-rc2/artifact.md) in the if block.

Comment on lines 80 to 88
err := descriptor.Digest.Validate()
if err != nil {
errs = append(errs, err, distribution.ErrManifestBlobUnknown{Digest: descriptor.Digest})
continue
}
exists, err := manifestService.Exists(ctx, descriptor.Digest)
if err != nil || !exists {
errs = append(errs, distribution.ErrManifestBlobUnknown{Digest: descriptor.Digest})
}

Choose a reason for hiding this comment

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

This part does not look right. Descriptor of Subject refers to manifest but descriptors of Blobs refers to blobs.

Copy link
Author

@wangxiaoxuan273 wangxiaoxuan273 Nov 2, 2022

Choose a reason for hiding this comment

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

Corrected this part with blobService.

Signed-off-by: wangxiaoxuan273 <[email protected]>
Signed-off-by: wangxiaoxuan273 <[email protected]>
@codecov-commenter
Copy link

Codecov Report

Merging #30 (1011695) into main (0fce2c9) will increase coverage by 0.03%.
The diff coverage is 63.26%.

@@            Coverage Diff             @@
##             main      #30      +/-   ##
==========================================
+ Coverage   57.17%   57.21%   +0.03%     
==========================================
  Files         106      107       +1     
  Lines       10892    10979      +87     
==========================================
+ Hits         6228     6282      +54     
- Misses       3972     3995      +23     
- Partials      692      702      +10     
Impacted Files Coverage Δ
registry/storage/ociartifactmanifesthandler.go 59.21% <59.21%> (ø)
registry/storage/manifeststore.go 76.08% <70.58%> (-0.66%) ⬇️
registry/storage/registry.go 88.94% <100.00%> (+0.26%) ⬆️

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

@@ -94,19 +96,25 @@ func (ms *manifestStore) Get(ctx context.Context, dgst digest.Digest, options ..
return nil, err
}

switch versioned.MediaType {

Choose a reason for hiding this comment

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

To maintain the behavior of all previous implementation. I suggest

switch versioned.MediaType {
	case v1.MediaTypeArtifactManifest:
		return ms.ociartifactHandler.Unmarshal(ctx, dgst, content)
}

switch versioned.SchemaVersion {
// ... all code below should not be modified.

If we do want to improve, it should be done in a separated PR after upstream merge.

Copy link
Author

Choose a reason for hiding this comment

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

changed accordingly.

Comment on lines 108 to 122
// TODO: we should be able to handle the case in which 'descriptor' only has Digest and no MediaType
// currently, if Digest is a manifest digest and MediaType is "", there will be an error.
switch descriptor.MediaType {
case v1.MediaTypeArtifactManifest, v1.MediaTypeImageManifest, v1.MediaTypeImageIndex,
schema1.MediaTypeManifest, schema2.MediaTypeManifest, manifestlist.MediaTypeManifestList:
exists, err := manifestService.Exists(ctx, descriptor.Digest)
if err != nil || !exists {
errs = append(errs, distribution.ErrManifestBlobUnknown{Digest: descriptor.Digest})
}
default:
_, err = blobsService.Stat(ctx, descriptor.Digest)
if err != nil {
errs = append(errs, distribution.ErrManifestBlobUnknown{Digest: descriptor.Digest})
}
}

Choose a reason for hiding this comment

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

Media Type is a MUST field. Meanwhile, all descriptors in the blobs field are blobs. Even if they are manifests, they are still considered as blobs.

Copy link
Author

Choose a reason for hiding this comment

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

Changed the unit test accordingly.

Signed-off-by: wangxiaoxuan273 <[email protected]>
Signed-off-by: wangxiaoxuan273 <[email protected]>
Copy link

@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

@shizhMSFT shizhMSFT merged commit d03813c into oras-project:main Nov 3, 2022
@wangxiaoxuan273 wangxiaoxuan273 deleted the storage-implementation branch November 3, 2022 08:54
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.

5 participants