From a2e212bb2641cf28e5701ad4a2202261c2c5ee5c Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Wed, 9 Nov 2022 19:19:57 +0100 Subject: [PATCH] stages/containers.storage: ability to specify a base file In newer version of the container storage package the config file moved from `/etc/containers` to `/usr/containers/`. The later is not marked as config, so we don't want to change it. The current containers code[1] will read _either_ a file in `usr` or in `etc` depending on the existence of the latter. This we can not just write the keys we want into a file in `/etc/containers` without losing all other defaults set in the config file. A new option `filebase` is therefore added, that when given will be read and form the bases of the configuration data. Then data from the target file (given via `filename`) will be merged into and finally the actual configuration will be applied on top. [1] https://github.com/containers/storage/blob/232bf398bd68595d2a6e53ec07d8b3c4424be3c0/types/options.go#L85 --- stages/org.osbuild.containers.storage.conf | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/stages/org.osbuild.containers.storage.conf b/stages/org.osbuild.containers.storage.conf index 64524a56..f2f89ab1 100755 --- a/stages/org.osbuild.containers.storage.conf +++ b/stages/org.osbuild.containers.storage.conf @@ -87,6 +87,10 @@ SCHEMA = r""" "/usr/share/containers/storage.conf" ] }, + "filebase": { + "type": "string", + "description": "Read the base configuration from this file." + }, "comment": { "type": "array", "items": { @@ -166,14 +170,24 @@ def main(tree, options): location = options.get("filename", DEFAULT_LOCATION) config = options["config"] comment = options.get("comment", []) + filebase = options.get("filebase") path = os.path.join(tree, location.lstrip("/")) data = {} - with contextlib.suppress(FileNotFoundError): - with open(path, "r", encoding="utf8") as f: + # if a filebase was specified, we use it as base + if filebase: + with open(filebase, "r", encoding="utf8") as f: data = toml.load(f) + # if the target exists, we merge it + with contextlib.suppress(FileNotFoundError): + with open(path, "r", encoding="utf8") as f: + have = toml.load(f) + + merge_config("storage", data, have) + + # now merge our configuration into data merge_config("storage", data, config) with open(path, "w", encoding="utf8") as f: