]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
ci: Do all work on a btrfs filesystem 2497/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 13 Mar 2024 16:20:19 +0000 (17:20 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 13 Mar 2024 21:52:48 +0000 (22:52 +0100)
Let's make sure we take advantage of our COW and subvolume support
in CI by doing all work in a btrfs filesystem. Additionally enable
compression and user subvolume deletes on the btrfs filesystem to
speed things up even more.

.github/workflows/ci.yml
tests/__init__.py
tests/test_initrd.py
tests/test_sysext.py

index 1e2c3cd6d81f02d7e7cb978343ef99b276408996..f688d445bf2b91cc3525015b62f0531a45facfba 100644 (file)
@@ -133,16 +133,30 @@ jobs:
     - name: Install
       run: |
         sudo apt-get update
-        sudo apt-get install python3-pytest lvm2 cryptsetup-bin
+        sudo apt-get install python3-pytest lvm2 cryptsetup-bin btrfs-progs
         # Make sure the latest changes from the pull request are used.
         sudo ln -svf $PWD/bin/mkosi /usr/bin/mkosi
       working-directory: ./
 
+    - name: Btrfs
+      run: |
+        truncate --size=20G btrfs.raw
+        mkfs.btrfs btrfs.raw
+        sudo mkdir -p /mnt/mkosi
+        LOOP="$(sudo losetup --find --show --direct-io=on btrfs.raw)"
+        sudo mount "$LOOP" /mnt/mkosi --options compress=zstd,user_subvol_rm_allowed
+        sudo chown "$(id -u):$(id -g)" /mnt/mkosi
+
     - name: Configure
       run: |
         tee mkosi.local.conf <<EOF
         [Output]
         ManifestFormat=json
+        UseSubvolumes=yes
+
+        CacheDirectory=/mnt/mkosi/mkosi.cache
+        PackageCacheDirectory=/mnt/mkosi/mkosi.cache
+        WorkspaceDirectory=/mnt/mkosi
 
         [Content]
         KernelCommandLine=systemd.default_device_timeout_sec=180
@@ -170,7 +184,8 @@ jobs:
 
     - name: Run integration tests
       run: |
-        sudo timeout -k 30 1h python3 -m pytest \
+        sudo TMPDIR=/mnt/mkosi \
+            timeout -k 30 1h python3 -m pytest \
             --tb=no \
             --capture=no \
             --verbose \
index 471151cc98dd6786c3f029fa3fc4cd9c43590745..6363cc635b904ebd761eb4d9aa0a487fd1d08a34 100644 (file)
@@ -3,8 +3,9 @@
 import os
 import subprocess
 import sys
-import tempfile
+import uuid
 from collections.abc import Iterator, Sequence
+from pathlib import Path
 from types import TracebackType
 from typing import Any, NamedTuple, Optional
 
@@ -29,8 +30,7 @@ class Image:
         self.config = config
 
     def __enter__(self) -> "Image":
-        self.output_dir = tempfile.TemporaryDirectory(dir="/var/tmp")
-        os.chown(self.output_dir.name, INVOKING_USER.uid, INVOKING_USER.gid)
+        self.output_dir = Path(os.getenv("TMPDIR", "/var/tmp")) / uuid.uuid4().hex[:16]
 
         return self
 
@@ -79,8 +79,7 @@ class Image:
             ),
             *self.options,
             *options,
-            "--output-dir", self.output_dir.name,
-            "--cache-dir", "mkosi.cache",
+            "--output-dir", self.output_dir,
             *(f"--kernel-command-line={i}" for i in kcl),
             "--qemu-vsock=yes",
             verb,
