From: Daan De Meyer Date: Sat, 13 Apr 2024 16:03:41 +0000 (+0200) Subject: Add Cacheonly.never and rename Cacheonly.none to Cacheonly.auto X-Git-Tag: v23~4^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1e7fdcdef9abd69350b16b3461d62bc2c19755f5;p=thirdparty%2Fmkosi.git Add Cacheonly.never and rename Cacheonly.none to Cacheonly.auto When set to "never", we'll always sync repository metadata. --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 45c347add..60c32c6b4 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -324,8 +324,8 @@ def configure_autologin(context: Context) -> None: @contextlib.contextmanager -def mount_cache_overlay(context: Context) -> Iterator[None]: - if not context.config.incremental or not context.config.base_trees or context.config.overlay: +def mount_cache_overlay(context: Context, cached: bool) -> Iterator[None]: + if not context.config.incremental or not context.config.base_trees or context.config.overlay or cached: yield return @@ -3506,15 +3506,16 @@ def lock_repository_metadata(config: Config) -> Iterator[None]: def copy_repository_metadata(context: Context) -> None: - if have_cache(context.config): - return - subdir = context.config.distribution.package_manager(context.config).subdir(context.config) - # Don't copy anything if the repository metadata directories are already populated. + # Don't copy anything if the repository metadata directories are already populated and we're not explicitly asked + # to sync repository metadata. if ( - any((context.package_cache_dir / "cache" / subdir).glob("*")) or - any((context.package_cache_dir / "lib" / subdir).glob("*")) + context.config.cacheonly != Cacheonly.never and + ( + any((context.package_cache_dir / "cache" / subdir).glob("*")) or + any((context.package_cache_dir / "lib" / subdir).glob("*")) + ) ): logging.debug(f"Found repository metadata in {context.package_cache_dir}, not copying repository metadata") return @@ -3562,15 +3563,14 @@ def build_image(context: Context) -> None: install_base_trees(context) cached = reuse_cache(context) - if not cached: - with mount_cache_overlay(context): - copy_repository_metadata(context) + with mount_cache_overlay(context, cached): + copy_repository_metadata(context) context.config.distribution.setup(context) install_package_directories(context) if not cached: - with mount_cache_overlay(context): + with mount_cache_overlay(context, cached): install_skeleton_trees(context) install_distribution(context) run_prepare_scripts(context, build=False) @@ -4268,7 +4268,10 @@ def rchown_package_manager_dirs(config: Config) -> Iterator[None]: def sync_repository_metadata(context: Context) -> None: - if have_cache(context.config) or context.config.cacheonly != Cacheonly.none: + if ( + context.config.cacheonly != Cacheonly.never and + (have_cache(context.config) or context.config.cacheonly != Cacheonly.auto) + ): return with ( diff --git a/mkosi/config.py b/mkosi/config.py index 7dadb4610..b3324e4c5 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -259,9 +259,11 @@ class ShimBootloader(StrEnum): class Cacheonly(StrEnum): - always = enum.auto() - none = enum.auto() + always = enum.auto() + auto = enum.auto() + none = auto metadata = enum.auto() + never = enum.auto() class QemuFirmware(StrEnum): @@ -1898,11 +1900,11 @@ SETTINGS = ( dest="cacheonly", long="--cache-only", name="CacheOnly", - metavar="CACHEONLY", section="Distribution", - parse=config_make_enum_parser_with_boolean(Cacheonly, yes=Cacheonly.always, no=Cacheonly.none), - default=Cacheonly.none, + parse=config_make_enum_parser_with_boolean(Cacheonly, yes=Cacheonly.always, no=Cacheonly.auto), + default=Cacheonly.auto, help="Only use the package cache when installing packages", + choices=Cacheonly.values(), ), ConfigSetting( dest="package_manager_trees", diff --git a/mkosi/resources/mkosi.md b/mkosi/resources/mkosi.md index fad19033a..819680da9 100644 --- a/mkosi/resources/mkosi.md +++ b/mkosi/resources/mkosi.md @@ -643,13 +643,16 @@ boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`, `CacheOnly=`, `--cache-only=` -: Takes one of `none`, `metadata` or `always`. If `always`, the package - manager is instructed not to contact the network. This provides a - minimal level of reproducibility, as long as the package cache is - already fully populated. If set to `metadata`, the package manager can - still download packages, but we won't sync the repository metadata. If - set to `none`, the repository metadata is synced and packages can be - downloaded during the build. +: Takes one of `auto`, `metadata`, `always` or `never`. Defaults to + `auto`. If `always`, the package manager is instructed not to contact + the network. This provides a minimal level of reproducibility, as long + as the package cache is already fully populated. If set to `metadata`, + the package manager can still download packages, but we won't sync the + repository metadata. If set to `auto`, the repository metadata is + synced unless we have a cached image (see `Incremental=`) and packages + can be downloaded during the build. If set to `never`, repository + metadata is always synced and and packages can be downloaded during + the build. `PackageManagerTrees=`, `--package-manager-tree=`