CI: test and publish on the build VM, deploy on stpvm
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]>
This commit is contained in:
+27
-14
@@ -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 stpweb 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 stpweb 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,12 +33,14 @@ 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
|
# Over HTTP with the job's own token (read access to this repo while
|
||||||
GIT_SSH_COMMAND: "ssh -o StrictHostKeyChecking=no"
|
# 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 }}
|
SRC: /home/adamf/.cache/activity-tracker-ci/src-${{ github.sha }}
|
||||||
steps:
|
steps:
|
||||||
@@ -46,6 +50,11 @@ 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"
|
||||||
|
# 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"
|
git --git-dir="$CACHE" fetch --quiet --no-tags "$REMOTE" "$REF"
|
||||||
rm -rf "$SRC"
|
rm -rf "$SRC"
|
||||||
mkdir -p "$SRC"
|
mkdir -p "$SRC"
|
||||||
@@ -109,7 +118,7 @@ jobs:
|
|||||||
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
|
||||||
@@ -135,6 +144,10 @@ 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 stpweb'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
|
||||||
|
|||||||
Reference in New Issue
Block a user