Merge pull request #3480 from dmcgowan/fix-export-named-manifest-opt

Fix bug in export named manifest option
This commit is contained in:
Michael Crosby 2019-08-02 10:30:50 -04:00 committed by GitHub
commit d3e539af79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -89,31 +89,29 @@ func WithImage(is images.Store, name string) ExportOpt {
} }
// WithManifest adds a manifest to the exported archive. // WithManifest adds a manifest to the exported archive.
// It is up to caller to put name annotation to on the manifest // When names are given they will be set on the manifest in the
// descriptor if needed. // exported archive, creating an index record for each name.
func WithManifest(manifest ocispec.Descriptor) ExportOpt { // When no names are provided, it is up to caller to put name annotation to
// on the manifest descriptor if needed.
func WithManifest(manifest ocispec.Descriptor, names ...string) ExportOpt {
return func(ctx context.Context, o *exportOptions) error { return func(ctx context.Context, o *exportOptions) error {
o.manifests = append(o.manifests, manifest) if len(names) == 0 {
return nil
}
}
// WithNamedManifest adds a manifest to the exported archive
// with the provided names.
func WithNamedManifest(manifest ocispec.Descriptor, names ...string) ExportOpt {
return func(ctx context.Context, o *exportOptions) error {
for _, name := range names {
manifest.Annotations = addNameAnnotation(name, manifest.Annotations)
o.manifests = append(o.manifests, manifest) o.manifests = append(o.manifests, manifest)
} }
for _, name := range names {
mc := manifest
mc.Annotations = addNameAnnotation(name, manifest.Annotations)
o.manifests = append(o.manifests, mc)
}
return nil return nil
} }
} }
func addNameAnnotation(name string, annotations map[string]string) map[string]string { func addNameAnnotation(name string, base map[string]string) map[string]string {
if annotations == nil { annotations := map[string]string{}
annotations = map[string]string{} for k, v := range base {
annotations[k] = v
} }
annotations[images.AnnotationImageName] = name annotations[images.AnnotationImageName] = name