systemd/0791-ci-backport-mkosi-CI-configuration-from-upstream.patch
Jan Macku 75aa201631 systemd-252-37
Resolves: RHEL-13159,RHEL-20322,RHEL-27512,RHEL-30372,RHEL-31070,RHEL-31219,RHEL-33890,RHEL-35703,RHEL-38864,RHEL-40878,RHEL-6589
2024-06-13 16:16:12 +02:00

218 lines
7.4 KiB
Diff

From 45bcebd103f23fb595d0ff1d5e02ea5edd25f12d Mon Sep 17 00:00:00 2001
From: Frantisek Sumsal <frantisek@sumsal.cz>
Date: Tue, 27 Feb 2024 12:53:35 +0100
Subject: [PATCH] ci: backport mkosi CI configuration from upstream
Notes:
- on RHEL 9 we don't have vsock support in systemd, so we have to fall
back to some "older" checks (i.e. pre-6aca147f82).
- our systemd-repart doesn't automatically fall back to Format=swap
for Type=swap partitions, so we have to do that explicitely
- don't pull in sd-resolved and sd-networkd, since the former needs
some extra configuration to work alongsideNM, and we don't
build the latter at all on RHEL 9
RHEL-only
Related: RHEL-27512
---
.github/workflows/mkosi.yml | 139 ++++++++++++++++++
.../mkosi.extra/usr/lib/repart.d/15-swap.conf | 1 +
.../lib/systemd/mkosi-check-and-shutdown.sh | 3 +
.../system/mkosi-check-and-shutdown.service | 5 +-
4 files changed, 144 insertions(+), 4 deletions(-)
create mode 100644 .github/workflows/mkosi.yml
diff --git a/.github/workflows/mkosi.yml b/.github/workflows/mkosi.yml
new file mode 100644
index 0000000000..f9b6d9ba58
--- /dev/null
+++ b/.github/workflows/mkosi.yml
@@ -0,0 +1,139 @@
+---
+# vi: ts=2 sw=2 et:
+# SPDX-License-Identifier: LGPL-2.1-or-later
+# Simple boot tests that build and boot the mkosi images generated by the mkosi config files in mkosi.conf.d/.
+name: mkosi
+
+on:
+ push:
+ branches:
+ - main
+ - v[0-9]+-stable
+ paths:
+ - '**'
+ - '!README*'
+ - '!LICENSE*'
+ - '!LICENSES/**'
+ - '!TODO'
+ - '!docs/**'
+ - '!man/**'
+ - '!catalog/**'
+ - '!shell-completion/**'
+ - '!po/**'
+ - '!.**'
+ - '.github/**'
+
+ pull_request:
+ branches:
+ - main
+ - v[0-9]+-stable
+ paths:
+ - '**'
+ - '!README*'
+ - '!LICENSE*'
+ - '!LICENSES/**'
+ - '!TODO'
+ - '!docs/**'
+ - '!man/**'
+ - '!catalog/**'
+ - '!shell-completion/**'
+ - '!po/**'
+ - '!.**'
+ - '.github/**'
+
+permissions:
+ contents: read
+
+jobs:
+ ci:
+ runs-on: ubuntu-22.04
+ concurrency:
+ group: ${{ github.workflow }}-${{ matrix.distro }}-${{ matrix.release }}-${{ github.ref }}
+ cancel-in-progress: true
+ strategy:
+ fail-fast: false
+ matrix:
+ include:
+ - distro: centos
+ release: "9"
+
+ env:
+ SYSTEMD_LOG_LEVEL: debug
+
+ steps:
+ - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
+ - uses: systemd/mkosi@070528fec478fc93af7ec057a5d2fd0045123c99
+
+ - name: Configure
+ run: |
+ tee mkosi.local.conf <<EOF
+ [Distribution]
+ Distribution=${{ matrix.distro }}
+ Release=${{ matrix.release }}
+
+ [Output]
+ Format=disk
+
+ [Content]
+ Environment=CI_BUILD=1
+ SLOW_TESTS=true
+
+ [Host]
+ ToolsTree=default
+ ToolsTreeDistribution=fedora
+ # Sometimes we run on a host with /dev/kvm, but it is broken, so explicitly disable it
+ QemuKvm=no
+ EOF
+
+ # These should override the options from mkosi.conf so we put them in a dropin that's ordered later
+ # instead.
+ tee mkosi.conf.d/99-ci.conf <<EOF
+ [Host]
+ KernelCommandLineExtra=systemd.unit=mkosi-check-and-shutdown.service
+ systemd.journald.max_level_console=debug
+ # udev's debug log output is very verbose, so up it to info in CI.
+ udev.log_level=info
+ # Root device can take a long time to appear, so let's bump the timeout.
+ systemd.default_device_timeout_sec=180
+ EOF
+
+ # For erofs, we have to install linux-modules-extra-azure, but that doesn't match the running kernel
+ # version, so we can't load the erofs module. squashfs is a builtin module so we use that instead.
+
+ mkdir -p mkosi.images/system/mkosi.repart/10-usr.conf.d
+ tee mkosi.images/system/mkosi.repart/10-usr.conf.d/squashfs.conf <<EOF
+ [Partition]
+ Format=squashfs
+ EOF
+
+ # The emergency shell is not useful in the CI, as it just blocks for a long time before the job
+ # eventually times out. Override it to just shutdown immediately.
+ mkdir -p mkosi.images/initrd/mkosi.extra/usr/lib/systemd/system/emergency.service.d/
+ mkdir -p mkosi.images/system/mkosi.extra/usr/lib/systemd/system/emergency.service.d/
+ tee mkosi.images/initrd/mkosi.extra/usr/lib/systemd/system/emergency.service.d/poweroff.conf <<EOF
+ [Unit]
+ FailureAction=exit
+ [Service]
+ ExecStartPre=
+ ExecStart=
+ ExecStart=false
+ EOF
+ cp mkosi.images/initrd/mkosi.extra/usr/lib/systemd/system/emergency.service.d/poweroff.conf mkosi.images/system/mkosi.extra/usr/lib/systemd/system/emergency.service.d/poweroff.conf
+
+ - name: Generate secure boot key
+ run: mkosi --debug genkey
+
+ - name: Show image summary
+ run: mkosi summary
+
+ - name: Build
+ run: mkosi --debug
+
+ - name: Boot systemd-nspawn
+ run: sudo mkosi --debug boot
+
+ - name: Boot QEMU
+ run: timeout -k 30 10m mkosi --debug qemu
+
+ - name: Check ${{ matrix.distro }} QEMU
+ run: sudo mkosi shell bash -c "[[ -e /testok ]] || { cat /failed-services; exit 1; }"
diff --git a/mkosi.images/system/mkosi.extra/usr/lib/repart.d/15-swap.conf b/mkosi.images/system/mkosi.extra/usr/lib/repart.d/15-swap.conf
index 3755278462..1cbd6c7c2f 100644
--- a/mkosi.images/system/mkosi.extra/usr/lib/repart.d/15-swap.conf
+++ b/mkosi.images/system/mkosi.extra/usr/lib/repart.d/15-swap.conf
@@ -2,5 +2,6 @@
[Partition]
Type=swap
+Format=swap
SizeMinBytes=100M
SizeMaxBytes=100M
diff --git a/mkosi.images/system/mkosi.extra/usr/lib/systemd/mkosi-check-and-shutdown.sh b/mkosi.images/system/mkosi.extra/usr/lib/systemd/mkosi-check-and-shutdown.sh
index 9bb246263e..210fa78850 100755
--- a/mkosi.images/system/mkosi.extra/usr/lib/systemd/mkosi-check-and-shutdown.sh
+++ b/mkosi.images/system/mkosi.extra/usr/lib/systemd/mkosi-check-and-shutdown.sh
@@ -1,6 +1,8 @@
#!/bin/bash -eux
# SPDX-License-Identifier: LGPL-2.1-or-later
+rm -f /testok
+
# TODO: Figure out why this is failing
systemctl reset-failed systemd-vconsole-setup.service
@@ -17,3 +19,4 @@ fi
# Exit with non-zero EC if the /failed-services file is not empty (we have -e set)
[[ ! -s /failed-services ]]
+touch /testok
diff --git a/mkosi.images/system/mkosi.extra/usr/lib/systemd/system/mkosi-check-and-shutdown.service b/mkosi.images/system/mkosi.extra/usr/lib/systemd/system/mkosi-check-and-shutdown.service
index 7942cbfa77..4021ede274 100644
--- a/mkosi.images/system/mkosi.extra/usr/lib/systemd/system/mkosi-check-and-shutdown.service
+++ b/mkosi.images/system/mkosi.extra/usr/lib/systemd/system/mkosi-check-and-shutdown.service
@@ -3,12 +3,9 @@
Description=Check if any service failed and then shutdown the machine
After=multi-user.target network-online.target
Requires=multi-user.target
-Wants=systemd-resolved.service systemd-networkd.service network-online.target
+Wants=network-online.target
SuccessAction=exit
FailureAction=exit
-# On success, exit with 123 so that we can check that we receive the actual exit code from the script on the
-# host.
-SuccessActionExitStatus=123
[Service]
Type=oneshot