mirror of
https://github.com/containers/buildah.git
synced 2025-07-31 15:24:26 +03:00
build-using-dockerfile: add --annotation
Add an --annotation flag to "buildah build-using-dockerfile". Refactor the logic for --label handling to use SetLabel() to set them in the image configuration in Executor.Commit(), instead of passing them as a field in CommitOptions for Builder.Commit() and expecting it to do so. Signed-off-by: Nalin Dahyabhai <nalin@redhat.com> Closes: #716 Approved by: rhatdan
This commit is contained in:
committed by
Atomic Bot
parent
c806e6e065
commit
71f0f9d063
@ -185,6 +185,7 @@ func budCmd(c *cli.Context) error {
|
|||||||
IIDFile: c.String("iidfile"),
|
IIDFile: c.String("iidfile"),
|
||||||
Squash: c.Bool("squash"),
|
Squash: c.Bool("squash"),
|
||||||
Labels: c.StringSlice("label"),
|
Labels: c.StringSlice("label"),
|
||||||
|
Annotations: c.StringSlice("annotation"),
|
||||||
}
|
}
|
||||||
|
|
||||||
if !c.Bool("quiet") {
|
if !c.Bool("quiet") {
|
||||||
|
12
commit.go
12
commit.go
@ -5,7 +5,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
cp "github.com/containers/image/copy"
|
cp "github.com/containers/image/copy"
|
||||||
@ -53,8 +52,6 @@ type CommitOptions struct {
|
|||||||
// Squash tells the builder to produce an image with a single layer
|
// Squash tells the builder to produce an image with a single layer
|
||||||
// instead of with possibly more than one layer.
|
// instead of with possibly more than one layer.
|
||||||
Squash bool
|
Squash bool
|
||||||
// Labels metadata for an image
|
|
||||||
Labels []string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// PushOptions can be used to alter how an image is copied somewhere.
|
// PushOptions can be used to alter how an image is copied somewhere.
|
||||||
@ -89,15 +86,6 @@ type PushOptions struct {
|
|||||||
func (b *Builder) Commit(ctx context.Context, dest types.ImageReference, options CommitOptions) (string, error) {
|
func (b *Builder) Commit(ctx context.Context, dest types.ImageReference, options CommitOptions) (string, error) {
|
||||||
var imgID string
|
var imgID string
|
||||||
|
|
||||||
for _, labelSpec := range options.Labels {
|
|
||||||
label := strings.SplitN(labelSpec, "=", 2)
|
|
||||||
if len(label) > 1 {
|
|
||||||
b.SetLabel(label[0], label[1])
|
|
||||||
} else {
|
|
||||||
b.SetLabel(label[0], "")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
systemContext := getSystemContext(options.SystemContext, options.SignaturePolicyPath)
|
systemContext := getSystemContext(options.SystemContext, options.SignaturePolicyPath)
|
||||||
policy, err := signature.DefaultPolicy(systemContext)
|
policy, err := signature.DefaultPolicy(systemContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -366,6 +366,7 @@ return 1
|
|||||||
|
|
||||||
local options_with_args="
|
local options_with_args="
|
||||||
--add-host
|
--add-host
|
||||||
|
--annotation
|
||||||
--authfile
|
--authfile
|
||||||
--build-arg
|
--build-arg
|
||||||
--cert-dir
|
--cert-dir
|
||||||
|
@ -26,6 +26,12 @@ Add a custom host-to-IP mapping (host:ip)
|
|||||||
|
|
||||||
Add a line to /etc/hosts. The format is hostname:ip. The **--add-host** option can be set multiple times.
|
Add a line to /etc/hosts. The format is hostname:ip. The **--add-host** option can be set multiple times.
|
||||||
|
|
||||||
|
**--annotation** *annotation*
|
||||||
|
|
||||||
|
Add an image *annotation* (e.g. annotation=*value*) to the image metadata. Can be used multiple times.
|
||||||
|
|
||||||
|
Note: this information is not present in Docker image formats, so it is discarded when writing images in Docker formats.
|
||||||
|
|
||||||
**--authfile** *path*
|
**--authfile** *path*
|
||||||
|
|
||||||
Path of the authentication file. Default is ${XDG\_RUNTIME\_DIR}/containers/auth.json, which is set using `podman login`.
|
Path of the authentication file. Default is ${XDG\_RUNTIME\_DIR}/containers/auth.json, which is set using `podman login`.
|
||||||
|
@ -118,6 +118,8 @@ type BuildOptions struct {
|
|||||||
Squash bool
|
Squash bool
|
||||||
// Labels metadata for an image
|
// Labels metadata for an image
|
||||||
Labels []string
|
Labels []string
|
||||||
|
// Annotation metadata for an image
|
||||||
|
Annotations []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Executor is a buildah-based implementation of the imagebuilder.Executor
|
// Executor is a buildah-based implementation of the imagebuilder.Executor
|
||||||
@ -157,6 +159,7 @@ type Executor struct {
|
|||||||
iidfile string
|
iidfile string
|
||||||
squash bool
|
squash bool
|
||||||
labels []string
|
labels []string
|
||||||
|
annotations []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// withName creates a new child executor that will be used whenever a COPY statement uses --from=NAME.
|
// withName creates a new child executor that will be used whenever a COPY statement uses --from=NAME.
|
||||||
@ -490,7 +493,8 @@ func NewExecutor(store storage.Store, options BuildOptions) (*Executor, error) {
|
|||||||
defaultMountsFilePath: options.DefaultMountsFilePath,
|
defaultMountsFilePath: options.DefaultMountsFilePath,
|
||||||
iidfile: options.IIDFile,
|
iidfile: options.IIDFile,
|
||||||
squash: options.Squash,
|
squash: options.Squash,
|
||||||
labels: options.Labels,
|
labels: append([]string{}, options.Labels...),
|
||||||
|
annotations: append([]string{}, options.Annotations...),
|
||||||
}
|
}
|
||||||
if exec.err == nil {
|
if exec.err == nil {
|
||||||
exec.err = os.Stderr
|
exec.err = os.Stderr
|
||||||
@ -682,6 +686,22 @@ func (b *Executor) Commit(ctx context.Context, ib *imagebuilder.Builder) (err er
|
|||||||
for k, v := range config.Labels {
|
for k, v := range config.Labels {
|
||||||
b.builder.SetLabel(k, v)
|
b.builder.SetLabel(k, v)
|
||||||
}
|
}
|
||||||
|
for _, labelSpec := range b.labels {
|
||||||
|
label := strings.SplitN(labelSpec, "=", 2)
|
||||||
|
if len(label) > 1 {
|
||||||
|
b.builder.SetLabel(label[0], label[1])
|
||||||
|
} else {
|
||||||
|
b.builder.SetLabel(label[0], "")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, annotationSpec := range b.annotations {
|
||||||
|
annotation := strings.SplitN(annotationSpec, "=", 2)
|
||||||
|
if len(annotation) > 1 {
|
||||||
|
b.builder.SetAnnotation(annotation[0], annotation[1])
|
||||||
|
} else {
|
||||||
|
b.builder.SetAnnotation(annotation[0], "")
|
||||||
|
}
|
||||||
|
}
|
||||||
if imageRef != nil {
|
if imageRef != nil {
|
||||||
logName := transports.ImageName(imageRef)
|
logName := transports.ImageName(imageRef)
|
||||||
logrus.Debugf("COMMIT %q", logName)
|
logrus.Debugf("COMMIT %q", logName)
|
||||||
@ -702,7 +722,6 @@ func (b *Executor) Commit(ctx context.Context, ib *imagebuilder.Builder) (err er
|
|||||||
PreferredManifestType: b.outputFormat,
|
PreferredManifestType: b.outputFormat,
|
||||||
IIDFile: b.iidfile,
|
IIDFile: b.iidfile,
|
||||||
Squash: b.squash,
|
Squash: b.squash,
|
||||||
Labels: b.labels,
|
|
||||||
}
|
}
|
||||||
imgID, err := b.builder.Commit(ctx, imageRef, options)
|
imgID, err := b.builder.Commit(ctx, imageRef, options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -11,6 +11,10 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
BudFlags = []cli.Flag{
|
BudFlags = []cli.Flag{
|
||||||
|
cli.StringSliceFlag{
|
||||||
|
Name: "annotation",
|
||||||
|
Usage: "Set metadata for an image (default [])",
|
||||||
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "authfile",
|
Name: "authfile",
|
||||||
Usage: "path of the authentication file. Default is ${XDG_RUNTIME_DIR}/containers/auth.json",
|
Usage: "path of the authentication file. Default is ${XDG_RUNTIME_DIR}/containers/auth.json",
|
||||||
|
@ -37,6 +37,16 @@ load helpers
|
|||||||
buildah rmi ${target}
|
buildah rmi ${target}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "bud-from-scratch-annotation" {
|
||||||
|
target=scratch-image
|
||||||
|
buildah bud --annotation "test=annotation" --signature-policy ${TESTSDIR}/policy.json -t ${target} ${TESTSDIR}/bud/from-scratch
|
||||||
|
run buildah --debug=false inspect --format '{{printf "%q" .ImageAnnotations}}' ${target}
|
||||||
|
echo "$output"
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[ "$output" = 'map["test":"annotation"]' ]
|
||||||
|
buildah rmi ${target}
|
||||||
|
}
|
||||||
|
|
||||||
@test "bud-from-multiple-files-one-from" {
|
@test "bud-from-multiple-files-one-from" {
|
||||||
target=scratch-image
|
target=scratch-image
|
||||||
buildah bud --signature-policy ${TESTSDIR}/policy.json -t ${target} -f ${TESTSDIR}/bud/from-multiple-files/Dockerfile1.scratch -f ${TESTSDIR}/bud/from-multiple-files/Dockerfile2.nofrom
|
buildah bud --signature-policy ${TESTSDIR}/policy.json -t ${target} -f ${TESTSDIR}/bud/from-multiple-files/Dockerfile1.scratch -f ${TESTSDIR}/bud/from-multiple-files/Dockerfile2.nofrom
|
||||||
|
Reference in New Issue
Block a user