From e42782f2f2a545b5ac4c3451266e805eb4384f1f Mon Sep 17 00:00:00 2001 From: kiskaadee Date: Wed, 18 Nov 2026 22:41:43 -0500 Subject: [PATCH 1/4] feat(gitea): mount persistent state under homelab state root --- gitea/docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitea/docker-compose.yml b/gitea/docker-compose.yml index 328a0b0..0dadd3c 100644 --- a/gitea/docker-compose.yml +++ b/gitea/docker-compose.yml @@ -18,7 +18,7 @@ services: ports: - "${SSH_PORT:-2223}:22" volumes: - - ./data:/data + - ~/var/lib/homelab/gitea:/data networks: - proxy-net labels: From d53439954990e667f0042ef07852b99b65a329eb Mon Sep 17 00:00:00 2001 From: kiskaadee Date: Wed, 18 Nov 2026 22:45:02 -0500 Subject: [PATCH 2/4] feat(gitea_runner): configure host-mode Nix runner with persistent store - Add gitea_runner/Dockerfile combining nixos/nix (flakes + nodejs + /bin/sleep) with act_runner binary and entrypoint - Update gitea_runner/docker-compose.yml to build locally, mount ~/var/lib/homelab/gitea_runner:/data and nix-store:/nix, remove DOCKER_HOST, and use :host runner labels - Add compose_build to gitea_runner/app.yaml deployment actions - Document runtime env vars and host-mode architecture in gitea_runner/.env-example and README.md --- gitea_runner/.env-example | 8 ++++++++ gitea_runner/Dockerfile | 22 ++++++++++++++++++++++ gitea_runner/README.md | 19 +++++++++++++++++++ gitea_runner/app.yaml | 1 + gitea_runner/docker-compose.yml | 14 +++++++++----- 5 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 gitea_runner/.env-example create mode 100644 gitea_runner/Dockerfile create mode 100644 gitea_runner/README.md diff --git a/gitea_runner/.env-example b/gitea_runner/.env-example new file mode 100644 index 0000000..815e3a1 --- /dev/null +++ b/gitea_runner/.env-example @@ -0,0 +1,8 @@ +# Gitea Actions Runner environment variables (injected at runtime; never commit real tokens) +GITEA_INSTANCE_URL=http://gitea:3000 +GITEA_RUNNER_TOKEN=replace-with-gitea-runner-registration-token +GITEA_RUNNER_NAME=homelab-runner +GITEA_RUNNER_LABELS=ubuntu-latest:host,nix:host + +# Host state root (default: ~/var/lib/homelab; compose mounts ~/var/lib/homelab/gitea_runner:/data) +HOMELAB_STATE_ROOT=~/var/lib/homelab diff --git a/gitea_runner/Dockerfile b/gitea_runner/Dockerfile new file mode 100644 index 0000000..2343159 --- /dev/null +++ b/gitea_runner/Dockerfile @@ -0,0 +1,22 @@ +FROM gitea/act_runner:latest AS act-runner + +FROM nixos/nix:latest + +# Enable flakes and nix-command for CI workflows +RUN echo "experimental-features = nix-command flakes" >> /etc/nix/nix.conf + +# Install Node.js (required by standard GitHub/Gitea Actions JS actions) +RUN nix-env -iA nixpkgs.nodejs \ + && nix-collect-garbage -d + +# Ensure /bin/sleep exists (required by act_runner init) +RUN mkdir -p /bin \ + && ln -sf "$(command -v sleep)" /bin/sleep + +# Copy static act_runner binary and entrypoint from official image +COPY --from=act-runner /usr/local/bin/act_runner /usr/local/bin/act_runner +COPY --from=act-runner /usr/local/bin/run.sh /usr/local/bin/run.sh + +ENV PATH="/usr/local/bin:/root/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/usr/bin:/bin" + +ENTRYPOINT ["/usr/local/bin/run.sh"] diff --git a/gitea_runner/README.md b/gitea_runner/README.md new file mode 100644 index 0000000..c44b985 --- /dev/null +++ b/gitea_runner/README.md @@ -0,0 +1,19 @@ +# Gitea Actions Runner (`gitea_runner`) + +Standalone `act_runner` for Gitea Actions, built with Nix (`nix-command` and `flakes` enabled), `git`, `bash`, and `nodejs` for **host-mode (`:host`)** execution. + +## Architecture + +- **Host-Mode Execution (`:host`)**: Core platform security bans direct Docker socket mounts and enforces a read-only `socket-proxy` (`POST=0`), so `act_runner` cannot spawn `docker://` job containers. Jobs run directly inside the runner container via `:host` labels (`ubuntu-latest:host,nix:host`). +- **Persistent State & Nix Cache**: + - Runner registration and workspace state: `~/var/lib/homelab/gitea_runner:/data` (under `HOMELAB_STATE_ROOT`, default `~/var/lib/homelab`). + - Nix store cache: named Docker volume `nix-store:/nix` so evaluated derivations persist across rebuilds. + +## Configuration + +See [`.env-example`](.env-example) for required runtime variables: + +- `GITEA_INSTANCE_URL`: Internal or external Gitea URL (default `http://gitea:3000` over `proxy-net`). +- `GITEA_RUNNER_TOKEN`: One-time runner registration token (injected into `GITEA_RUNNER_REGISTRATION_TOKEN` in Compose). +- `GITEA_RUNNER_NAME`: Runner display name (default `homelab-runner`). +- `GITEA_RUNNER_LABELS`: Comma-separated `:host` labels (default `ubuntu-latest:host,nix:host`). diff --git a/gitea_runner/app.yaml b/gitea_runner/app.yaml index 76a786f..3512c01 100644 --- a/gitea_runner/app.yaml +++ b/gitea_runner/app.yaml @@ -14,4 +14,5 @@ deployment: branch: "main" actions: - git_pull + - compose_build - compose_up diff --git a/gitea_runner/docker-compose.yml b/gitea_runner/docker-compose.yml index 87ff5e7..cbc0308 100644 --- a/gitea_runner/docker-compose.yml +++ b/gitea_runner/docker-compose.yml @@ -1,19 +1,23 @@ services: gitea_runner: - image: gitea/act_runner:${ACT_RUNNER_VERSION:-latest} - container_name: ${CONTAINER_NAME:-gitea-runner} + build: . + image: ${RUNNER_IMAGE:-gitea-runner:local} + container_name: ${CONTAINER_NAME:-gitea_runner} restart: unless-stopped environment: - GITEA_INSTANCE_URL=${GITEA_INSTANCE_URL:-http://gitea:3000} - GITEA_RUNNER_REGISTRATION_TOKEN=${GITEA_RUNNER_TOKEN:-} - GITEA_RUNNER_NAME=${GITEA_RUNNER_NAME:-homelab-runner} - - GITEA_RUNNER_LABELS=${GITEA_RUNNER_LABELS:-ubuntu-latest:docker://ghcr.io/catthehacker/ubuntu:act-latest,ubuntu-22.04:docker://ghcr.io/catthehacker/ubuntu:act-latest} - - DOCKER_HOST=${DOCKER_HOST:-tcp://docker-socket-proxy:2375} + - GITEA_RUNNER_LABELS=${GITEA_RUNNER_LABELS:-ubuntu-latest:host,nix:host} volumes: - - ./data:/data + - ~/var/lib/homelab/gitea_runner:/data + - nix-store:/nix networks: - proxy-net +volumes: + nix-store: {} + networks: proxy-net: name: ${PROXY_NETWORK:-proxy-net} From 45a9450526c8d524cc8d691ebbf31ac98496c0e0 Mon Sep 17 00:00:00 2001 From: kiskaadee Date: Wed, 18 Nov 2026 23:03:22 -0500 Subject: [PATCH 3/4] fix(gitea,gitea_runner): use relative state mounts and nix-independent runner base - Replace ~/var/lib/homelab/ with ../../var/lib/homelab/ in gitea and gitea_runner compose files so docker compose resolves state without HOME - Remove inert HOMELAB_STATE_ROOT from gitea_runner/.env-example and update gitea_runner/README.md - Rebase gitea_runner/Dockerfile on gitea/act_runner:latest with Alpine nodejs/git/bash/coreutils, regular-file /etc/nix/nix.conf, pinned nixos/nix:2.24.12 store, and entrypoint-nix.sh auto-seed wrapper --- gitea/docker-compose.yml | 2 +- gitea_runner/.env-example | 3 --- gitea_runner/Dockerfile | 33 +++++++++++++++++---------------- gitea_runner/README.md | 4 ++-- gitea_runner/docker-compose.yml | 2 +- gitea_runner/entrypoint-nix.sh | 9 +++++++++ 6 files changed, 30 insertions(+), 23 deletions(-) create mode 100644 gitea_runner/entrypoint-nix.sh diff --git a/gitea/docker-compose.yml b/gitea/docker-compose.yml index 0dadd3c..7b7a8b6 100644 --- a/gitea/docker-compose.yml +++ b/gitea/docker-compose.yml @@ -18,7 +18,7 @@ services: ports: - "${SSH_PORT:-2223}:22" volumes: - - ~/var/lib/homelab/gitea:/data + - ../../var/lib/homelab/gitea:/data networks: - proxy-net labels: diff --git a/gitea_runner/.env-example b/gitea_runner/.env-example index 815e3a1..20e69bb 100644 --- a/gitea_runner/.env-example +++ b/gitea_runner/.env-example @@ -3,6 +3,3 @@ GITEA_INSTANCE_URL=http://gitea:3000 GITEA_RUNNER_TOKEN=replace-with-gitea-runner-registration-token GITEA_RUNNER_NAME=homelab-runner GITEA_RUNNER_LABELS=ubuntu-latest:host,nix:host - -# Host state root (default: ~/var/lib/homelab; compose mounts ~/var/lib/homelab/gitea_runner:/data) -HOMELAB_STATE_ROOT=~/var/lib/homelab diff --git a/gitea_runner/Dockerfile b/gitea_runner/Dockerfile index 2343159..1ca9551 100644 --- a/gitea_runner/Dockerfile +++ b/gitea_runner/Dockerfile @@ -1,22 +1,23 @@ -FROM gitea/act_runner:latest AS act-runner +FROM nixos/nix:2.24.12 AS nix-src +RUN tar -czf /nix-seed.tar.gz -C /nix . -FROM nixos/nix:latest +FROM gitea/act_runner:latest -# Enable flakes and nix-command for CI workflows -RUN echo "experimental-features = nix-command flakes" >> /etc/nix/nix.conf +RUN apk add --no-cache nodejs npm bash git coreutils ca-certificates -# Install Node.js (required by standard GitHub/Gitea Actions JS actions) -RUN nix-env -iA nixpkgs.nodejs \ - && nix-collect-garbage -d +# Regular file (never a symlink into /nix/store) so nix-store volume mounts cannot break it +RUN mkdir -p /etc/nix /nix && \ + printf '%s\n' \ + 'sandbox = false' \ + 'experimental-features = nix-command flakes' \ + 'trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=' \ + > /etc/nix/nix.conf -# Ensure /bin/sleep exists (required by act_runner init) -RUN mkdir -p /bin \ - && ln -sf "$(command -v sleep)" /bin/sleep +COPY --from=nix-src /nix /nix +COPY --from=nix-src /nix-seed.tar.gz /opt/nix-seed.tar.gz +COPY entrypoint-nix.sh /usr/local/bin/entrypoint-nix.sh +RUN chmod +x /usr/local/bin/entrypoint-nix.sh -# Copy static act_runner binary and entrypoint from official image -COPY --from=act-runner /usr/local/bin/act_runner /usr/local/bin/act_runner -COPY --from=act-runner /usr/local/bin/run.sh /usr/local/bin/run.sh +ENV PATH="/usr/local/bin:/nix/var/nix/profiles/default/bin:/usr/bin:/bin" -ENV PATH="/usr/local/bin:/root/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/usr/bin:/bin" - -ENTRYPOINT ["/usr/local/bin/run.sh"] +ENTRYPOINT ["/usr/local/bin/entrypoint-nix.sh"] diff --git a/gitea_runner/README.md b/gitea_runner/README.md index c44b985..d46deff 100644 --- a/gitea_runner/README.md +++ b/gitea_runner/README.md @@ -6,8 +6,8 @@ Standalone `act_runner` for Gitea Actions, built with Nix (`nix-command` and `fl - **Host-Mode Execution (`:host`)**: Core platform security bans direct Docker socket mounts and enforces a read-only `socket-proxy` (`POST=0`), so `act_runner` cannot spawn `docker://` job containers. Jobs run directly inside the runner container via `:host` labels (`ubuntu-latest:host,nix:host`). - **Persistent State & Nix Cache**: - - Runner registration and workspace state: `~/var/lib/homelab/gitea_runner:/data` (under `HOMELAB_STATE_ROOT`, default `~/var/lib/homelab`). - - Nix store cache: named Docker volume `nix-store:/nix` so evaluated derivations persist across rebuilds. + - Runner registration and workspace state: `../../var/lib/homelab/gitea_runner:/data` (resolves relative to `~/Workloads/gitea_runner` to `~/var/lib/homelab/gitea_runner` without requiring `HOME` or `${...}` interpolation). + - Nix store cache: named Docker volume `nix-store:/nix` so evaluated derivations persist across rebuilds. If `/nix/var/nix/profiles/default/bin/nix` is missing or broken on an existing volume, `entrypoint-nix.sh` seeds `/nix` from `/opt/nix-seed.tar.gz`. ## Configuration diff --git a/gitea_runner/docker-compose.yml b/gitea_runner/docker-compose.yml index cbc0308..8ce3986 100644 --- a/gitea_runner/docker-compose.yml +++ b/gitea_runner/docker-compose.yml @@ -10,7 +10,7 @@ services: - GITEA_RUNNER_NAME=${GITEA_RUNNER_NAME:-homelab-runner} - GITEA_RUNNER_LABELS=${GITEA_RUNNER_LABELS:-ubuntu-latest:host,nix:host} volumes: - - ~/var/lib/homelab/gitea_runner:/data + - ../../var/lib/homelab/gitea_runner:/data - nix-store:/nix networks: - proxy-net diff --git a/gitea_runner/entrypoint-nix.sh b/gitea_runner/entrypoint-nix.sh new file mode 100644 index 0000000..c65fd95 --- /dev/null +++ b/gitea_runner/entrypoint-nix.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +set -euo pipefail + +if [ ! -x /nix/var/nix/profiles/default/bin/nix ] || ! /nix/var/nix/profiles/default/bin/nix --version >/dev/null 2>&1; then + echo "[entrypoint-nix] /nix/var/nix/profiles/default/bin/nix missing or broken; seeding /nix from /opt/nix-seed.tar.gz..." >&2 + tar -xzf /opt/nix-seed.tar.gz -C /nix +fi + +exec /usr/local/bin/run.sh "$@" From 75f2149275ce4d4971bbf0331a0b99e218f5965d Mon Sep 17 00:00:00 2001 From: kiskaadee Date: Thu, 19 Nov 2026 00:18:13 -0500 Subject: [PATCH 4/4] fix(gitea_runner): pin act_runner 0.6.1 and wrap entrypoint with tini --- gitea_runner/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gitea_runner/Dockerfile b/gitea_runner/Dockerfile index 1ca9551..b7cbcd5 100644 --- a/gitea_runner/Dockerfile +++ b/gitea_runner/Dockerfile @@ -1,7 +1,7 @@ FROM nixos/nix:2.24.12 AS nix-src RUN tar -czf /nix-seed.tar.gz -C /nix . -FROM gitea/act_runner:latest +FROM gitea/act_runner:0.6.1 RUN apk add --no-cache nodejs npm bash git coreutils ca-certificates @@ -20,4 +20,4 @@ RUN chmod +x /usr/local/bin/entrypoint-nix.sh ENV PATH="/usr/local/bin:/nix/var/nix/profiles/default/bin:/usr/bin:/bin" -ENTRYPOINT ["/usr/local/bin/entrypoint-nix.sh"] +ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/entrypoint-nix.sh"]