Skip to content

Commit 5009a39

Browse files
Merge pull request #5343 from TomSweeneyRedHat/dev/tsweeney/picker2
[release-1.34] Cherry Pick a number of commits from main
2 parents 21ec7ac + 83a1368 commit 5009a39

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+988
-324
lines changed

Makefile

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ APPARMORTAG := $(shell hack/apparmor_tag.sh)
44
STORAGETAGS := exclude_graphdriver_devicemapper $(shell ./btrfs_tag.sh) $(shell ./btrfs_installed_tag.sh) $(shell ./hack/libsubid_tag.sh)
55
SECURITYTAGS ?= seccomp $(APPARMORTAG)
66
TAGS ?= $(SECURITYTAGS) $(STORAGETAGS) $(shell ./hack/systemd_tag.sh)
7+
ifeq ($(shell uname -s),FreeBSD)
8+
# FreeBSD needs CNI until netavark is supported
9+
TAGS += cni
10+
endif
711
BUILDTAGS += $(TAGS)
812
PREFIX := /usr/local
913
BINDIR := $(PREFIX)/bin
@@ -123,7 +127,7 @@ gopath:
123127
test $(shell pwd) = $(shell cd ../../../../src/github.com/containers/buildah ; pwd)
124128

125129
codespell:
126-
codespell -S Makefile,buildah.spec.rpkg,AUTHORS,bin,vendor,.git,go.mod,go.sum,CHANGELOG.md,changelog.txt,seccomp.json,.cirrus.yml,"*.xz,*.gz,*.tar,*.tgz,*ico,*.png,*.1,*.5,*.orig,*.rej" -L passt,bu,uint,iff,od,erro -w
130+
codespell -S Makefile,buildah.spec.rpkg,AUTHORS,bin,vendor,.git,go.mod,go.sum,CHANGELOG.md,changelog.txt,seccomp.json,.cirrus.yml,"*.xz,*.gz,*.tar,*.tgz,*ico,*.png,*.1,*.5,*.orig,*.rej" -L secon,passt,bu,uint,iff,od,erro -w
127131

128132
.PHONY: validate
129133
validate: install.tools

add.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"github.com/containers/storage/pkg/idtools"
2424
"github.com/hashicorp/go-multierror"
2525
digest "github.com/opencontainers/go-digest"
26-
"github.com/opencontainers/runc/libcontainer/userns"
2726
"github.com/opencontainers/runtime-spec/specs-go"
2827
"github.com/sirupsen/logrus"
2928
)
@@ -438,7 +437,7 @@ func (b *Builder) Add(destination string, extract bool, options AddAndCopyOption
438437
ChmodDirs: nil,
439438
ChownFiles: nil,
440439
ChmodFiles: nil,
441-
IgnoreDevices: userns.RunningInUserNS(),
440+
IgnoreDevices: runningInUserNS(),
442441
}
443442
putErr = copier.Put(extractDirectory, extractDirectory, putOptions, io.TeeReader(pipeReader, hasher))
444443
}
@@ -579,7 +578,7 @@ func (b *Builder) Add(destination string, extract bool, options AddAndCopyOption
579578
ChmodDirs: nil,
580579
ChownFiles: nil,
581580
ChmodFiles: nil,
582-
IgnoreDevices: userns.RunningInUserNS(),
581+
IgnoreDevices: runningInUserNS(),
583582
}
584583
putErr = copier.Put(extractDirectory, extractDirectory, putOptions, io.TeeReader(pipeReader, hasher))
585584
}

add_common.go

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//go:build !linux
2+
// +build !linux
3+
4+
package buildah
5+
6+
func runningInUserNS() bool {
7+
return false
8+
}

add_linux.go

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package buildah
2+
3+
import (
4+
"github.com/opencontainers/runc/libcontainer/userns"
5+
)
6+
7+
func runningInUserNS() bool {
8+
return userns.RunningInUserNS()
9+
}

chroot/run_test.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ func TestMounts(t *testing.T) {
497497
})
498498
},
499499
func(t *testing.T, report *types.TestReport) {
500-
foundMounts := make(map[string]bool)
500+
foundBindDestinationMount := false
501501
for _, mount := range report.Spec.Mounts {
502502
if mount.Destination == bind.destination {
503503
allRequired := true
@@ -516,10 +516,12 @@ func TestMounts(t *testing.T) {
516516
anyRejected = true
517517
}
518518
}
519-
foundMounts[mount.Destination] = allRequired && !anyRejected
519+
if allRequired && !anyRejected {
520+
foundBindDestinationMount = true
521+
}
520522
}
521523
}
522-
if !foundMounts[bind.destination] {
524+
if !foundBindDestinationMount {
523525
t.Errorf("added mount for %s not found with the right flags (%v) in %+v", bind.destination, bind.options, report.Spec.Mounts)
524526
}
525527
},