index c2327734e5c8ac6847c323fb515aef056bc64ff2..6df167ec52617445d1433a24dc7390c92b4cfc2a 100644 (file)
@@ -58,7 +58,7 @@ def test_initrd(initrd: Image) -> None:
     with Image(
         initrd.config,
         options=[
-            "--initrd", Path(initrd.output_dir.name) / "initrd",
+            "--initrd", Path(initrd.output_dir) / "initrd",
             "--kernel-command-line=systemd.unit=mkosi-check-and-shutdown.service",
             "--incremental",
             "--ephemeral",
@@ -93,7 +93,7 @@ def test_initrd_lvm(initrd: Image) -> None:
     with Image(
         initrd.config,
         options=[
-            "--initrd", Path(initrd.output_dir.name) / "initrd",
+            "--initrd", Path(initrd.output_dir) / "initrd",
             "--kernel-command-line=systemd.unit=mkosi-check-and-shutdown.service",
             "--kernel-command-line=root=LABEL=root",
             "--kernel-command-line=rw",
@@ -104,7 +104,7 @@ def test_initrd_lvm(initrd: Image) -> None:
     ) as image, contextlib.ExitStack() as stack:
         image.build(["--format", "directory"])
 
-        drive = Path(image.output_dir.name) / "image.raw"
+        drive = Path(image.output_dir) / "image.raw"
         drive.touch()
         os.truncate(drive, 5000 * 1024**2)
 
@@ -125,7 +125,7 @@ def test_initrd_lvm(initrd: Image) -> None:
         with tempfile.TemporaryDirectory() as mnt, mount(Path("/dev/vg_mkosi/lv0"), Path(mnt)):
             # The image might have been built unprivileged so we need to fix the file ownership. Making all the
             # files owned by root isn't completely correct but good enough for the purposes of the test.
-            copy_tree(Path(image.output_dir.name) / "image", Path(mnt), preserve=False)
+            copy_tree(Path(image.output_dir) / "image", Path(mnt), preserve=False)
 
         stack.close()
 
@@ -179,7 +179,7 @@ def test_initrd_luks(initrd: Image, passphrase: Path) -> None:
         with Image(
             initrd.config,
             options=[
-                "--initrd", Path(initrd.output_dir.name) / "initrd",
+                "--initrd", Path(initrd.output_dir) / "initrd",
                 "--repart-dir", repartd,
                 "--passphrase", passphrase,
                 "--kernel-command-line=systemd.unit=mkosi-check-and-shutdown.service",
@@ -201,7 +201,7 @@ def test_initrd_luks_lvm(config: Image.Config, initrd: Image, passphrase: Path)
     with Image(
         config,
         options=[
-            "--initrd", Path(initrd.output_dir.name) / "initrd",
+            "--initrd", Path(initrd.output_dir) / "initrd",
             "--kernel-command-line=systemd.unit=mkosi-check-and-shutdown.service",
             "--kernel-command-line=root=LABEL=root",
             "--kernel-command-line=rw",
@@ -213,7 +213,7 @@ def test_initrd_luks_lvm(config: Image.Config, initrd: Image, passphrase: Path)
     ) as image, contextlib.ExitStack() as stack:
         image.build(["--format", "directory"])
 
-        drive = Path(image.output_dir.name) / "image.raw"
+        drive = Path(image.output_dir) / "image.raw"
         drive.touch()
         os.truncate(drive, 5000 * 1024**2)
 
@@ -248,7 +248,7 @@ def test_initrd_luks_lvm(config: Image.Config, initrd: Image, passphrase: Path)
         with tempfile.TemporaryDirectory() as mnt, mount(Path("/dev/vg_mkosi/lv0"), Path(mnt)):
             # The image might have been built unprivileged so we need to fix the file ownership. Making all the
             # files owned by root isn't completely correct but good enough for the purposes of the test.
-            copy_tree(Path(image.output_dir.name) / "image", Path(mnt), preserve=False)
+            copy_tree(Path(image.output_dir) / "image", Path(mnt), preserve=False)
 
         stack.close()
 
@@ -268,4 +268,4 @@ def test_initrd_size(initrd: Image) -> None:
         Distribution.opensuse: 39,
     }.get(initrd.config.distribution, 48)
 
-    assert (Path(initrd.output_dir.name) / "initrd").stat().st_size <= maxsize
+    assert (Path(initrd.output_dir) / "initrd").stat().st_size <= maxsize
index 39ecec0363386a60c056581a01a900ae4974fd40..122f1c8804c0f48b7d3d5ef04dae2440739984bc 100644 (file)
@@ -24,7 +24,7 @@ def test_sysext(config: Image.Config) -> None:
             image.config,
             options=[
                 "--directory", "",
-                "--base-tree", Path(image.output_dir.name) / "image",
+                "--base-tree", Path(image.output_dir) / "image",
                 "--overlay",
                 "--package=dnsmasq",
                 "--format=disk",