From db512f76331ce860d4412f844fe31f214bc1915e Mon Sep 17 00:00:00 2001 From: Florian Date: Sun, 18 Oct 2026 17:27:06 +0200 Subject: [PATCH] Initialcommit --- .../workflows/gitea-runner-release-local.yaml | 72 +++++++++++++++++++ .gitignore | 2 + Makefile | 34 +++++++++ pkg/DEBIAN/control | 14 ++++ pkg/DEBIAN/postinst | 35 +++++++++ pkg/DEBIAN/postrm | 22 ++++++ pkg/DEBIAN/prerm | 12 ++++ pkg/usr/lib/systemd/system/act_runner.service | 21 ++++++ 8 files changed, 212 insertions(+) create mode 100644 .gitea/workflows/gitea-runner-release-local.yaml create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 pkg/DEBIAN/control create mode 100755 pkg/DEBIAN/postinst create mode 100755 pkg/DEBIAN/postrm create mode 100755 pkg/DEBIAN/prerm create mode 100644 pkg/usr/lib/systemd/system/act_runner.service diff --git a/.gitea/workflows/gitea-runner-release-local.yaml b/.gitea/workflows/gitea-runner-release-local.yaml new file mode 100644 index 0000000..8b5f0eb --- /dev/null +++ b/.gitea/workflows/gitea-runner-release-local.yaml @@ -0,0 +1,72 @@ +name: Build and publish gitea-runner via local runner + +on: + workflow_dispatch: + inputs: + version: + description: "Upstream version, without the v (e.g. 5.1.1)" + required: true + type: string + revision: + description: "Packaging revision" + required: false + default: "1" + type: string + +env: + DISTRIBUTION: any + COMPONENT: main + +jobs: + build-and-publish: + runs-on: ubuntu-latest + steps: + - name: Validate inputs + env: + VERSION: ${{ inputs.version }} + REVISION: ${{ inputs.revision }} + run: | + # Inputs may come from an external service, so never trust them blindly + echo "$VERSION" | grep -Eq '^[0-9]+(\.[0-9]+)*$' || { echo "Bad version"; exit 1; } + echo "$REVISION" | grep -Eq '^[0-9]+$' || { echo "Bad revision"; exit 1; } + + - uses: actions/checkout@v4 + + - name: Install build tools + run: | + if ! command -v make >/dev/null || ! command -v curl >/dev/null; then + apt-get update && apt-get install -y make curl + fi + + - name: Build package + env: + VERSION: ${{ inputs.version }} + REVISION: ${{ inputs.revision }} + run: make VERSION="$VERSION" REVISION="$REVISION" + + - name: Publish to Gitea package registry + env: + VERSION: ${{ inputs.version }} + REVISION: ${{ inputs.revision }} + UPLOADER: ${{ secrets.PACKAGE_UPLOAD_USERNAME }} + TOKEN: ${{ secrets.PACKAGE_UPLOAD_TOKEN }} + OWNER: ${{ GITHUB_REPOSITORY_OWNER }} + SERVER: ${{ GITHUB_SERVER_URL }} + run: | + DEB="build/gitea-runner_${VERSION}-${REVISION}_amd64.deb" + CODE=$(curl -sS -o /tmp/resp -w '%{http_code}' \ + --user "${UPLOADER}:${TOKEN}" \ + --upload-file "$DEB" \ + "${SERVER}/api/packages/${OWNER}/debian/pool/${DISTRIBUTION}/${COMPONENT}/upload") + cat /tmp/resp; echo + case "$CODE" in + 201) echo "Published $DEB" ;; + 409) echo "This version/revision already exists; bump REVISION"; exit 1 ;; + *) echo "Upload failed with HTTP $CODE"; exit 1 ;; + esac + + - name: Keep the .deb as a workflow artifact + uses: actions/upload-artifact@v3 + with: + name: gitea-runner-deb + path: build/*.deb \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e64e617 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +build/ +cache/ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5c663ef --- /dev/null +++ b/Makefile @@ -0,0 +1,34 @@ +VERSION ?= 5.1.1 +REVISION ?= 1 + +NAME := gitea-runner-$(VERSION)-linux-amd64 +BASE := https://gitea.com/gitea/runner/releases/download/v$(VERSION) +PKG := gitea-runner_$(VERSION)-$(REVISION)_amd64 +STAGE := build/$(PKG) +BIN := cache/$(NAME) +SUMS := cache/checksums-$(VERSION).txt + +.PHONY: deb clean +deb: build/$(PKG).deb + +$(SUMS): + mkdir -p cache + curl -fsSL -o $@ $(BASE)/checksums.txt + +$(BIN): $(SUMS) + curl -fsSL -o $@ $(BASE)/$(NAME) + cd cache && grep -E '[ *]$(NAME)$$' checksums-$(VERSION).txt | sha256sum -c - \ + || { rm -f $(NAME); echo "Checksum verification failed" >&2; exit 1; } + +build/$(PKG).deb: $(BIN) $(shell find pkg -type f) + rm -rf $(STAGE) + mkdir -p $(STAGE) + cp -a pkg/. $(STAGE)/ + install -D -m 0755 $(BIN) $(STAGE)/usr/bin/gitea-runner + sed -i -e 's|@VERSION@|$(VERSION)|' -e 's|@REVISION@|$(REVISION)|' \ + $(STAGE)/DEBIAN/control + chmod 0755 $(STAGE)/DEBIAN/postinst $(STAGE)/DEBIAN/prerm $(STAGE)/DEBIAN/postrm + dpkg-deb --root-owner-group --build $(STAGE) $@ + +clean: + rm -rf build \ No newline at end of file diff --git a/pkg/DEBIAN/control b/pkg/DEBIAN/control new file mode 100644 index 0000000..c6c3531 --- /dev/null +++ b/pkg/DEBIAN/control @@ -0,0 +1,14 @@ +Package: gitea-runner +Version: @VERSION@-@REVISION@ +Architecture: amd64 +Maintainer: Florian@gansejunge.com +Section: devel +Priority: optional +Depends: adduser +Recommends: docker.io | docker-ce +Homepage: https://gitea.com/gitea/runner +Description: Runner for Gitea Actions + gitea-runner executes Gitea Actions workflow jobs, usually inside Docker + containers. It runs as the unprivileged gitea-runner user, with state in + /var/lib/gitea-runner and configuration in /etc/gitea-runner. + \ No newline at end of file diff --git a/pkg/DEBIAN/postinst b/pkg/DEBIAN/postinst new file mode 100755 index 0000000..08c6e9a --- /dev/null +++ b/pkg/DEBIAN/postinst @@ -0,0 +1,35 @@ +#!/bin/sh +set -e + +case "$1" in +configure) + if ! getent passwd gitea-runner >/dev/null; then + adduser --system --group --no-create-home \ + --home /var/lib/gitea-runner --shell /usr/sbin/nologin \ + --gecos "Gitea Actions runner" gitea-runner + fi + + install -d -o gitea-runner -g gitea-runner -m 0750 /var/lib/gitea-runner + install -d -o root -g gitea-runner -m 0750 /etc/gitea-runner + + if [ ! -e /etc/gitea-runner/config.yaml ]; then + /usr/bin/gitea-runner generate-config > /etc/gitea-runner/config.yaml + chown root:gitea-runner /etc/gitea-runner/config.yaml + chmod 0640 /etc/gitea-runner/config.yaml + fi + + if getent group docker >/dev/null; then + adduser --quiet gitea-runner docker || true + fi + + if [ -d /run/systemd/system ]; then + systemctl daemon-reload || true + systemctl enable gitea-runner.service >/dev/null 2>&1 || true + if systemctl is-active --quiet gitea-runner.service; then + systemctl restart gitea-runner.service || true + fi + fi + ;; +esac + +exit 0 diff --git a/pkg/DEBIAN/postrm b/pkg/DEBIAN/postrm new file mode 100755 index 0000000..00ec713 --- /dev/null +++ b/pkg/DEBIAN/postrm @@ -0,0 +1,22 @@ +#!/bin/sh +set -e + +case "$1" in +remove) + if [ -d /run/systemd/system ]; then + systemctl disable gitea-runner.service >/dev/null 2>&1 || true + systemctl daemon-reload || true + fi + ;; +purge) + rm -rf /etc/gitea-runner /var/lib/gitea-runner + if getent passwd gitea-runner >/dev/null; then + deluser --quiet --system gitea-runner || true + fi + if getent group gitea-runner >/dev/null; then + delgroup --quiet --system gitea-runner || true + fi + ;; +esac + +exit 0 diff --git a/pkg/DEBIAN/prerm b/pkg/DEBIAN/prerm new file mode 100755 index 0000000..3e62a91 --- /dev/null +++ b/pkg/DEBIAN/prerm @@ -0,0 +1,12 @@ +#!/bin/sh +set -e + +case "$1" in +remove|deconfigure) + if [ -d /run/systemd/system ]; then + systemctl stop gitea-runner.service || true + fi + ;; +esac + +exit 0 diff --git a/pkg/usr/lib/systemd/system/act_runner.service b/pkg/usr/lib/systemd/system/act_runner.service new file mode 100644 index 0000000..589ca73 --- /dev/null +++ b/pkg/usr/lib/systemd/system/act_runner.service @@ -0,0 +1,21 @@ +[Unit] +Description=Gitea Actions runner (gitea-runner) +Documentation=https://gitea.com/gitea/gitea-runner +After=network-online.target docker.service +Wants=network-online.target +ConditionPathExists=/var/lib/gitea-runner/.runner + +[Service] +Type=simple +User=gitea-runner +Group=gitea-runner +WorkingDirectory=/var/lib/gitea-runner +StateDirectory=gitea-runner +Environment=HOME=/var/lib/gitea-runner +ExecStart=/usr/bin/gitea-runner daemon --config /etc/gitea-runner/config.yaml +Restart=on-failure +RestartSec=10 +TimeoutSec=0 + +[Install] +WantedBy=multi-user.target