Compare commits

3 Commits
Author SHA1 Message Date
adamfandClaude Opus 5.5 a5fabc02d6 CI: scratch directories per run, not per commit
Test and publish / test (push) Successful in 22s
Test and publish / publish (push) Successful in 25s
Test and publish / deploy (push) Successful in 0s
The build runner takes two jobs at once, so the same commit pushed to
two branches (main and a feature branch) ran its test job twice in
parallel against one src-<sha> directory, and each run's clean-up
deleted the other's source mid-test. Suffix the scratch directories
(and activity-tracker's throwaway Postgres and network) with the run id.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-26 16:14:44 +00:00
adamfandClaude Opus 5.5 0c54e01106 CI: test and publish on the build VM, deploy on stpvm
Test and publish / test (push) Successful in 2m42s
Test and publish / deploy (push) Successful in 12s
Test and publish / publish (push) Successful in 54s
test and publish move to stpbuild's runner (label `build`); rolling the
image out becomes its own deploy job on stpvm (`self-hosted`), the only
host with the stack. The fetch is over HTTP with the job's own
GITEA_TOKEN, so the build VM needs no SSH key or Gitea user.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-26 16:00:13 +00:00
adamfandClaude Opus 5.5 1dad3583b1 CI: roll out into /home/adamf/deploy/stpweb
Test and publish / test (push) Successful in 19s
Test and publish / publish (push) Successful in 31s
The site's deploy directory moved from web_server to stpweb with the repo
rename, so the publish job's roll-out step failed after pushing the image.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-26 15:19:17 +00:00
2 changed files with 44 additions and 27 deletions
+43 -26
View File
@@ -1,21 +1,23 @@
# ============================================================================= # =============================================================================
# ci.yaml — test every push; publish an image for pushes to main that pass. # ci.yaml — test every push; publish an image for pushes to main that pass.
# #
# Modelled on job-tracker's ci.yaml and run by the same runner: a self-hosted # Modelled on job-tracker's ci.yaml. test and publish run on the build VM's
# act_runner on the web_server host (stpvm) in HOST mode, with git and docker and no other # act_runner (stpbuild, label `build`); deploy runs on the stpweb host's
# toolchain. So Go runs in a `docker run` container, and the source is # (stpvm, `self-hosted`), the only one with the stack. Both are in HOST mode,
# fetched with plain git rather than actions/checkout (which needs Node on # with git and docker and no other toolchain. So Go runs in a `docker run`
# the host). # container, and the source is fetched with plain git rather than
# actions/checkout (which needs Node on the host).
# #
# TWO JOBS # THREE JOBS
# test gofmt, go vet, staticcheck and go test (with the database # test gofmt, go vet, staticcheck and go test (with the database
# tests against a throwaway Postgres container), as `make check` # tests against a throwaway Postgres container), as `make check`
# minus -race (see the Go step). Then the Vue app's # minus -race (see the Go step). Then the Vue app's
# typecheck and build, in a node container. # typecheck and build, in a node container.
# publish main only, after test: builds deploy/Dockerfile, pushes it to # publish main only, after test: builds deploy/Dockerfile and pushes it
# this Gitea's container registry as :<sha> and :latest, then # to this Gitea's container registry as :<sha> and :latest. It
# pulls it into the web_server stack (its `activity-tracker` # reuses test's git cache, so both must run on the same runner.
# service) and waits for it to be healthy. # deploy after publish, on stpvm: pulls it into the stpweb stack (its
# `activity-tracker` service) and waits for it to be healthy.
# #
# SECRETS (repo settings -> Actions -> Secrets) # SECRETS (repo settings -> Actions -> Secrets)
# REGISTRY_USER a Gitea user that can write packages for adamf # REGISTRY_USER a Gitea user that can write packages for adamf
@@ -31,14 +33,20 @@ env:
jobs: jobs:
test: test:
runs-on: self-hosted runs-on: build
env: env:
SHA: ${{ github.sha }} SHA: ${{ github.sha }}
REF: ${{ github.ref }} REF: ${{ github.ref }}
REMOTE: ssh://[email protected]:2222/adamf/ccp.git # Names this run's Postgres and network (see SRC below).
GIT_SSH_COMMAND: "ssh -o StrictHostKeyChecking=no" RUN: ${{ github.run_id }}
# Over HTTP with the job's own token (read access to this repo while
# the job runs), so the runner needs no SSH key or Gitea user.
REMOTE: http://git.adam-french.co.uk:3000/adamf/ccp.git
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
CACHE: /home/adamf/.cache/activity-tracker-ci/repo.git CACHE: /home/adamf/.cache/activity-tracker-ci/repo.git
SRC: /home/adamf/.cache/activity-tracker-ci/src-${{ github.sha }} # Per run, not just per commit: the build runner takes two jobs at
# once, and the same commit pushed to two branches runs twice.
SRC: /home/adamf/.cache/activity-tracker-ci/src-${{ github.sha }}-${{ github.run_id }}
steps: steps:
- name: Export the pushed commit to a scratch directory - name: Export the pushed commit to a scratch directory
shell: bash shell: bash
@@ -46,7 +54,12 @@ jobs:
set -eu set -eu
mkdir -p "$(dirname "$CACHE")" mkdir -p "$(dirname "$CACHE")"
[ -d "$CACHE" ] || git init --quiet --bare "$CACHE" [ -d "$CACHE" ] || git init --quiet --bare "$CACHE"
git --git-dir="$CACHE" fetch --quiet --no-tags "$REMOTE" "$REF" # The job's token as a Basic auth header, passed via env rather
# than -c so it never shows in the process list.
auth=$(printf 'x-access-token:%s' "$GITEA_TOKEN" | base64 -w0)
GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=http.extraHeader \
GIT_CONFIG_VALUE_0="Authorization: Basic $auth" \
git --git-dir="$CACHE" fetch --quiet --no-tags "$REMOTE" "$REF"
rm -rf "$SRC" rm -rf "$SRC"
mkdir -p "$SRC" mkdir -p "$SRC"
git --git-dir="$CACHE" archive --format=tar "$SHA" | tar -x -C "$SRC" git --git-dir="$CACHE" archive --format=tar "$SHA" | tar -x -C "$SRC"
@@ -58,14 +71,14 @@ jobs:
shell: bash shell: bash
run: | run: |
set -eu set -eu
docker network create "ci-$SHA" docker network create "ci-$RUN"
docker run -d --name "ci-pg-$SHA" --network "ci-$SHA" --network-alias pg \ docker run -d --name "ci-pg-$RUN" --network "ci-$RUN" --network-alias pg \
-e POSTGRES_PASSWORD=ci postgres:17 -e POSTGRES_PASSWORD=ci postgres:17
for i in $(seq 1 30); do for i in $(seq 1 30); do
docker exec "ci-pg-$SHA" pg_isready -U postgres -h localhost && exit 0 docker exec "ci-pg-$RUN" pg_isready -U postgres -h localhost && exit 0
sleep 1 sleep 1
done done
docker logs "ci-pg-$SHA" docker logs "ci-pg-$RUN"
exit 1 exit 1
# Read-only source, and named volumes for the module and build # Read-only source, and named volumes for the module and build
@@ -81,7 +94,7 @@ jobs:
-v "$SRC":/src:ro -w /src \ -v "$SRC":/src:ro -w /src \
-v activity_tracker_ci_gomod:/go/pkg/mod \ -v activity_tracker_ci_gomod:/go/pkg/mod \
-v activity_tracker_ci_gobuild:/root/.cache/go-build \ -v activity_tracker_ci_gobuild:/root/.cache/go-build \
--network "ci-$SHA" \ --network "ci-$RUN" \
-e TEST_DATABASE_URL='postgres://postgres:ci@pg:5432/postgres?sslmode=disable' \ -e TEST_DATABASE_URL='postgres://postgres:ci@pg:5432/postgres?sslmode=disable' \
golang:1.27 \ golang:1.27 \
sh -c 'test -z "$(gofmt -l .)" && go vet ./... && go tool staticcheck ./... && go test -count=1 ./...' sh -c 'test -z "$(gofmt -l .)" && go vet ./... && go tool staticcheck ./... && go test -count=1 ./...'
@@ -103,17 +116,17 @@ jobs:
shell: bash shell: bash
run: | run: |
rm -rf "$SRC" rm -rf "$SRC"
docker rm -f "ci-pg-$SHA" || true docker rm -f "ci-pg-$RUN" || true
docker network rm "ci-$SHA" || true docker network rm "ci-$RUN" || true
publish: publish:
needs: test needs: test
if: github.ref == 'refs/heads/main' if: github.ref == 'refs/heads/main'
runs-on: self-hosted runs-on: build
env: env:
SHA: ${{ github.sha }} SHA: ${{ github.sha }}
CACHE: /home/adamf/.cache/activity-tracker-ci/repo.git CACHE: /home/adamf/.cache/activity-tracker-ci/repo.git
SRC: /home/adamf/.cache/activity-tracker-ci/publish-${{ github.sha }} SRC: /home/adamf/.cache/activity-tracker-ci/publish-${{ github.sha }}-${{ github.run_id }}
REGISTRY_USER: ${{ secrets.REGISTRY_USER }} REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }} REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
steps: steps:
@@ -135,12 +148,16 @@ jobs:
shell: bash shell: bash
run: rm -rf "$SRC" run: rm -rf "$SRC"
deploy:
needs: publish
runs-on: self-hosted
steps:
# Put the new image live, exactly as job-tracker does: pull and # Put the new image live, exactly as job-tracker does: pull and
# recreate only this service, under .compose.lock, which web_server's # recreate only this service, under .compose.lock, which stpweb's
# deploy and maintenance hold while they run compose. A pinned # deploy and maintenance hold while they run compose. A pinned
# ACTIVITY_TRACKER_IMAGE_TAG in the site's .env makes this a no-op. # ACTIVITY_TRACKER_IMAGE_TAG in the site's .env makes this a no-op.
- name: Roll the site onto the new image - name: Roll the site onto the new image
working-directory: /home/adamf/deploy/web_server working-directory: /home/adamf/deploy/stpweb
shell: bash shell: bash
run: | run: |
set -eu set -eu
+1 -1
View File
@@ -53,7 +53,7 @@ Put the service behind your reverse proxy (Caddy, Traefik and so on) for TLS, be
### Deploying to stpvm ### Deploying to stpvm
Pushing to `main` on Gitea (`adamf/ccp`) runs `.gitea/workflows/ci.yaml` on the web_server host's runner. The workflow runs the tests, pushes `adam-french.co.uk/adamf/activity-tracker:<sha>` and `:latest` to Gitea's container registry, and recreates the `activity-tracker` service in the web_server stack. The service is served at `https://www.adam-french.co.uk/tracker/`, so set collectors to `TRACKER_URL=https://www.adam-french.co.uk/tracker`. Use the `www` host because the apex redirect would turn uploaded POSTs into GETs. To hold a version, set `ACTIVITY_TRACKER_IMAGE_TAG` to a sha in web_server's `.env`. Pushing to `main` on Gitea (`adamf/ccp`) runs `.gitea/workflows/ci.yaml` on stpvm's runner. The workflow runs the tests, pushes `adam-french.co.uk/adamf/activity-tracker:<sha>` and `:latest` to Gitea's container registry, and recreates the `activity-tracker` service in the stpweb stack. The service is served at `https://www.adam-french.co.uk/tracker/`, so set collectors to `TRACKER_URL=https://www.adam-french.co.uk/tracker`. Use the `www` host because the apex redirect would turn uploaded POSTs into GETs. To hold a version, set `ACTIVITY_TRACKER_IMAGE_TAG` to a sha in stpweb's `.env`.
The repo needs the `REGISTRY_USER` and `REGISTRY_TOKEN` Actions secrets, the same ones job-tracker uses. Create its database role once on the host: The repo needs the `REGISTRY_USER` and `REGISTRY_TOKEN` Actions secrets, the same ones job-tracker uses. Create its database role once on the host: