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: push an ORAS artifact manifest when no blob is specified #486

Closed
wants to merge 3 commits into from
Closed
Changes from 2 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
43 changes: 28 additions & 15 deletions cmd/oras/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ Example - Push file to the insecure registry:

Example - Push file to the HTTP registry:
oras push localhost:5000/hello:latest hi.txt --plain-http

Example - Push oras artifact manifest type with no file:
yuehaoliang marked this conversation as resolved.
Show resolved Hide resolved
oras push localhost:5000/hello:latest --artifact-type empty/example
`,
Args: cobra.MinimumNArgs(1),
PreRunE: func(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -136,33 +139,43 @@ func runPush(opts pushOptions) error {
return opts.ExportManifest(ctx, store, desc)
}

func packManifest(ctx context.Context, store *file.Store, annotations map[string]map[string]string, opts *pushOptions) (ocispec.Descriptor, error) {
func packManifest(ctx context.Context, store *file.Store, annotations map[string]map[string]string, opts *pushOptions) (manifestDesc ocispec.Descriptor, err error) {
var packOpts oras.PackOptions
packOpts.ConfigAnnotations = annotations[annotationConfig]
packOpts.ManifestAnnotations = annotations[annotationManifest]

if opts.artifactType != "" {
packOpts.ConfigMediaType = opts.artifactType
}
if opts.manifestConfigRef != "" {
path, mediatype := parseFileReference(opts.manifestConfigRef, oras.MediaTypeUnknownConfig)
desc, err := store.Add(ctx, annotationConfig, mediatype, path)
if len(opts.FileRefs) != 0 {
// pack OCI artifact
if opts.artifactType != "" {
packOpts.ConfigMediaType = opts.artifactType
}
if opts.manifestConfigRef != "" {
path, mediatype := parseFileReference(opts.manifestConfigRef, oras.MediaTypeUnknownConfig)
desc, err := store.Add(ctx, annotationConfig, mediatype, path)
if err != nil {
return ocispec.Descriptor{}, err
}
desc.Annotations = packOpts.ConfigAnnotations
packOpts.ConfigDescriptor = &desc
}
var descs []ocispec.Descriptor
descs, err = loadFiles(ctx, store, annotations, opts.FileRefs, opts.Verbose)
if err != nil {
return ocispec.Descriptor{}, err
}
desc.Annotations = packOpts.ConfigAnnotations
packOpts.ConfigDescriptor = &desc
}
descs, err := loadFiles(ctx, store, annotations, opts.FileRefs, opts.Verbose)
if err != nil {
return ocispec.Descriptor{}, err
manifestDesc, err = oras.Pack(ctx, store, descs, packOpts)
} else {
// pack ORAS artifact
if opts.artifactType == "" {
return ocispec.Descriptor{}, errors.New("artifact type required when no file specified")
}
yuehaoliang marked this conversation as resolved.
Show resolved Hide resolved
manifestDesc, err = oras.PackArtifact(ctx, store, opts.artifactType, nil, oras.PackArtifactOptions{})
}
manifestDesc, err := oras.Pack(ctx, store, descs, packOpts)
if err != nil {
return ocispec.Descriptor{}, err
}
if err := store.Tag(ctx, manifestDesc, tagStaged); err != nil {
return ocispec.Descriptor{}, err
}
return manifestDesc, nil
return
}