]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Add more logging when we don't reuse cached images 2516/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 15 Mar 2024 14:05:58 +0000 (15:05 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 15 Mar 2024 16:19:11 +0000 (17:19 +0100)
mkosi/__init__.py

index 47741e762cb3be1b6b1a409745f34e92cbfb8468..89fc8f30d57434555d8071b762ff77685b019237 100644 (file)
@@ -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