]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Debugging improvements
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 30 Jan 2024 13:19:24 +0000 (14:19 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 31 Jan 2024 13:24:41 +0000 (14:24 +0100)
Make sure /var/log from the sandbox is persisted so we can access logs
more easily. Also enable dnf debug logging if ARG_DEBUG is set.

mkosi/context.py
mkosi/installer/dnf.py

index 4214c421d961b3c37eda13991eb449bef724dc56..43aff6d0977b7251eb801d6ba9566b44d36a6a3a 100644 (file)
@@ -35,6 +35,7 @@ class Context:
 
         self.staging.mkdir()
         self.pkgmngr.mkdir()
+        (self.pkgmngr / "var/log").mkdir(parents=True)
         self.packages.mkdir()
         self.install_dir.mkdir(exist_ok=True)
         self.cache_dir.mkdir(parents=True, exist_ok=True)
@@ -84,6 +85,7 @@ class Context:
                     for p in (self.pkgmngr / "etc").iterdir()
                 ),
                 *options,
+                "--bind", self.pkgmngr / "var/log", "/var/log",
                 *(["--ro-bind", os.fspath(p), os.fspath(p)] if (p := self.pkgmngr / "usr").exists() else []),
             ],
         ) + (
index d195470d0e696189c9e6b7b9a7694544f33d3d9c..65c302aa421fdec60889071ddf4491f43019c714 100644 (file)
@@ -6,6 +6,7 @@ from pathlib import Path
 from mkosi.context import Context
 from mkosi.installer import finalize_package_manager_mounts
 from mkosi.installer.rpm import RpmRepository, fixup_rpmdb_location, setup_rpm
+from mkosi.log import ARG_DEBUG
 from mkosi.mounts import finalize_ephemeral_source_mounts
 from mkosi.run import find_binary, run
 from mkosi.sandbox import apivfs_cmd
@@ -93,6 +94,7 @@ def dnf_cmd(context: Context) -> list[PathString]:
         f"--releasever={context.config.release}",
         f"--installroot={context.root}",
         "--setopt=keepcache=1",
+        "--setopt=logdir=/var/log",
         f"--setopt=cachedir=/var/cache/{dnf_subdir(context)}",
         f"--setopt=persistdir=/var/lib/{dnf_subdir(context)}",
         f"--setopt=install_weak_deps={int(context.config.with_recommends)}",
@@ -101,6 +103,9 @@ def dnf_cmd(context: Context) -> list[PathString]:
         "--enable-plugin=builddep" if dnf.endswith("dnf5") else "--enableplugin=builddep",
     ]
 
+    if ARG_DEBUG.get():
+        cmdline += ["--setopt=debuglevel=10"]
+
     if not context.config.repository_key_check:
         cmdline += ["--nogpgcheck"]
 
@@ -150,11 +155,12 @@ def invoke_dnf(context: Context, command: str, packages: Iterable[str], apivfs:
 
     fixup_rpmdb_location(context)
 
-    # The log directory is always interpreted relative to the install root so there's nothing we can do but
-    # to remove the log files from the install root afterwards.
-    for p in (context.root / "var/log").iterdir():
-        if any(p.name.startswith(prefix) for prefix in ("dnf", "hawkey", "yum")):
-            p.unlink()
+    # dnf interprets the log directory relative to the install root so there's nothing we can do but to remove the log
+    # files from the install root afterwards.
+    if (context.root / "var/log").exists():
+        for p in (context.root / "var/log").iterdir():
+            if any(p.name.startswith(prefix) for prefix in ("dnf", "hawkey", "yum")):
+                p.unlink()
 
 
 def createrepo_dnf(context: Context) -> None: