2017-02-11 00:48:15 +08:00
|
|
|
package buildah
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/containers/image/copy"
|
|
|
|
"github.com/containers/image/signature"
|
|
|
|
"github.com/containers/image/types"
|
|
|
|
"github.com/containers/storage/pkg/archive"
|
|
|
|
)
|
|
|
|
|
2017-02-11 03:45:06 +08:00
|
|
|
// CommitOptions can be used to alter how an image is committed.
|
2017-02-11 00:48:15 +08:00
|
|
|
type CommitOptions struct {
|
2017-02-11 03:45:06 +08:00
|
|
|
// Compression specifies the type of compression which is applied to
|
|
|
|
// layer blobs. The default is to not use compression, but
|
|
|
|
// archive.Gzip is recommended.
|
|
|
|
Compression archive.Compression
|
|
|
|
// SignaturePolicyPath specifies an override location for the signature
|
|
|
|
// policy which should be used for verifying the new image as it is
|
|
|
|
// being written. Except in specific circumstances, no value should be
|
|
|
|
// specified, indicating that the shared, system-wide default policy
|
|
|
|
// should be used.
|
2017-02-11 00:48:15 +08:00
|
|
|
SignaturePolicyPath string
|
|
|
|
}
|
|
|
|
|
2017-02-11 03:45:06 +08:00
|
|
|
// Commit writes the contents of the container, along with its updated
|
|
|
|
// configuration, to a new image in the specified location.
|
2017-02-11 00:48:15 +08:00
|
|
|
func (b *Builder) Commit(dest types.ImageReference, options CommitOptions) error {
|
|
|
|
policy, err := signature.DefaultPolicy(getSystemContext(options.SignaturePolicyPath))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
policyContext, err := signature.NewPolicyContext(policy)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
src, err := b.makeContainerImageRef(options.Compression)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = copy.Image(policyContext, dest, src, getCopyOptions())
|
|
|
|
return err
|
|
|
|
}
|