From 089355708ffc9e84b6c72d72f251b4545d0b988d Mon Sep 17 00:00:00 2001 From: David Gwilliam Date: Tue, 3 Nov 2026 23:02:39 -0800 Subject: [PATCH] ci: build the image on the host daemon via the runner socket (#8) Builds on dhg.lol's daemon (the runner whitelists /var/run/docker.sock and /apps), tags :latest plus the commit SHA, and restarts the compose stack only when apps/knox is already installed. No registry credentials: the registry requires htpasswd auth and self-built apps are consumed with pull_policy never. --- .gitea/workflows/build.yml | 78 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 .gitea/workflows/build.yml diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml new file mode 100644 index 0000000..5560f0a --- /dev/null +++ b/.gitea/workflows/build.yml @@ -0,0 +1,78 @@ +name: build + +# Build the knox image on the dhg.lol daemon through the runner's docker socket. +# +# The registry on the host requires htpasswd auth, and the established pattern +# for self-built apps here is a locally-tagged image consumed with +# `pull_policy: never` (see apps/plant-dashboard). Building against the host +# daemon keeps that contract and means a knox change needs no registry +# credentials at all. +# +# Deployment stays with tf-net: this workflow only makes the new image available +# and restarts the stack when the app is already installed. + +on: + push: + paths: + - "**/*.go" + - "go.mod" + - "go.sum" + - "Dockerfile" + - ".dockerignore" + - ".gitea/workflows/build.yml" + workflow_dispatch: + +concurrency: + group: knox-build + cancel-in-progress: true + +jobs: + test: + runs-on: ubuntu-latest + container: + image: golang:1.27-alpine + steps: + - uses: actions/checkout@v4 + - run: go vet ./... && go test ./... + + image: + needs: test + runs-on: ubuntu-latest + container: + image: docker:27-cli + # Whitelisted in the runner config (valid_volumes): the host daemon and + # the CasaOS app directory where compose files live. + volumes: + - /var/run/docker.sock:/var/run/docker.sock + - /apps:/apps + env: + IMAGE: docker.notsosm.art/knox + steps: + - uses: actions/checkout@v4 + + - name: Build image on the host daemon + run: | + set -eu + # .git is present in the checkout, so the binary records the commit + # it was built from (`knox --version`). + docker build \ + --label "org.opencontainers.image.revision=${{ github.sha }}" \ + -t "$IMAGE:latest" \ + -t "$IMAGE:${GITHUB_SHA}" \ + . + docker run --rm "$IMAGE:latest" --version + + - name: Restart the app if it is installed + run: | + set -eu + if [ ! -f /apps/knox/docker-compose.yml ]; then + echo "apps/knox is not installed yet; image built, skipping restart" + exit 0 + fi + if ! docker compose version >/dev/null 2>&1; then + echo "compose plugin unavailable in this image; restart deferred to tf-net" + exit 0 + fi + cd /apps/knox + docker compose up -d + docker compose ps