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 manifest fetch-config #540

Merged
merged 14 commits into from
Sep 19, 2022

Conversation

yuehaoliang
Copy link
Contributor

Resolve #131

Signed-off-by: Haoliang Yue [email protected]

@codecov-commenter
Copy link

codecov-commenter commented Sep 7, 2022

Codecov Report

Merging #540 (eb49aba) into main (ba2385c) will increase coverage by 0.10%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #540      +/-   ##
==========================================
+ Coverage   72.44%   72.54%   +0.10%     
==========================================
  Files          13       14       +1     
  Lines         508      510       +2     
==========================================
+ Hits          368      370       +2     
  Misses        112      112              
  Partials       28       28              
Impacted Files Coverage Δ
internal/descriptor/descriptor.go 100.00% <100.00%> (ø)

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

@shizhMSFT shizhMSFT added this to the v0.15.0 milestone Sep 8, 2022
Signed-off-by: Haoliang Yue <[email protected]>
Signed-off-by: Haoliang Yue <[email protected]>
Signed-off-by: Haoliang Yue <[email protected]>
cmd/oras/internal/descriptor/descriptor.go Outdated Show resolved Hide resolved
cmd/oras/manifest/fetchConfig.go Outdated Show resolved Hide resolved
cmd/oras/manifest/fetchConfig.go Outdated Show resolved Hide resolved
}

cmd.Flags().StringVarP(&opts.outputPath, "output", "o", "", "output file path")
cmd.Flags().StringVarP(&opts.mediaType, "media-type", "", "", "media type of the manifest config")
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we remove this flag as it does not have a user scenario and it confuses users? /cc @FeynmanZhou @yizha1

Copy link
Contributor Author

@yuehaoliang yuehaoliang Sep 15, 2022

Choose a reason for hiding this comment

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

Can we remove this flag as it does not have a user scenario and it confuses users? /cc @FeynmanZhou @yizha1

I was tried to support the same feature as oras pull --config, but if users only use this command for an image manifest, --media-type is not required, because we can always recognize the config for an image manifest.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed --media-type for now. I think if only image manifest type support this manifest fetch-config command, this argument is unnecessary.

Comment on lines 158 to 176
func fetchConfigDesc(ctx context.Context, src oras.ReadOnlyTarget, reference string, configMediaType string) (ocispec.Descriptor, error) {
// fetch manifest descriptor
manifestDesc, err := oras.Resolve(ctx, src, reference, oras.ResolveOptions{})
if err != nil {
return ocispec.Descriptor{}, err
}

// fetch config descriptor
successors, err := content.Successors(ctx, src, manifestDesc)
if err != nil {
return ocispec.Descriptor{}, err
}
for i, s := range successors {
if s.MediaType == configMediaType || (configMediaType == "" && i == 0 && descriptor.IsImageManifest(manifestDesc.MediaType)) {
return s, nil
}
}
return ocispec.Descriptor{}, fmt.Errorf("%s does not have a config", reference)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we know it is an image manifest, we can call oras.FetchBytes() and then unmarshal it to extract the config descriptor. The simplified operation not only has less network calls but also cleaner.

Copy link
Contributor Author

@yuehaoliang yuehaoliang Sep 15, 2022

Choose a reason for hiding this comment

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

Since we know it is an image manifest, we can call oras.FetchBytes() and then unmarshal it to extract the config descriptor. The simplified operation not only has less network calls but also cleaner.

Are we sure that manifest fetch-config is only used for image manifest? I see in oras pull --config, users can provided the media type of the config file. If the manifest is not an image manifest, the command will fetch the blob who has a matched media type.

Copy link
Contributor

@shizhMSFT shizhMSFT Sep 15, 2022

Choose a reason for hiding this comment

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

Are we sure that manifest fetch-config is only used for image manifest?

Yes, manifest fetch-config should only run against image manifests.

Copy link
Contributor

Choose a reason for hiding this comment

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

oras manifest fetch-config should return error if the manifest is not an image manifest.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved as required.

cmd/oras/manifest/fetchConfig.go Outdated Show resolved Hide resolved
@qweeah
Copy link
Contributor

qweeah commented Sep 16, 2022

@yuehaoliang-microsoft Can we have a UX described in the #131 or https://hackmd.io/aLxws7mhSZukfFzx3PKq3w

@yuehaoliang
Copy link
Contributor Author

@yuehaoliang-microsoft Can we have a UX described in the #131 or https://hackmd.io/aLxws7mhSZukfFzx3PKq3w

I attached a few picture about UX in #131, and also updates the HackMD documentation.

cmd/oras/manifest/fetch_config.go Show resolved Hide resolved
cmd/oras/manifest/fetch_config.go Outdated Show resolved Hide resolved
cmd/oras/manifest/fetch_config.go Outdated Show resolved Hide resolved
cmd/oras/manifest/fetch_config.go Outdated Show resolved Hide resolved
internal/file/file.go Outdated Show resolved Hide resolved
cmd/oras/pull.go Outdated Show resolved Hide resolved
cmd/oras/manifest/fetch_config.go Outdated Show resolved Hide resolved

** This command is in preview and under development. **

Example - Fetch the config:
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a scenario missing:

oras manifest fetch-config --platform 'linux/arm/v5' localhost:5000/hello:latest

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Supported option.Platform.

Signed-off-by: Haoliang Yue <[email protected]>
// fetch manifest descriptor and content
fetchOpts := oras.DefaultFetchBytesOptions
fetchOpts.TargetPlatform = targetPlatform
manifestDesc, manifestContent, err := oras.FetchBytes(ctx, src, reference, oras.DefaultFetchBytesOptions)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
manifestDesc, manifestContent, err := oras.FetchBytes(ctx, src, reference, oras.DefaultFetchBytesOptions)
manifestDesc, manifestContent, err := oras.FetchBytes(ctx, src, reference, fetchOpts)

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

@shizhMSFT shizhMSFT merged commit 1075b3b into oras-project:main Sep 19, 2022
TerryHowe pushed a commit to TerryHowe/oras that referenced this pull request Feb 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

oras pull to support pulling the manifest.config object
5 participants