Skip to content

Commit

Permalink
buildah: new global option --cgroup-manager
Browse files Browse the repository at this point in the history
allow to override the cgroup manager with a global option
--cgroup-manager=MANAGER that has the same semantic as Podman.

Signed-off-by: Giuseppe Scrivano <[email protected]>
  • Loading branch information
giuseppe committed Feb 14, 2022
1 parent 87f6c19 commit 5a999cf
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cmd/buildah/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type globalFlags struct {
cpuProfileFile *os.File
MemoryProfile string
UserShortNameAliasConfPath string
CgroupManager string
}

var rootCmd = &cobra.Command{
Expand Down Expand Up @@ -77,6 +78,13 @@ func init() {
defaultStoreDriverOptions = optionSlice
}

containerConfig, err := config.Default()
if err != nil {
logrus.Errorf(err.Error())
os.Exit(1)
}
containerConfig.CheckCgroupsAndAdjustConfig()

cobra.OnInitialize(initConfig)
// Disable the implicit `completion` command in cobra.
rootCmd.CompletionOptions.DisableDefaultCmd = true
Expand All @@ -89,6 +97,7 @@ func init() {
rootCmd.PersistentFlags().StringVar(&globalFlagResults.UserShortNameAliasConfPath, "short-name-alias-conf", "", "path to short name alias cache file (not usually used)")
rootCmd.PersistentFlags().StringVar(&globalFlagResults.Root, "root", storageOptions.GraphRoot, "storage root dir")
rootCmd.PersistentFlags().StringVar(&globalFlagResults.RunRoot, "runroot", storageOptions.RunRoot, "storage state dir")
rootCmd.PersistentFlags().StringVar(&globalFlagResults.CgroupManager, "cgroup-manager", containerConfig.Engine.CgroupManager, "cgroup manager")
rootCmd.PersistentFlags().StringVar(&globalFlagResults.StorageDriver, "storage-driver", storageOptions.GraphDriverName, "storage-driver")
rootCmd.PersistentFlags().StringSliceVar(&globalFlagResults.StorageOpts, "storage-opt", defaultStoreDriverOptions, "storage driver option")
rootCmd.PersistentFlags().StringSliceVar(&globalFlagResults.UserNSUID, "userns-uid-map", []string{}, "default `ctrID:hostID:length` UID mapping to use")
Expand Down
1 change: 1 addition & 0 deletions cmd/buildah/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ func runCmd(c *cobra.Command, args []string, iopts runInputOptions) error {
options.Mounts = mounts
// Run() will automatically clean them up.
options.ExternalImageMounts = mountedImages
options.CgroupManager = globalFlagResults.CgroupManager

runerr := builder.Run(args, options)

Expand Down
5 changes: 5 additions & 0 deletions contrib/completions/bash/buildah
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ return 1
--version -v
"
local options_with_args="
--cgroup-manager
--registries-conf
--registries-conf-dir
--root
Expand Down Expand Up @@ -200,6 +201,10 @@ return 1
COMPREPLY=($(compgen -W 'devicemapper overlay2' -- "$cur"))
return
;;
--cgroup-manager)
COMPREPLY=($(compgen -W 'cgroupfs systemd' -- "$cur"))
return
;;
$(__buildah_to_extglob "$options_with_args"))
return
;;
Expand Down
7 changes: 7 additions & 0 deletions docs/buildah.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ The Buildah package provides a command line tool which can be used to:

## OPTIONS

**--cgroup-manager**=*manager*

The CGroup manager to use for container cgroups. Supported values are cgroupfs or systemd. Default is systemd unless overridden in the containers.conf file.

Note: Setting this flag can cause certain commands to break when called on containers previously created by the other CGroup manager type.
Note: CGroup manager is not supported in rootless mode when using CGroups Version V1.

**--log-level** **value**

The log level to be used. Either "trace", "debug", "info", "warn", "error", "fatal", or "panic", defaulting to "warn".
Expand Down
2 changes: 2 additions & 0 deletions run.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ type RunOptions struct {
ExternalImageMounts []string
// System context of current build
SystemContext *types.SystemContext
// CgroupManager to use for running OCI containers
CgroupManager string
}

// RunMountArtifacts are the artifacts created when using a run mount.
Expand Down

0 comments on commit 5a999cf

Please sign in to comment.