Skip to content

Commit

Permalink
Allow overriding the manifestdescriptor when pushing
Browse files Browse the repository at this point in the history
  • Loading branch information
ecordell committed Oct 11, 2019
1 parent ea5c23a commit 2566435
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
39 changes: 22 additions & 17 deletions pkg/oras/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
9 changes: 9 additions & 0 deletions pkg/oras/push_opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 2566435

Please sign in to comment.