Skip to content

Commit

Permalink
feat: use --artifact-type to change the media type of the config blob (
Browse files Browse the repository at this point in the history
…#482)

Signed-off-by: Haoliang Yue <yuehaoliang@microsoft.com>
  • Loading branch information
yuehaoliang authored Aug 9, 2022
1 parent 96900e7 commit d776a22
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 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
artifactType 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 @@ -69,6 +74,9 @@ Example - Push file to the HTTP registry:
`,
Args: cobra.MinimumNArgs(1),
PreRunE: func(cmd *cobra.Command, args []string) error {
if opts.artifactType != "" && opts.manifestConfigRef != "" {
return errors.New("--artifact-type and --manifest-config cannot both be provided")
}
return opts.ReadPassword()
},
RunE: func(cmd *cobra.Command, args []string) error {
Expand All @@ -79,6 +87,7 @@ Example - Push file to the HTTP registry:
}

cmd.Flags().StringVarP(&opts.manifestConfigRef, "manifest-config", "", "", "manifest config file")
cmd.Flags().StringVarP(&opts.artifactType, "artifact-type", "", "", "media type of config or manifest")

option.ApplyFlags(&opts, cmd.Flags())
return cmd
Expand Down Expand Up @@ -132,6 +141,9 @@ func packManifest(ctx context.Context, store *file.Store, annotations map[string
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)
Expand Down

0 comments on commit d776a22

Please sign in to comment.