The tracker now runs on stppriv behind Cloudflare Access. The userscript points at priv.adam-french.co.uk and migrates a saved www base, since www only 301s now (which drops a POST). CI publishes the image but no longer rolls stpvm's stack; stppriv is deployed by hand. Merge only at cutover, once priv.adam-french.co.uk/jobs/ is live. Co-Authored-By: Claude Opus 5.5 <[email protected]>
122 lines
5.3 KiB
YAML
122 lines
5.3 KiB
YAML
# =============================================================================
|
|
# ci.yaml — test every push; publish an image for pushes to main that pass.
|
|
#
|
|
# Same runner and the same constraints as web_server's deploy.yaml: a
|
|
# self-hosted act_runner on the web_server host (stpvm) in HOST mode, with git and docker and no
|
|
# other toolchain. So Go and Node run in `docker run` containers, and the
|
|
# source is fetched with plain git rather than actions/checkout (which needs
|
|
# Node on the host).
|
|
#
|
|
# TWO JOBS
|
|
# test go vet + go test, and a vite build of web/. The same checks as
|
|
# `make check`.
|
|
# publish main only, after test: builds the image and pushes it to this
|
|
# Gitea's container registry as :<sha> and :latest. It does NOT
|
|
# deploy: the tracker runs on stppriv, which is deployed by hand
|
|
# (`docker compose pull jobs && docker compose up -d jobs` in
|
|
# ~/deploy/stppriv). The runner lives on stpvm and only deploys
|
|
# stpvm.
|
|
#
|
|
# SECRETS (repo settings -> Actions -> Secrets)
|
|
# REGISTRY_USER a Gitea user that can write packages for adamf
|
|
# REGISTRY_TOKEN that user's access token with the write:package scope
|
|
# =============================================================================
|
|
name: Test and publish
|
|
|
|
on:
|
|
push:
|
|
|
|
env:
|
|
IMAGE: adam-french.co.uk/adamf/job-tracker
|
|
|
|
jobs:
|
|
test:
|
|
runs-on: self-hosted
|
|
env:
|
|
SHA: ${{ github.sha }}
|
|
REF: ${{ github.ref }}
|
|
REMOTE: ssh://[email protected]:2222/adamf/job-tracker.git
|
|
GIT_SSH_COMMAND: "ssh -o StrictHostKeyChecking=no"
|
|
CACHE: /home/adamf/.cache/job-tracker-ci/repo.git
|
|
SRC: /home/adamf/.cache/job-tracker-ci/src-${{ github.sha }}
|
|
steps:
|
|
- name: Export the pushed commit to a scratch directory
|
|
shell: bash
|
|
run: |
|
|
set -eu
|
|
mkdir -p "$(dirname "$CACHE")"
|
|
[ -d "$CACHE" ] || git init --quiet --bare "$CACHE"
|
|
git --git-dir="$CACHE" fetch --quiet --no-tags "$REMOTE" "$REF"
|
|
rm -rf "$SRC"
|
|
mkdir -p "$SRC"
|
|
git --git-dir="$CACHE" archive --format=tar "$SHA" | tar -x -C "$SRC"
|
|
test -f "$SRC/go.mod"
|
|
|
|
# Read-only source, and named volumes for the module and build
|
|
# caches, for the reasons given in web_server's deploy.yaml.
|
|
- name: Go - vet and test
|
|
shell: bash
|
|
run: |
|
|
set -eu
|
|
docker run --rm \
|
|
-v "$SRC":/src:ro -w /src \
|
|
-v job_tracker_ci_gomod:/go/pkg/mod \
|
|
-v job_tracker_ci_gobuild:/root/.cache/go-build \
|
|
golang:1.26 \
|
|
sh -c 'go vet ./... && go test ./...'
|
|
|
|
# Built in the container's own copy: node_modules and dist must not
|
|
# be written into $SRC, which is mounted read-only.
|
|
- name: Web - vite build
|
|
shell: bash
|
|
run: |
|
|
set -eu
|
|
docker run --rm \
|
|
-v "$SRC/web":/src:ro \
|
|
-v job_tracker_ci_npm:/root/.npm \
|
|
node:22-alpine \
|
|
sh -c 'cp -r /src /build && cd /build && npm ci --no-audit --no-fund && npx vite build'
|
|
|
|
- name: Remove the scratch directory
|
|
if: always()
|
|
shell: bash
|
|
run: rm -rf "$SRC"
|
|
|
|
publish:
|
|
needs: test
|
|
if: github.ref == 'refs/heads/main'
|
|
runs-on: self-hosted
|
|
env:
|
|
SHA: ${{ github.sha }}
|
|
REMOTE: ssh://[email protected]:2222/adamf/job-tracker.git
|
|
GIT_SSH_COMMAND: "ssh -o StrictHostKeyChecking=no"
|
|
CACHE: /home/adamf/.cache/job-tracker-ci/repo.git
|
|
SRC: /home/adamf/.cache/job-tracker-ci/publish-${{ github.sha }}
|
|
REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
|
|
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
|
# The Dockerfile's `RUN --mount=type=cache` lines need BuildKit.
|
|
# It is the default from Docker 23 (the host runs 29); this was
|
|
# needed on the Pi's Docker 20.10, whose plain `docker build` used
|
|
# the legacy builder, and is kept for any older daemon. This switches on the BuildKit
|
|
# built into the daemon. (Compose builds through buildx, which is
|
|
# why web_server's images build without it.)
|
|
DOCKER_BUILDKIT: "1"
|
|
steps:
|
|
- name: Build and push the image
|
|
shell: bash
|
|
run: |
|
|
set -eu
|
|
rm -rf "$SRC" && mkdir -p "$SRC"
|
|
git --git-dir="$CACHE" archive --format=tar "$SHA" | tar -x -C "$SRC"
|
|
printf '%s' "$REGISTRY_TOKEN" | docker login adam-french.co.uk -u "$REGISTRY_USER" --password-stdin
|
|
# Built natively on the host, so the image is amd64 — the only
|
|
# platform it runs on.
|
|
docker build -t "$IMAGE:$SHA" -t "$IMAGE:latest" "$SRC"
|
|
docker push "$IMAGE:$SHA"
|
|
docker push "$IMAGE:latest"
|
|
|
|
- name: Remove the scratch directory
|
|
if: always()
|
|
shell: bash
|
|
run: rm -rf "$SRC"
|