diff --git a/cmd/oras/push.go b/cmd/oras/push.go index 2eceea52a..f6e0820fc 100644 --- a/cmd/oras/push.go +++ b/cmd/oras/push.go @@ -17,6 +17,7 @@ package main import ( "context" + "errors" "fmt" ocispec "github.com/opencontainers/image-spec/specs-go/v1" @@ -40,6 +41,7 @@ type pushOptions struct { targetRef string manifestConfigRef string + artifactType string } func pushCmd() *cobra.Command { @@ -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 @@ -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 { @@ -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 @@ -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)