From 964d22fabd70335e225135224a611e90518fe232 Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Mon, 17 Aug 2020 12:45:48 -0400 Subject: [PATCH] Add CONTAINERS_STORAGE_CONF Environment hanlding for testing Currently it is difficult to modify the path to the storage.conf file for setting up testing. It is hard coded to use /etc/containers/storage.conf. Adding this envionment variable, will allow us to write tests on storage.conf that do not override the system defaults. Signed-off-by: Daniel J Walsh --- common/docs/containers.conf.5.md | 15 ++++++++++++++- common/pkg/config/default.go | 12 +++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/common/docs/containers.conf.5.md b/common/docs/containers.conf.5.md index 53e69ed327..328945453a 100644 --- a/common/docs/containers.conf.5.md +++ b/common/docs/containers.conf.5.md @@ -221,7 +221,7 @@ the system uses `65536k`. **tz=**"" Set timezone in container. Takes IANA timezones as well as `local`, which sets the timezone in the container to match the host machine. -If not set, then containers will run with the time zone specified in the image. +If not set, then containers will run with the time zone specified in the image. Examples: `tz="local"` `tz="America/New_York"` @@ -452,6 +452,9 @@ containers. This convention is followed by the default volume driver, but may not be by other drivers. # FILES + +**containers.conf** + Distributions often provide a `/usr/share/containers/containers.conf` file to define default container configuration. Administrators can override fields in this file by creating `/etc/containers/containers.conf` to specify their own @@ -465,6 +468,16 @@ this path will be used. This is primarily used for testing. Fields specified in the containers.conf file override the default options, as well as options in previously read containers.conf files. +**storage.conf** + +The `/etc/containers/storage.conf` file is the default storage configuration file. +Rootless users can override fields in the storage config by creating +`$HOME/.config/containers/storage.conf`. + +If the `CONTAINERS_STORAGE_CONF` path environment variable is set, this path +is used for the storage.conf file rather than the default. +This is primarily used for testing. + # SEE ALSO containers-storage.conf(5), containers-policy.json(5), containers-registries.conf(5) diff --git a/common/pkg/config/default.go b/common/pkg/config/default.go index 948f78d141..8632477d81 100644 --- a/common/pkg/config/default.go +++ b/common/pkg/config/default.go @@ -223,10 +223,16 @@ func defaultConfigFromMemory() (*EngineConfig, error) { c.EventsLogFilePath = filepath.Join(c.TmpDir, "events", "events.log") - storeOpts, err := storage.DefaultStoreOptions(unshare.IsRootless(), unshare.GetRootlessUID()) - if err != nil { - return nil, err + var storeOpts storage.StoreOptions + if path, ok := os.LookupEnv("CONTAINER_STORAGE_CONF"); ok { + storage.ReloadConfigurationFile(path, &storeOpts) + } else { + storeOpts, err = storage.DefaultStoreOptions(unshare.IsRootless(), unshare.GetRootlessUID()) + if err != nil { + return nil, err + } } + if storeOpts.GraphRoot == "" { logrus.Warnf("Storage configuration is unset - using hardcoded default graph root %q", _defaultGraphRoot) storeOpts.GraphRoot = _defaultGraphRoot