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: use --artifact-type to change the media type of the config blob #482

Merged
merged 3 commits into from
Aug 9, 2022
Merged
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
13 changes: 13 additions & 0 deletions cmd/oras/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package main

import (
"context"
"errors"
"fmt"

ocispec "github.com/opencontainers/image-spec/specs-go/v1"
Expand All @@ -40,6 +41,7 @@ type pushOptions struct {

targetRef string
manifestConfigRef string
artifactTpye string
}

func pushCmd() *cobra.Command {
Expand All @@ -58,6 +60,9 @@ Example - Push file "hi.txt" with the custom "application/vnd.me.hi" media type:
Example - Push multiple files with different media types:
oras push localhost:5000/hello:latest hi.txt:application/vnd.me.hi bye.txt:application/vnd.me.bye

Example - Push file "hi.txt" with "application/vnd.me.config" as config type:
oras push --artifact-type application/vnd.me.config localhost:5000/hello:latest hi.txt

Example - Push file "hi.txt" with the custom manifest config "config.json" of the custom "application/vnd.me.config" media type:
oras push --manifest-config config.json:application/vnd.me.config localhost:5000/hello:latest hi.txt

Expand All @@ -79,12 +84,17 @@ Example - Push file to the HTTP registry:
}

cmd.Flags().StringVarP(&opts.manifestConfigRef, "manifest-config", "", "", "manifest config file")
cmd.Flags().StringVarP(&opts.artifactTpye, "artifact-type", "", "", "media type of config or manifest")
yuehaoliang marked this conversation as resolved.
Show resolved Hide resolved

option.ApplyFlags(&opts, cmd.Flags())
return cmd
}

func runPush(opts pushOptions) error {
if opts.artifactTpye != "" && opts.manifestConfigRef != "" {
return errors.New("--artifact-type and --manifest-config cannot be both provided")
}

ctx, _ := opts.SetLoggerLevel()
annotations, err := opts.LoadManifestAnnotations()
if err != nil {
Expand Down Expand Up @@ -132,6 +142,9 @@ func packManifest(ctx context.Context, store *file.Store, annotations map[string
packOpts.ConfigAnnotations = annotations[annotationConfig]
packOpts.ManifestAnnotations = annotations[annotationManifest]

if opts.artifactTpye != "" {
packOpts.ConfigMediaType = opts.artifactTpye
}
if opts.manifestConfigRef != "" {
path, mediatype := parseFileReference(opts.manifestConfigRef, oras.MediaTypeUnknownConfig)
desc, err := store.Add(ctx, annotationConfig, mediatype, path)
Expand Down