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.
This commit is contained in:
2026-11-03 23:02:39 -08:00
parent c13ac12d97
commit 089355708f
+78
View File
@@ -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