diff --git a/pkg/oras/push.go b/pkg/oras/push.go index 012fde648..d2c953305 100644 --- a/pkg/oras/push.go +++ b/pkg/oras/push.go @@ -83,24 +83,29 @@ func pack(provider content.Provider, descriptors []ocispec.Descriptor, opts *pus } // Manifest - manifest := ocispec.Manifest{ - Versioned: specs.Versioned{ - SchemaVersion: 2, // historical value. does not pertain to OCI or docker version - }, - Config: config, - Layers: descriptors, - Annotations: opts.manifestAnnotations, - } - manifestBytes, err := json.Marshal(manifest) - if err != nil { - return ocispec.Descriptor{}, nil, err - } - manifestDescriptor := ocispec.Descriptor{ - MediaType: ocispec.MediaTypeImageManifest, - Digest: digest.FromBytes(manifestBytes), - Size: int64(len(manifestBytes)), + var manifestDescriptor ocispec.Descriptor + if opts.manifest == nil { + manifest := ocispec.Manifest{ + Versioned: specs.Versioned{ + SchemaVersion: 2, // historical value. does not pertain to OCI or docker version + }, + Config: config, + Layers: descriptors, + Annotations: opts.manifestAnnotations, + } + manifestBytes, err := json.Marshal(manifest) + if err != nil { + return ocispec.Descriptor{}, nil, err + } + manifestDescriptor = ocispec.Descriptor{ + MediaType: ocispec.MediaTypeImageManifest, + Digest: digest.FromBytes(manifestBytes), + Size: int64(len(manifestBytes)), + } + store.Set(manifestDescriptor, manifestBytes) + } else { + manifestDescriptor = *opts.manifest } - store.Set(manifestDescriptor, manifestBytes) return manifestDescriptor, store, nil } diff --git a/pkg/oras/push_opts.go b/pkg/oras/push_opts.go index c8aa7a8e9..f97ae9090 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 @@ -53,6 +54,14 @@ func WithConfigAnnotations(annotations map[string]string) PushOpt { } } +// WithManifest overrides the manifest +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 {