From: Daan De Meyer Date: Fri, 15 Mar 2024 14:05:58 +0000 (+0100) Subject: Add more logging when we don't reuse cached images X-Git-Tag: v23~87^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F2516%2Fhead;p=thirdparty%2Fmkosi.git Add more logging when we don't reuse cached images --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 47741e762..89fc8f30d 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -53,7 +53,7 @@ from mkosi.context import Context from mkosi.distributions import Distribution from mkosi.installer import clean_package_manager_metadata from mkosi.kmod import gen_required_kernel_modules, process_kernel_modules -from mkosi.log import complete_step, die, log_notice, log_step +from mkosi.log import ARG_DEBUG, complete_step, die, log_notice, log_step from mkosi.manifest import Manifest from mkosi.mounts import finalize_source_mounts, mount_overlay from mkosi.pager import page @@ -2946,14 +2946,26 @@ def have_cache(config: Config) -> bool: return False final, build, manifest = cache_tree_paths(config) - if not final.exists() or (need_build_overlay(config) and not build.exists()): + if not final.exists(): + logging.info(f"{final} does not exist, not reusing cached images") + return False + + if need_build_overlay(config) and not build.exists(): + logging.info(f"{build} does not exist, not reusing cached images") return False if manifest.exists(): prev = json.loads(manifest.read_text()) - if prev != json.loads(json.dumps(config.cache_manifest(), cls=JsonEncoder)): + new = json.dumps(config.cache_manifest(), cls=JsonEncoder, indent=4, sort_keys=True) + if prev != json.loads(new): + logging.info("Cache manifest mismatch, not reusing cached images") + if ARG_DEBUG.get(): + run(["diff", manifest, "-"], input=new, check=False, + sandbox=config.sandbox(mounts=[Mount(manifest, manifest)])) + return False else: + logging.info(f"{manifest} does not exist, not reusing cached images") return False # Either we're running as root and the cache is owned by root or we're running unprivileged inside a user @@ -2961,6 +2973,7 @@ def have_cache(config: Config) -> bool: # generated by an unprivileged build, the cache will not be owned by root and we should not use it. for p in (final, build): if p.exists() and os.getuid() == 0 and p.stat().st_uid != 0: + logging.info("Running as root but cached images were not built as root, not reusing cached images") return False return True