diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml index b1d48e4..80c41c2 100644 --- a/.gitea/workflows/ci.yaml +++ b/.gitea/workflows/ci.yaml @@ -1,21 +1,23 @@ # ============================================================================= # 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 -# act_runner on the stpweb host (stpvm) in HOST mode, with git and docker and no other -# toolchain. So Go runs in a `docker run` container, and the source is -# fetched with plain git rather than actions/checkout (which needs Node on -# the host). +# Modelled on job-tracker's ci.yaml. test and publish run on the build VM's +# act_runner (stpbuild, label `build`); deploy runs on the stpweb host's +# (stpvm, `self-hosted`), the only one with the stack. Both are in HOST mode, +# with git and docker and no other toolchain. So Go runs in a `docker run` +# 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 # tests against a throwaway Postgres container), as `make check` # minus -race (see the Go step). Then the Vue app's # typecheck and build, in a node container. -# publish main only, after test: builds deploy/Dockerfile, pushes it to -# this Gitea's container registry as : and :latest, then -# pulls it into the stpweb stack (its `activity-tracker` -# service) and waits for it to be healthy. +# publish main only, after test: builds deploy/Dockerfile and pushes it +# to this Gitea's container registry as : and :latest. It +# reuses test's git cache, so both must run on the same runner. +# 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) # REGISTRY_USER a Gitea user that can write packages for adamf @@ -31,12 +33,14 @@ env: jobs: test: - runs-on: self-hosted + runs-on: build env: SHA: ${{ github.sha }} REF: ${{ github.ref }} - REMOTE: ssh://git@git.adam-french.co.uk:2222/adamf/ccp.git - GIT_SSH_COMMAND: "ssh -o StrictHostKeyChecking=no" + # 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 SRC: /home/adamf/.cache/activity-tracker-ci/src-${{ github.sha }} steps: @@ -46,7 +50,12 @@ jobs: set -eu mkdir -p "$(dirname "$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" mkdir -p "$SRC" git --git-dir="$CACHE" archive --format=tar "$SHA" | tar -x -C "$SRC" @@ -109,7 +118,7 @@ jobs: publish: needs: test if: github.ref == 'refs/heads/main' - runs-on: self-hosted + runs-on: build env: SHA: ${{ github.sha }} CACHE: /home/adamf/.cache/activity-tracker-ci/repo.git @@ -135,6 +144,10 @@ jobs: shell: bash run: rm -rf "$SRC" + deploy: + needs: publish + runs-on: self-hosted + steps: # Put the new image live, exactly as job-tracker does: pull and # recreate only this service, under .compose.lock, which stpweb's # deploy and maintenance hold while they run compose. A pinned