From 4bf3f11b78af3ed1f1ce40415eb0e210ba01a154 Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Sun, 16 Feb 2025 16:27:41 +0100 Subject: [PATCH] pmb.helpers.apk: support PMB_APK_NO_CACHE Add a new environment variable that disables apk's caching feature for space constrained environments such as the bpo image build jobs. Currently we have a workaround in place in bpo: the apk cache is moved to a tmpfs. But this is fragile and just disabling the apk cache is a more elegant solution. I've decided to make this an env var instead of a full pmbootstrap option since this option is not relevant for normal users, only for CI jobs in space constrained environments. Also we already have another `PMB_APK_` env var. Related: bpo issue 136 Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2553 --- docs/environment_variables.md | 5 +++++ pmb/helpers/apk.py | 14 +++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/docs/environment_variables.md b/docs/environment_variables.md index 67d8ea80..72f2026e 100644 --- a/docs/environment_variables.md +++ b/docs/environment_variables.md @@ -14,6 +14,11 @@ APKINDEX results in a 404 not found error. This is used by the first time. For example if the `x86_64` repository was already built and published, but the `aarch64` repository wasn't published yet. +## `PMB_APK_NO_CACHE` + +When this is set to `1`, pmbootstrap will disable apk's caching feature. This +is used by bpo for image build jobs, so these jobs don't need as much space. + ## `PMB_FDE_PASSWORD` This variable can be used to set the password when running `install --fde`. The diff --git a/pmb/helpers/apk.py b/pmb/helpers/apk.py index 1322b65b..e46d6057 100644 --- a/pmb/helpers/apk.py +++ b/pmb/helpers/apk.py @@ -173,10 +173,14 @@ def _prepare_cmd(command: Sequence[PathString], chroot: Chroot | None) -> list[s str(chroot.path), "--arch", str(chroot.arch), - "--cache-dir", - str(cache_dir), ] ) + + if os.getenv("PMB_APK_NO_CACHE") == "1": + _command.extend(["--no-cache"]) + else: + _command.extend(["--cache-dir", str(cache_dir)]) + local_repos = pmb.helpers.repo.urls( user_repository=config.work / "packages", mirrors_exclude=True ) @@ -212,7 +216,11 @@ def run(command: Sequence[PathString], chroot: Chroot, with_progress: bool = Tru raise RuntimeError( "Encountered an 'apk add' command without --no-interactive! This is a bug." ) - if "--cache-dir" not in _command: + if os.getenv("PMB_APK_NO_CACHE") == "1" and "--no-cache" not in _command: + raise RuntimeError( + "Encountered an 'apk add' command without --no-cache! This is a bug." + ) + if os.getenv("PMB_APK_NO_CACHE") != "1" and "--cache-dir" not in _command: raise RuntimeError( "Encountered an 'apk add' command without --cache-dir! This is a bug." )