diff --git a/.gitea/workflows/os.yml b/.gitea/workflows/os.yml index c57be0c..84bf52e 100644 --- a/.gitea/workflows/os.yml +++ b/.gitea/workflows/os.yml @@ -35,24 +35,20 @@ jobs: release=$(curl -fsS -H "$AUTH" "$API/tags/latest") || release=$(curl -fsS -H "$AUTH" -H 'Content-Type: application/json' "$API" -d '{"tag_name": "latest", "name": "latest"}') echo "RELEASE=$API/$(jq .id <<<"$release")" >> "$GITHUB_ENV" - # Uploads the update, then replaces SHA256SUMS, which tells runners it is there. + # Uploads the update, then replaces SHA256SUMS, which tells runners it is there, then removes + # older versions. - name: Publish the update working-directory: mkosi.output run: | - for f in $(awk '{print $2}' SHA256SUMS); do curl -fsS -o /dev/null -H "$AUTH" -F "attachment=@$f" "$RELEASE/assets?name=$f"; done - old=$(curl -fsS -H "$AUTH" "$RELEASE/assets" | jq '.[] | select(.name == "SHA256SUMS") | .id') - [ -z "$old" ] || curl -fsS -H "$AUTH" -X DELETE "$RELEASE/assets/$old" - curl -fsS -o /dev/null -H "$AUTH" -F attachment=@SHA256SUMS "$RELEASE/assets?name=SHA256SUMS" - - name: Remove older versions - working-directory: mkosi.output - run: | - curl -fsS -H "$AUTH" "$RELEASE/assets" | jq -r '.[] | "\(.id) \(.name)"' | grep ' git-runner_' | - grep -vFf <(awk '{print " " $2}' SHA256SUMS) | while read -r id name; do curl -fsS -H "$AUTH" -X DELETE "$RELEASE/assets/$id"; done - - name: Publish the disk image - if: github.event_name != 'push' - working-directory: mkosi.output - run: | - qemu-img convert -c -O qcow2 "$(basename git-runner_*.efi .efi).raw" git-runner.qcow2 - old=$(curl -fsS -H "$AUTH" "$RELEASE/assets" | jq '.[] | select(.name == "git-runner.qcow2") | .id') - [ -z "$old" ] || curl -fsS -H "$AUTH" -X DELETE "$RELEASE/assets/$old" - curl -fsS -o /dev/null -H "$AUTH" -F attachment=@git-runner.qcow2 "$RELEASE/assets?name=git-runner.qcow2" + assets() { curl -fsS -H "$AUTH" "$RELEASE/assets" | jq -r '.[] | "\(.id) \(.name)"'; } + upload() { curl -fsS -o /dev/null -H "$AUTH" -F "attachment=@$1" "$RELEASE/assets?name=$1"; } + delete() { while read -r id _; do curl -fsS -H "$AUTH" -X DELETE "$RELEASE/assets/$id"; done; } + for f in $(awk '{print $2}' SHA256SUMS); do upload "$f"; done + assets | awk '$2 == "SHA256SUMS"' | delete + upload SHA256SUMS + assets | awk 'NR == FNR { keep[$2]; next } $2 ~ /^git-runner_/ && !($2 in keep)' SHA256SUMS - | delete + if [ "${{ github.event_name }}" != push ]; then + qemu-img convert -c -O qcow2 "$(basename git-runner_*.efi .efi).raw" git-runner.qcow2 + assets | awk '$2 == "git-runner.qcow2"' | delete + upload git-runner.qcow2 + fi diff --git a/mkosi.extra/usr/lib/systemd/system/gitea-runner.service b/mkosi.extra/usr/lib/systemd/system/gitea-runner.service index d7dc9dd..2a60c12 100644 --- a/mkosi.extra/usr/lib/systemd/system/gitea-runner.service +++ b/mkosi.extra/usr/lib/systemd/system/gitea-runner.service @@ -7,14 +7,13 @@ After=network-online.target podman.socket gitea-runner-images.service gitea-runn Requires=podman.socket [Service] -# The runner drives root's podman (podman.socket.d gives this user the socket). The jobs it starts -# never get the socket (see config.yaml). -User=gitea-runner +# Runs as root: it drives root's podman, which is root access anyway. The jobs it starts never +# get the socket (see config.yaml). WorkingDirectory=/var/lib/gitea-runner EnvironmentFile=/var/lib/gitea-runner/runner.env Environment=DOCKER_HOST=unix:///run/podman/podman.sock -# The hostname is the runner's name. /etc is read-only, so it is set on every start (as root: +). -ExecStartPre=+/usr/bin/hostnamectl hostname --transient ${GITEA_RUNNER_NAME} +# The hostname is the runner's name. /etc is read-only, so it is set on every start. +ExecStartPre=/usr/bin/hostnamectl hostname --transient ${GITEA_RUNNER_NAME} # Register once; the result is kept in .runner. ExecStartPre=/bin/sh -c '[ -f .runner ] || exec gitea-runner register --no-interactive --config /usr/lib/gitea-runner/config.yaml --instance "$GITEA_INSTANCE_URL"' ExecStart=/usr/bin/gitea-runner daemon --config /usr/lib/gitea-runner/config.yaml diff --git a/mkosi.extra/usr/lib/systemd/system/podman.socket.d/gitea-runner.conf b/mkosi.extra/usr/lib/systemd/system/podman.socket.d/gitea-runner.conf deleted file mode 100644 index 0a8f905..0000000 --- a/mkosi.extra/usr/lib/systemd/system/podman.socket.d/gitea-runner.conf +++ /dev/null @@ -1,4 +0,0 @@ -# The runner may use root's podman. Jobs never get this socket. -[Socket] -SocketGroup=gitea-runner -SocketMode=0660 diff --git a/mkosi.extra/usr/lib/sysusers.d/gitea-runner.conf b/mkosi.extra/usr/lib/sysusers.d/gitea-runner.conf deleted file mode 100644 index 206cc7a..0000000 --- a/mkosi.extra/usr/lib/sysusers.d/gitea-runner.conf +++ /dev/null @@ -1,2 +0,0 @@ -# The runner's user. -u gitea-runner - "Gitea Actions runner" /var/lib/gitea-runner diff --git a/mkosi.extra/usr/lib/tmpfiles.d/gitea-runner.conf b/mkosi.extra/usr/lib/tmpfiles.d/gitea-runner.conf index fc31181..1d90729 100644 --- a/mkosi.extra/usr/lib/tmpfiles.d/gitea-runner.conf +++ b/mkosi.extra/usr/lib/tmpfiles.d/gitea-runner.conf @@ -1,9 +1,6 @@ # The runner's directories, and a clean container storage on every boot. -# Home directory; holds the registration (.runner) and the actions cache. -d /var/lib/gitea-runner 0700 gitea-runner gitea-runner - -# podman's own line makes this 0700; the runner needs to reach podman.sock inside (podman.socket.d). -# This file sorts before podman.conf, so its line wins. -D! /run/podman 0750 root gitea-runner - +# State: holds the registration (.runner) and the actions cache. +d /var/lib/gitea-runner 0700 root root - # Wipe all job containers, volumes and images on every boot. The shared base images # (/var/lib/containers/base-images) stay; gitea-runner-images.service updates them. R /var/lib/containers/storage diff --git a/mkosi.extra/usr/libexec/gitea-runner-setup b/mkosi.extra/usr/libexec/gitea-runner-setup index 960f39d..6dda22b 100755 --- a/mkosi.extra/usr/libexec/gitea-runner-setup +++ b/mkosi.extra/usr/libexec/gitea-runner-setup @@ -21,7 +21,7 @@ read -rp "Gitea URL (e.g. https://gitea.example.com): " url read -rp "Runner registration token: " token read -rp "Parallel jobs [1]: " capacity [[ $capacity =~ ^[1-9][0-9]*$ ]] || capacity=1 -install -D -m 0640 -g gitea-runner /dev/stdin /var/lib/gitea-runner/runner.env <