cmd/buildah/commit.go

+26
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66
"fmt"
77
"os"
8+
"strings"
89
"time"
910

1011
"github.com/containers/buildah"
@@ -49,6 +50,7 @@ type commitInputOptions struct {
4950
encryptionKeys []string
5051
encryptLayers []int
5152
unsetenvs []string
53+
addFile []string
5254
}
5355

5456
func init() {
@@ -77,6 +79,7 @@ func commitListFlagSet(cmd *cobra.Command, opts *commitInputOptions) {
7779
flags := cmd.Flags()
7880
flags.SetInterspersed(false)
7981

82+
flags.StringArrayVar(&opts.addFile, "add-file", nil, "add contents of a file to the image at a specified path (`source:destination`)")
8083
flags.StringVar(&opts.authfile, "authfile", auth.GetDefaultAuthFile(), "path of the authentication file. Use REGISTRY_AUTH_FILE environment variable to override")
8184
_ = cmd.RegisterFlagCompletionFunc("authfile", completion.AutocompleteDefault)
8285
flags.StringVar(&opts.blobCache, "blob-cache", "", "assume image blobs in the specified directory will be available for pushing")
@@ -223,6 +226,28 @@ func commitCmd(c *cobra.Command, args []string, iopts commitInputOptions) error
223226
}
224227
}
225228

229+
var addFiles map[string]string
230+
if len(iopts.addFile) > 0 {
231+
addFiles = make(map[string]string)
232+
for _, spec := range iopts.addFile {
233+
specSlice := strings.SplitN(spec, ":", 2)
234+
if len(specSlice) == 1 {
235+
specSlice = []string{specSlice[0], specSlice[0]}
236+
}
237+
if len(specSlice) != 2 {
238+
return fmt.Errorf("parsing add-file argument %q: expected 1 or 2 parts, got %d", spec, len(strings.SplitN(spec, ":", 2)))
239+
}
240+
st, err := os.Stat(specSlice[0])
241+
if err != nil {
242+
return fmt.Errorf("parsing add-file argument %q: source %q: %w", spec, specSlice[0], err)
243+
}
244+
if st.IsDir() {
245+
return fmt.Errorf("parsing add-file argument %q: source %q is not a regular file", spec, specSlice[0])
246+
}
247+
addFiles[specSlice[1]] = specSlice[0]
248+
}
249+
}
250+
226251
options := buildah.CommitOptions{
227252
PreferredManifestType: format,
228253
Manifest: iopts.manifest,
@@ -239,6 +264,7 @@ func commitCmd(c *cobra.Command, args []string, iopts commitInputOptions) error
239264
UnsetEnvs: iopts.unsetenvs,
240265
OverrideChanges: iopts.changes,
241266
OverrideConfig: overrideConfig,
267+
ExtraImageContent: addFiles,
242268
}
243269
exclusiveFlags := 0
244270
if c.Flag("reference-time").Changed {

cmd/buildah/from.go

-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"github.com/containers/buildah/pkg/cli"
1414
"github.com/containers/buildah/pkg/parse"
1515
"github.com/containers/common/pkg/auth"
16-
"github.com/containers/common/pkg/config"
1716
"github.com/sirupsen/logrus"
1817
"github.com/spf13/cobra"
1918
)
@@ -188,11 +187,6 @@ func onBuild(builder *buildah.Builder, quiet bool) error {
188187
}
189188

