From 6bd568192a19ac2c95783ff97266121ca7399786 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Budai?= Date: Thu, 5 Sep 2019 08:16:02 +0200 Subject: [PATCH] osbuild: Move /var in BuildRoot outside of tmpfs In BuildRoot a new mount /var pointing to temporary directory in host's /var/tmp is created. This enables us to have temporary storage inside the container which is not hosted on tmpfs. Thanks to that we can move larger files out of the part of filesystem which is hosted on tmpfs to save up memory on machines with low memory capacity. --- osbuild/buildroot.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/osbuild/buildroot.py b/osbuild/buildroot.py index 663ad3f2..11f98533 100644 --- a/osbuild/buildroot.py +++ b/osbuild/buildroot.py @@ -16,7 +16,13 @@ class BuildRoot: def __init__(self, root, path="/run/osbuild"): self.root = tempfile.mkdtemp(prefix="osbuild-buildroot-", dir=path) self.api = tempfile.mkdtemp(prefix="osbuild-api-", dir=path) + self.var = tempfile.mkdtemp(prefix="osbuild-var-", dir="/var/tmp") self.mounts = [] + + self.mount_root(root) + self.mount_var() + + def mount_root(self, root): for p in ["usr", "bin", "sbin", "lib", "lib64"]: source = os.path.join(root, p) target = os.path.join(self.root, p) @@ -30,6 +36,16 @@ class BuildRoot: raise self.mounts.append(target) + def mount_var(self): + target = os.path.join(self.root, "var") + os.mkdir(target) + try: + subprocess.run(["mount", "-o", "bind", self.var, target], check=True) + except subprocess.CalledProcessError: + self.unmount() + raise + self.mounts.append(target) + def unmount(self): for path in self.mounts: subprocess.run(["umount", "--lazy", path], check=True) @@ -41,6 +57,9 @@ class BuildRoot: if self.api: shutil.rmtree(self.api) self.api = None + if self.var: + shutil.rmtree(self.var) + self.var = None def run(self, argv, binds=None, readonly_binds=None, **kwargs): """Runs a command in the buildroot.