diff --git a/README.md b/README.md index 79d2c78..3d717b1 100644 --- a/README.md +++ b/README.md @@ -23,14 +23,12 @@ image. Download [the disk image](https://git.plabble.org/api/packages/Job79/generic/runneros/latest/runneros.qcow2), resize it to the disk size you want and boot it with UEFI and a TPM. At first boot, the screen offers a recovery key for the encrypted disk and asks for a -root password. Then log in as root and register the runner with a token from -Gitea's runner settings: +root password. Then it asks how many jobs to run at once, the Gitea URL and a +registration token from Gitea's runner settings. It registers under the +hostname, `runneros-` and four hex digits, and starts. -```sh -gitea-runner -c /etc/gitea-runner/config.yaml register -``` - -It registers under the hostname, `runneros-` and four hex digits, and starts. +To change the number of parallel jobs later, run `systemctl edit +gitea-runner` and set `Environment=CAPACITY=` under `[Service]`. To start over, run `systemctl start factory-reset.target` as root. It reboots and wipes the root partition (`/etc` and `/var`), and the VM sets itself up as diff --git a/mkosi.extra/etc/gitea-runner/config.yaml b/mkosi.extra/etc/gitea-runner/config.yaml index 7510717..ce8dba8 100644 --- a/mkosi.extra/etc/gitea-runner/config.yaml +++ b/mkosi.extra/etc/gitea-runner/config.yaml @@ -8,6 +8,8 @@ runner: # file is where `gitea-runner register` keeps the registration, wherever it # runs. gitea-runner.path starts the runner once it is there. file: /var/lib/gitea-runner/.runner + # capacity is the number of parallel jobs, set by gitea-runner.service. + capacity: ${CAPACITY} # shutdown_timeout lets running jobs finish when the runner stops, as it # does before an update reboots the machine. shutdown_timeout: 1h diff --git a/mkosi.extra/usr/lib/systemd/system-preset/50-runneros.preset b/mkosi.extra/usr/lib/systemd/system-preset/50-runneros.preset index baa981c..2b3c105 100644 --- a/mkosi.extra/usr/lib/systemd/system-preset/50-runneros.preset +++ b/mkosi.extra/usr/lib/systemd/system-preset/50-runneros.preset @@ -5,7 +5,9 @@ # systemd-networkd is disabled by Fedora, which uses NetworkManager. enable systemd-networkd.service -# gitea-runner.path starts the runner once it is registered. +# gitea-runner-setup.service registers the runner, and gitea-runner.path then +# starts it. +enable gitea-runner-setup.service enable gitea-runner.path disable gitea-runner.service diff --git a/mkosi.extra/usr/lib/systemd/system/gitea-runner-setup.service b/mkosi.extra/usr/lib/systemd/system/gitea-runner-setup.service new file mode 100644 index 0000000..70f9af7 --- /dev/null +++ b/mkosi.extra/usr/lib/systemd/system/gitea-runner-setup.service @@ -0,0 +1,21 @@ +# gitea-runner-setup.service runs /usr/libexec/gitea-runner-setup on the +# console until the runner is registered, after systemd-firstboot has asked +# its questions there. Logins wait for it, as for systemd-firstboot, so no +# getty reads the same console. +[Unit] +Description=Gitea runner setup +ConditionPathExists=!/var/lib/gitea-runner/.runner +Wants=network-online.target +After=systemd-firstboot.service network-online.target +Before=systemd-user-sessions.service + +[Service] +Type=oneshot +# HOME is where gitea-runner keeps its cache, as in gitea-runner.service. +Environment=HOME=/var/lib/gitea-runner +ExecStart=/usr/libexec/gitea-runner-setup +StandardInput=tty +StandardOutput=tty + +[Install] +WantedBy=multi-user.target diff --git a/mkosi.extra/usr/lib/systemd/system/gitea-runner.path b/mkosi.extra/usr/lib/systemd/system/gitea-runner.path index d63b936..40526b9 100644 --- a/mkosi.extra/usr/lib/systemd/system/gitea-runner.path +++ b/mkosi.extra/usr/lib/systemd/system/gitea-runner.path @@ -1,5 +1,5 @@ # gitea-runner.path starts the runner once it is registered, so a new machine -# waits for `gitea-runner -c /etc/gitea-runner/config.yaml register`. +# waits for gitea-runner-setup.service. [Unit] Description=Start the Gitea runner once registered diff --git a/mkosi.extra/usr/lib/systemd/system/gitea-runner.service b/mkosi.extra/usr/lib/systemd/system/gitea-runner.service index f713d0f..084f02f 100644 --- a/mkosi.extra/usr/lib/systemd/system/gitea-runner.service +++ b/mkosi.extra/usr/lib/systemd/system/gitea-runner.service @@ -11,6 +11,9 @@ After=network-online.target podman.socket Requires=podman.socket [Service] +# CAPACITY is the number of parallel jobs. gitea-runner-setup writes a drop-in +# that overrides it, which `systemctl edit gitea-runner` changes. +Environment=CAPACITY=1 # HOME holds the cache of actions/cache, next to the registration. Environment=HOME=/var/lib/gitea-runner Environment=DOCKER_HOST=unix:///run/podman/podman.sock diff --git a/mkosi.extra/usr/libexec/gitea-runner-setup b/mkosi.extra/usr/libexec/gitea-runner-setup new file mode 100755 index 0000000..2a051ca --- /dev/null +++ b/mkosi.extra/usr/libexec/gitea-runner-setup @@ -0,0 +1,24 @@ +#!/bin/bash +# gitea-runner-setup asks on the console for the number of parallel jobs and +# the runner's registration, and registers the runner. gitea-runner.path then +# starts it. gitea-runner-setup.service runs it until the runner is registered. +# +# The capacity goes to a drop-in of gitea-runner.service, which passes it to +# /etc/gitea-runner/config.yaml as CAPACITY. It is written first, because the +# runner starts as soon as it is registered. +set -euo pipefail + +read -rp "Parallel jobs [1]: " capacity +[[ $capacity =~ ^[1-9][0-9]*$ ]] || capacity=1 +mkdir -p /etc/systemd/system/gitea-runner.service.d +printf '[Service]\nEnvironment=CAPACITY=%s\n' "$capacity" \ + > /etc/systemd/system/gitea-runner.service.d/capacity.conf +systemctl daemon-reload + +export CAPACITY=$capacity +until [[ -f /var/lib/gitea-runner/.runner ]]; do + read -rp "Gitea URL: " url + read -rp "Registration token: " token + gitea-runner -c /etc/gitea-runner/config.yaml register --no-interactive \ + --instance "$url" --token "$token" || echo "Try again." +done