mirror of
https://github.com/containers/buildah.git
synced 2025-07-31 15:24:26 +03:00
imagebuildah: add AdditionalTags
Add an AdditionalTags field to the imagebuildah options structure, to provide for additional tags which we'll want to apply to the image that we're writing. Signed-off-by: Nalin Dahyabhai <nalin@redhat.com> Closes: #88 Approved by: rhatdan
This commit is contained in:
committed by
Atomic Bot
parent
e06a697040
commit
4d155b93b4
43
commit.go
43
commit.go
@ -1,8 +1,12 @@
|
||||
package buildah
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/containers/image/copy"
|
||||
"github.com/containers/image/docker/reference"
|
||||
"github.com/containers/image/signature"
|
||||
"github.com/containers/image/storage"
|
||||
"github.com/containers/image/types"
|
||||
"github.com/containers/storage/pkg/archive"
|
||||
)
|
||||
@ -19,10 +23,32 @@ type CommitOptions struct {
|
||||
// specified, indicating that the shared, system-wide default policy
|
||||
// should be used.
|
||||
SignaturePolicyPath string
|
||||
// AdditionalTags is a list of additional names to add to the image, if
|
||||
// the transport to which we're writing the image gives us a way to add
|
||||
// them.
|
||||
AdditionalTags []string
|
||||
}
|
||||
|
||||
func expandTags(tags []string) ([]string, error) {
|
||||
expanded := []string{}
|
||||
for _, tag := range tags {
|
||||
name, err := reference.ParseNormalizedNamed(tag)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error parsing tag %q: %v", tag, err)
|
||||
}
|
||||
name = reference.TagNameOnly(name)
|
||||
tag = ""
|
||||
if tagged, ok := name.(reference.NamedTagged); ok {
|
||||
tag = ":" + tagged.Tag()
|
||||
}
|
||||
expanded = append(expanded, name.Name()+tag)
|
||||
}
|
||||
return expanded, nil
|
||||
}
|
||||
|
||||
// Commit writes the contents of the container, along with its updated
|
||||
// configuration, to a new image in the specified location.
|
||||
// configuration, to a new image in the specified location, and if we know how,
|
||||
// add any additional tags that were specified.
|
||||
func (b *Builder) Commit(dest types.ImageReference, options CommitOptions) error {
|
||||
policy, err := signature.DefaultPolicy(getSystemContext(options.SignaturePolicyPath))
|
||||
if err != nil {
|
||||
@ -37,5 +63,20 @@ func (b *Builder) Commit(dest types.ImageReference, options CommitOptions) error
|
||||
return err
|
||||
}
|
||||
err = copy.Image(policyContext, dest, src, getCopyOptions())
|
||||
switch dest.Transport().Name() {
|
||||
case storage.Transport.Name():
|
||||
tags, err := expandTags(options.AdditionalTags)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
img, err := storage.Transport.GetStoreImage(b.store, dest)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = b.store.SetNames(img.ID, append(img.Names, tags...))
|
||||
if err != nil {
|
||||
return fmt.Errorf("error setting image names to %v: %v", append(img.Names, tags...), err)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
Reference in New Issue
Block a user