From 205efe3f40d58812f5afa5329359f299ab2b3325 Mon Sep 17 00:00:00 2001 From: Evan Cordell Date: Mon, 14 Oct 2019 12:22:05 -0400 Subject: [PATCH] Allow overriding the manifestdescriptor when pushing (#133) --- pkg/oras/push.go | 4 ++++ pkg/oras/push_opts.go | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/pkg/oras/push.go b/pkg/oras/push.go index 012fde648..be773bedf 100644 --- a/pkg/oras/push.go +++ b/pkg/oras/push.go @@ -83,6 +83,10 @@ func pack(provider content.Provider, descriptors []ocispec.Descriptor, opts *pus } // Manifest + if opts.manifest != nil { + return *opts.manifest, store, nil + } + manifest := ocispec.Manifest{ Versioned: specs.Versioned{ SchemaVersion: 2, // historical value. does not pertain to OCI or docker version diff --git a/pkg/oras/push_opts.go b/pkg/oras/push_opts.go index c8aa7a8e9..090620540 100644 --- a/pkg/oras/push_opts.go +++ b/pkg/oras/push_opts.go @@ -15,6 +15,7 @@ type pushOpts struct { config *ocispec.Descriptor configMediaType string configAnnotations map[string]string + manifest *ocispec.Descriptor manifestAnnotations map[string]string validateName func(desc ocispec.Descriptor) error baseHandlers []images.Handler @@ -29,7 +30,7 @@ func pushOptsDefaults() *pushOpts { // PushOpt allows callers to set options on the oras push type PushOpt func(o *pushOpts) error -// WithConfig overrides the config +// WithConfig overrides the config - setting this will ignore WithConfigMediaType and WithConfigAnnotations func WithConfig(config ocispec.Descriptor) PushOpt { return func(o *pushOpts) error { o.config = &config @@ -53,6 +54,14 @@ func WithConfigAnnotations(annotations map[string]string) PushOpt { } } +// WithManifest overrides the manifest - setting this will ignore WithManifestConfigAnnotations +func WithManifest(manifest ocispec.Descriptor) PushOpt { + return func(o *pushOpts) error { + o.manifest = &manifest + return nil + } +} + // WithManifestAnnotations overrides the manifest annotations func WithManifestAnnotations(annotations map[string]string) PushOpt { return func(o *pushOpts) error {