190189
func fromCmd(c *cobra.Command, args []string, iopts fromReply) error {
191-
defaultContainerConfig, err := config.Default()
192-
if err != nil {
193-
return fmt.Errorf("failed to get container config: %w", err)
194-
}
195-
196190
if len(args) == 0 {
197191
return errors.New("an image name (or \"scratch\") must be specified")
198192
}

cmd/buildah/main.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ var rootCmd = &cobra.Command{
5959
}
6060

6161
var (
62-
globalFlagResults globalFlags
63-
exitCode int
62+
globalFlagResults globalFlags
63+
exitCode int
64+
defaultContainerConfig *config.Config
6465
)
6566

6667
func init() {
@@ -79,12 +80,12 @@ func init() {
7980
defaultStoreDriverOptions = optionSlice
8081
}
8182

82-
containerConfig, err := config.Default()
83+
defaultContainerConfig, err = config.Default()
8384
if err != nil {
8485
logrus.Errorf(err.Error())
8586
os.Exit(1)
8687
}
87-
containerConfig.CheckCgroupsAndAdjustConfig()
88+
defaultContainerConfig.CheckCgroupsAndAdjustConfig()
8889

8990
cobra.OnInitialize(initConfig)
9091
// Disable the implicit `completion` command in cobra.
@@ -98,7 +99,7 @@ func init() {
9899
rootCmd.PersistentFlags().StringVar(&globalFlagResults.UserShortNameAliasConfPath, "short-name-alias-conf", "", "path to short name alias cache file (not usually used)")
99100
rootCmd.PersistentFlags().StringVar(&globalFlagResults.Root, "root", storageOptions.GraphRoot, "storage root dir")
100101
rootCmd.PersistentFlags().StringVar(&globalFlagResults.RunRoot, "runroot", storageOptions.RunRoot, "storage state dir")
101-
rootCmd.PersistentFlags().StringVar(&globalFlagResults.CgroupManager, "cgroup-manager", containerConfig.Engine.CgroupManager, "cgroup manager")
102+
rootCmd.PersistentFlags().StringVar(&globalFlagResults.CgroupManager, "cgroup-manager", defaultContainerConfig.Engine.CgroupManager, "cgroup manager")
102103
rootCmd.PersistentFlags().StringVar(&globalFlagResults.StorageDriver, "storage-driver", storageOptions.GraphDriverName, "storage-driver")
103104
rootCmd.PersistentFlags().StringSliceVar(&globalFlagResults.StorageOpts, "storage-opt", defaultStoreDriverOptions, "storage driver option")
104105
rootCmd.PersistentFlags().StringSliceVar(&globalFlagResults.UserNSUID, "userns-uid-map", []string{}, "default `ctrID:hostID:length` UID mapping to use")

cmd/buildah/manifest.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ func init() {
231231
flags.StringVar(&manifestPushOpts.compressionFormat, "compression-format", "", "compression format to use")
232232
flags.IntVar(&manifestPushOpts.compressionLevel, "compression-level", 0, "compression level to use")
233233
flags.StringVarP(&manifestPushOpts.format, "format", "f", "", "manifest type (oci or v2s2) to attempt to use when pushing the manifest list (default is manifest type of source)")
234-
flags.StringSliceVar(&manifestPushOpts.addCompression, "add-compression", nil, "add instances with selected compression while pushing")
234+
flags.StringArrayVar(&manifestPushOpts.addCompression, "add-compression", defaultContainerConfig.Engine.AddCompression.Get(), "add instances with selected compression while pushing")
235235
flags.BoolVarP(&manifestPushOpts.removeSignatures, "remove-signatures", "", false, "don't copy signatures when pushing images")
236236
flags.StringVar(&manifestPushOpts.signBy, "sign-by", "", "sign the image using a GPG key with the specified `FINGERPRINT`")
237237
flags.StringVar(&manifestPushOpts.signaturePolicy, "signature-policy", "", "`pathname` of signature policy file (not usually used)")

commit.go

+6
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ type CommitOptions struct {
118118
// to the configuration of the image that is being committed, after
119119
// OverrideConfig is applied.
120120
OverrideChanges []string
121+
// ExtraImageContent is a map which describes additional content to add
122+
// to the committed image. The map's keys are filesystem paths in the
123+
// image and the corresponding values are the paths of files whose
124+
// contents will be used in their place. The contents will be owned by
125+
// 0:0 and have mode 0644. Currently only accepts regular files.
126+
ExtraImageContent map[string]string
121127
}
122128

123129
var (

convertcw.go

+1
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ func CWConvertImage(ctx context.Context, systemContext *types.SystemContext, sto
171171
Slop: options.Slop,
172172
FirmwareLibrary: options.FirmwareLibrary,
173173
Logger: logger,
174+
GraphOptions: store.GraphOptions(),
174175
}
175176
rc, workloadConfig, err := mkcw.Archive(sourceDir, &source.OCIv1, archiveOptions)
176177
if err != nil {

convertcw_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func TestCWConvertImage(t *testing.T) {
7272
for _, status := range []int{http.StatusOK, http.StatusInternalServerError} {
7373
for _, ignoreChainRetrievalErrors := range []bool{false, true} {
7474
for _, ignoreAttestationErrors := range []bool{false, true} {
75-
t.Run(fmt.Sprintf("status=%d,ignoreChainRetrievalErrors=%v,ignoreAttestationErrors=%v", status, ignoreChainRetrievalErrors, ignoreAttestationErrors), func(t *testing.T) {
75+
t.Run(fmt.Sprintf("status~%d~ignoreChainRetrievalErrors~%v~ignoreAttestationErrors~%v", status, ignoreChainRetrievalErrors, ignoreAttestationErrors), func(t *testing.T) {
7676
// create a per-test Store object
7777
storeOptions := storage.StoreOptions{
7878
GraphRoot: t.TempDir(),

define/types.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ const (
5454
SNP TeeType = "snp"
5555
)
5656

57+
// DefaultRlimitValue is the value set by default for nofile and nproc
58+
const RLimitDefaultValue = uint64(1048576)
59+
5760
// TeeType is a supported trusted execution environment type.
5861
type TeeType string
5962

@@ -121,7 +124,7 @@ type ConfidentialWorkloadOptions struct {
121124
AttestationURL string
122125
CPUs int
123126
Memory int
124-
TempDir string
127+
TempDir string // used for the temporary plaintext copy of the disk image
125128
TeeType TeeType
126129
IgnoreAttestationErrors bool
127130
WorkloadID string

docs/buildah-build.1.md

+13-5
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Set the ARCH of the image to be built, and that of the base image to be pulled,
5151

5252
**--authfile** *path*
5353

54-
Path of the authentication file. Default is ${XDG_RUNTIME_DIR}/containers/auth.json. If XDG_RUNTIME_DIR is not set, the default is /run/containers/$UID/auth.json. This file is created using `buildah login`.
54+
Path of the authentication file. Default is ${XDG_RUNTIME_DIR}/containers/auth.json. See containers-auth.json(5) for more information. This file is created using `buildah login`.
5555

5656
If the authorization state is not found there, $HOME/.docker/config.json is checked, which is set using `docker login`.
5757

@@ -708,6 +708,8 @@ Valid _type_ values are:
708708
If no type is specified, the value defaults to **local**.
709709
Alternatively, instead of a comma-separated sequence, the value of **--output** can be just a destination (in the `**dest** format) (e.g. `--output some-path`, `--output -`) where `--output some-path` is treated as if **type=local** and `--output -` is treated as if **type=tar**.
710710

711+
Note: The **--tag** option can also be used to change the file image format to supported `containers-transports(5)`.
712+
711713
**--pid** *how*
712714

713715
Sets the configuration for PID namespaces when handling `RUN` instructions.
@@ -795,7 +797,7 @@ environment variable. `export BUILDAH_RUNTIME=/usr/bin/crun`
795797

796798
**--runtime-flag** *flag*
797799

798-
Adds global flags for the container rutime. To list the supported flags, please
800+
Adds global flags for the container runtime. To list the supported flags, please
799801
consult the manpages of the selected container runtime.
800802

801803
Note: Do not pass the leading `--` to the flag. To pass the runc flag `--log-format json`
@@ -872,6 +874,13 @@ Specifies the name which will be assigned to the resulting image if the build
872874
process completes successfully.
873875
If _imageName_ does not include a registry name component, the registry name *localhost* will be prepended to the image name.
874876

877+
The **--tag** option supports all transports from `containers-transports(5)`.
878+
If no transport is specified, the `containers-storage` (i.e., local storage) transport is used.
879+
880+
__buildah build --tag=oci-archive:./foo.ociarchive .__
881+
882+
__buildah build -t quay.io/username/foo .__
883+
875884
**--target** *stageName*
876885

877886
Set the target build stage to build. When building a Containerfile with multiple build stages, --target
@@ -1022,12 +1031,11 @@ Set the architecture variant of the image to be pulled.
10221031

10231032
Mount a host directory into containers when executing *RUN* instructions during
10241033
the build. The `OPTIONS` are a comma delimited list and can be:
1025-
<sup>[[1]](#Footnote1)</sup>
10261034

10271035
* [rw|ro]
10281036
* [U]
10291037
* [z|Z|O]
1030-
* [`[r]shared`|`[r]slave`|`[r]private`]
1038+
* [`[r]shared`|`[r]slave`|`[r]private`] <sup>[[1]](#Footnote1)</sup>
10311039

10321040
The `CONTAINER-DIR` must be an absolute path such as `/src/docs`. The `HOST-DIR`
10331041
must be an absolute path as well. Buildah bind-mounts the `HOST-DIR` to the
@@ -1310,7 +1318,7 @@ registries.conf is the configuration file which specifies which container regist
13101318
Signature policy file. This defines the trust policy for container images. Controls which container registries can be used for image, and whether or not the tool should trust the images.
13111319

13121320
## SEE ALSO
1313-
buildah(1), cpp(1), buildah-login(1), docker-login(1), namespaces(7), pid\_namespaces(7), containers-policy.json(5), containers-registries.conf(5), user\_namespaces(7), crun(1), runc(8), containers.conf(5), oci-hooks(5)
1321+
buildah(1), cpp(1), buildah-login(1), docker-login(1), namespaces(7), pid\_namespaces(7), containers-policy.json(5), containers-registries.conf(5), user\_namespaces(7), crun(1), runc(8), containers.conf(5), oci-hooks(5), containers-transports(5), containers-auth.json(5)
13141322

13151323
## FOOTNOTES
13161324
<a name="Footnote1">1</a>: The Buildah project is committed to inclusivity, a core value of open source. The `master` and `slave` mount propagation terminology used here is problematic and divisive, and should be changed. However, these terms are currently used within the Linux kernel and must be used as-is at this time. When the kernel maintainers rectify this usage, Buildah will follow suit immediately.

docs/buildah-commit.1.md

+16-3
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,24 @@ with a registry name component, `localhost` will be added to the name. If
1414
name, the `buildah images` command will display `<none>` in the `REPOSITORY` and
1515
`TAG` columns.
1616

17+
The *image* value supports all transports from `containers-transports(5)`. If no transport is specified, the `containers-storage` (i.e., local storage) transport is used.
18+
1719
## RETURN VALUE
1820
The image ID of the image that was created. On error, 1 is returned and errno is returned.
1921

2022
## OPTIONS
2123

24+
**--add-file** *source[:destination]*
25+
26+
Read the contents of the file `source` and add it to the committed image as a
27+
file at `destination`. If `destination` is not specified, the path of `source`
28+
will be used. The new file will be owned by UID 0, GID 0, have 0644
29+
permissions, and be given a current timestamp unless the **--timestamp** option
30+
is also specified. This option can be specified multiple times.
31+
2232
**--authfile** *path*
2333

24-
Path of the authentication file. Default is ${XDG_RUNTIME_DIR}/containers/auth.json. If XDG_RUNTIME_DIR is not set, the default is /run/containers/$UID/auth.json. This file is created using `buildah login`.
34+
Path of the authentication file. Default is ${XDG_RUNTIME_DIR}/containers/auth.json. See containers-auth.json(5) for more information. This file is created using `buildah login`.
2535

2636
If the authorization state is not found there, $HOME/.docker/config.json is checked, which is set using `docker login`.
2737

@@ -192,9 +202,12 @@ Unset environment variables from the final image.
192202
This example saves an image based on the container.
193203
`buildah commit containerID newImageName`
194204

195-
This example saves an image named newImageName based on the container.
205+
This example saves an image named newImageName based on the container and removes the working container.
196206
`buildah commit --rm containerID newImageName`
197207

208+
This example commits to an OCI archive file named /tmp/newImageName based on the container.
209+
`buildah commit containerID oci-archive:/tmp/newImageName`
210+
198211
This example saves an image with no name, removes the working container, and creates a new container using the image's ID.
199212
`buildah from $(buildah commit --rm containerID)`
200213

@@ -260,4 +273,4 @@ registries.conf is the configuration file which specifies which container regist
260273
Signature policy file. This defines the trust policy for container images. Controls which container registries can be used for image, and whether or not the tool should trust the images.
261274

262275
## SEE ALSO
263-
buildah(1), buildah-images(1), containers-policy.json(5), containers-registries.conf(5)
276+
buildah(1), buildah-images(1), containers-policy.json(5), containers-registries.conf(5), containers-transports(5), containers-auth.json(5)

0 commit comments

Comments
 (0)