mirror of
https://github.com/containers/buildah.git
synced 2025-07-30 04:23:09 +03:00
Add support for buildah bud --label
We want to be able to add labels when building a container image. Signed-off-by: Daniel J Walsh <dwalsh@redhat.com> Closes: #698 Approved by: umohnani8
This commit is contained in:
committed by
Atomic Bot
parent
2749191a5f
commit
02cc30ba17
@ -187,6 +187,7 @@ func budCmd(c *cli.Context) error {
|
|||||||
CommonBuildOpts: commonOpts,
|
CommonBuildOpts: commonOpts,
|
||||||
DefaultMountsFilePath: c.GlobalString("default-mounts-file"),
|
DefaultMountsFilePath: c.GlobalString("default-mounts-file"),
|
||||||
IIDFile: c.String("iidfile"),
|
IIDFile: c.String("iidfile"),
|
||||||
|
Labels: c.StringSlice("label"),
|
||||||
}
|
}
|
||||||
|
|
||||||
if !c.Bool("quiet") {
|
if !c.Bool("quiet") {
|
||||||
|
12
commit.go
12
commit.go
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
cp "github.com/containers/image/copy"
|
cp "github.com/containers/image/copy"
|
||||||
@ -49,6 +50,8 @@ type CommitOptions struct {
|
|||||||
SystemContext *types.SystemContext
|
SystemContext *types.SystemContext
|
||||||
// IIDFile tells the builder to write the image ID to the specified file
|
// IIDFile tells the builder to write the image ID to the specified file
|
||||||
IIDFile string
|
IIDFile string
|
||||||
|
// 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.
|
||||||
@ -83,6 +86,15 @@ 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 {
|
||||||
|
@ -378,6 +378,7 @@ return 1
|
|||||||
--file
|
--file
|
||||||
--format
|
--format
|
||||||
--iidfile
|
--iidfile
|
||||||
|
--label
|
||||||
-m
|
-m
|
||||||
--memory
|
--memory
|
||||||
--memory-swap
|
--memory-swap
|
||||||
|
@ -157,6 +157,10 @@ Buildah is not currently supported on Windows, and does not have a daemon.
|
|||||||
If you want to override the container isolation you can choose a different
|
If you want to override the container isolation you can choose a different
|
||||||
OCI Runtime, using the --runtime flag.
|
OCI Runtime, using the --runtime flag.
|
||||||
|
|
||||||
|
**--label** *label*
|
||||||
|
|
||||||
|
Add an image *label* (e.g. label=*value*) to the image metadata. Can be used multiple times.
|
||||||
|
|
||||||
**--memory, -m**=""
|
**--memory, -m**=""
|
||||||
|
|
||||||
Memory limit (format: <number>[<unit>], where unit = b, k, m or g)
|
Memory limit (format: <number>[<unit>], where unit = b, k, m or g)
|
||||||
|
@ -113,6 +113,8 @@ type BuildOptions struct {
|
|||||||
DefaultMountsFilePath string
|
DefaultMountsFilePath string
|
||||||
// IIDFile tells the builder to write the image ID to the specified file
|
// IIDFile tells the builder to write the image ID to the specified file
|
||||||
IIDFile string
|
IIDFile string
|
||||||
|
// Labels metadata for an image
|
||||||
|
Labels []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Executor is a buildah-based implementation of the imagebuilder.Executor
|
// Executor is a buildah-based implementation of the imagebuilder.Executor
|
||||||
@ -150,6 +152,7 @@ type Executor struct {
|
|||||||
commonBuildOptions *buildah.CommonBuildOptions
|
commonBuildOptions *buildah.CommonBuildOptions
|
||||||
defaultMountsFilePath string
|
defaultMountsFilePath string
|
||||||
iidfile string
|
iidfile string
|
||||||
|
labels []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.
|
||||||
@ -482,6 +485,7 @@ func NewExecutor(store storage.Store, options BuildOptions) (*Executor, error) {
|
|||||||
commonBuildOptions: options.CommonBuildOpts,
|
commonBuildOptions: options.CommonBuildOpts,
|
||||||
defaultMountsFilePath: options.DefaultMountsFilePath,
|
defaultMountsFilePath: options.DefaultMountsFilePath,
|
||||||
iidfile: options.IIDFile,
|
iidfile: options.IIDFile,
|
||||||
|
labels: options.Labels,
|
||||||
}
|
}
|
||||||
if exec.err == nil {
|
if exec.err == nil {
|
||||||
exec.err = os.Stderr
|
exec.err = os.Stderr
|
||||||
@ -692,6 +696,7 @@ func (b *Executor) Commit(ctx context.Context, ib *imagebuilder.Builder) (err er
|
|||||||
ReportWriter: b.reportWriter,
|
ReportWriter: b.reportWriter,
|
||||||
PreferredManifestType: b.outputFormat,
|
PreferredManifestType: b.outputFormat,
|
||||||
IIDFile: b.iidfile,
|
IIDFile: b.iidfile,
|
||||||
|
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 {
|
||||||
|
@ -53,6 +53,10 @@ var (
|
|||||||
Name: "iidfile",
|
Name: "iidfile",
|
||||||
Usage: "Write the image ID to the file",
|
Usage: "Write the image ID to the file",
|
||||||
},
|
},
|
||||||
|
cli.StringSliceFlag{
|
||||||
|
Name: "label",
|
||||||
|
Usage: "Set metadata for an image (default [])",
|
||||||
|
},
|
||||||
cli.BoolFlag{
|
cli.BoolFlag{
|
||||||
Name: "no-cache",
|
Name: "no-cache",
|
||||||
Usage: "Do not use caching for the container build. Buildah does not currently support caching so this is a NOOP.",
|
Usage: "Do not use caching for the container build. Buildah does not currently support caching so this is a NOOP.",
|
||||||
|
@ -25,6 +25,15 @@ load helpers
|
|||||||
[ "$output" = "" ]
|
[ "$output" = "" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "bud-from-scratch-label" {
|
||||||
|
target=scratch-image
|
||||||
|
buildah bud --label "test=label" --signature-policy ${TESTSDIR}/policy.json -t ${target} ${TESTSDIR}/bud/from-scratch
|
||||||
|
run buildah --debug=false inspect --format '{{printf "%q" .Docker.Config.Labels}}' ${target}
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[ "$output" = 'map["test":"label"]' ]
|
||||||
|
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