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: export manifest descriptor by push #524

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
14 changes: 14 additions & 0 deletions cmd/oras/internal/option/packer.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ var (
// Packer option struct.
type Packer struct {
ManifestExportPath string
ManifestDescExportPath string
PathValidationDisabled bool
AnnotationFilePath string
ManifestAnnotations []string
Expand All @@ -53,6 +54,7 @@ type Packer struct {
// ApplyFlags applies flags to a command flag set.
func (opts *Packer) ApplyFlags(fs *pflag.FlagSet) {
fs.StringVarP(&opts.ManifestExportPath, "export-manifest", "", "", "export the pushed manifest")
fs.StringVarP(&opts.ManifestDescExportPath, "export-manifest-descriptor", "", "", "export the descriptor of pushed manifest")
fs.StringArrayVarP(&opts.ManifestAnnotations, "annotation", "a", nil, "manifest annotations")
fs.StringVarP(&opts.AnnotationFilePath, "annotation-file", "", "", "path of the annotation file")
fs.BoolVarP(&opts.PathValidationDisabled, "disable-path-validation", "", false, "skip path validation")
Expand All @@ -70,6 +72,18 @@ func (opts *Packer) ExportManifest(ctx context.Context, fetcher content.Fetcher,
return os.WriteFile(opts.ManifestExportPath, manifestBytes, 0666)
}

// ExportManifestDesc saves the descriptor of pushed manifest to a local file.
func (opts *Packer) ExportManifestDesc(desc ocispec.Descriptor) error {
if opts.ManifestDescExportPath == "" {
return nil
}
manifestDescBytes, err := json.Marshal(desc)
if err != nil {
return err
}
return os.WriteFile(opts.ManifestDescExportPath, manifestDescBytes, 0666)
}

// LoadManifestAnnotations loads the manifest annotation map.
func (opts *Packer) LoadManifestAnnotations() (annotations map[string]map[string]string, err error) {
if opts.AnnotationFilePath != "" && len(opts.ManifestAnnotations) != 0 {
Expand Down
4 changes: 4 additions & 0 deletions cmd/oras/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ func runPush(opts pushOptions) error {
fmt.Println("Pushed", opts.targetRef)
fmt.Println("Digest:", desc.Digest)

// Export manifest descriptor
if err := opts.ExportManifestDesc(desc); err != nil {
return err
}
// Export manifest
return opts.ExportManifest(ctx, store, desc)
Copy link
Contributor

Choose a reason for hiding this comment

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

Will both manifest content and descriptor be printed out both --export-manifest-descriptor and --export-manifest are specified?

}
Expand Down