CI: test and publish on the build VM, deploy on stpvm
test and publish (build, smoke test, push) move to stpbuild's runner (label `build`); the two roll-out steps become a deploy job on stpvm (`self-hosted`). The fetch is over HTTP with the job's own GITEA_TOKEN. Also fix the roll-out's working directory: /home/adamf/deploy/web_server no longer exists on stpvm; the stack lives in /home/adamf/deploy/stpweb. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
+35
-20
@@ -1,10 +1,12 @@
|
|||||||
# =============================================================================
|
# =============================================================================
|
||||||
# ci.yaml — test the site (site/) on every push that changes it; publish an
|
# ci.yaml — test the site (site/) on every push that changes it; publish an
|
||||||
# image for such pushes to main that pass. Copied from job-tracker's ci.yaml,
|
# image for such pushes to main that pass. Copied from job-tracker's ci.yaml.
|
||||||
# with the same runner and constraints: a self-hosted act_runner on the web_server
|
# test and publish run on the build VM's act_runner (stpbuild, label
|
||||||
# host (stpvm) in HOST mode, with git and docker and no other toolchain. So Go and Node run
|
# `build`); deploy runs on the stpweb host's (stpvm, `self-hosted`), the only
|
||||||
# in `docker run` containers, and the source is fetched with plain git rather
|
# one with the stack. Both are in HOST mode, with git and docker and no other
|
||||||
# than actions/checkout (which needs Node on the host).
|
# 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).
|
||||||
#
|
#
|
||||||
# PATHS
|
# PATHS
|
||||||
# Most pushes here are problems ("Solve moocast", from the CLI or from the
|
# Most pushes here are problems ("Solve moocast", from the CLI or from the
|
||||||
@@ -12,16 +14,18 @@
|
|||||||
# up through the Gitea webhook. Only changes to site/ or this workflow run
|
# up through the Gitea webhook. Only changes to site/ or this workflow run
|
||||||
# it.
|
# it.
|
||||||
#
|
#
|
||||||
# TWO JOBS
|
# THREE JOBS
|
||||||
# test go vet + go test, and a vite build of site/web. The same checks
|
# test go vet + go test, and a vite build of site/web. The same checks
|
||||||
# as `make check` in site/.
|
# as `make check` in site/.
|
||||||
# publish main only, after test: builds the two images, the site
|
# publish main only, after test: builds the two images, the site
|
||||||
# (Dockerfile) and its code runner (Dockerfile.runner), pushes
|
# (Dockerfile) and its code runner (Dockerfile.runner),
|
||||||
# each to this Gitea's container registry as :<sha> and :latest,
|
# smoke-tests the runner image, and pushes each to this Gitea's
|
||||||
# then pulls them into the web_server stack (services
|
# container registry as :<sha> and :latest. It reuses test's git
|
||||||
# `usaco-runner`, then `usaco`) and waits for each to be healthy —
|
# cache, so both must run on the same runner.
|
||||||
# see "Deploying" in site/README.md. The runner goes first, so the
|
# deploy after publish, on stpvm: pulls them into the stpweb stack
|
||||||
# new site never starts against an old runner.
|
# (services `usaco-runner`, then `usaco`) and waits for each to
|
||||||
|
# be healthy — see "Deploying" in site/README.md. The runner goes
|
||||||
|
# first, so the new site never starts against an old runner.
|
||||||
#
|
#
|
||||||
# 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
|
||||||
@@ -41,12 +45,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/usaco.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/usaco.git
|
||||||
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||||
CACHE: /home/adamf/.cache/usaco-ci/repo.git
|
CACHE: /home/adamf/.cache/usaco-ci/repo.git
|
||||||
SRC: /home/adamf/.cache/usaco-ci/src-${{ github.sha }}
|
SRC: /home/adamf/.cache/usaco-ci/src-${{ github.sha }}
|
||||||
steps:
|
steps:
|
||||||
@@ -56,6 +62,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"
|
||||||
@@ -63,7 +74,7 @@ jobs:
|
|||||||
test -f "$SRC/site/go.mod"
|
test -f "$SRC/site/go.mod"
|
||||||
|
|
||||||
# Read-only source, and named volumes for the module and build
|
# Read-only source, and named volumes for the module and build
|
||||||
# caches, for the reasons given in web_server's deploy.yaml. git
|
# caches, for the reasons given in stpweb's deploy.yaml. git
|
||||||
# is installed because internal/repo and internal/index test
|
# is installed because internal/repo and internal/index test
|
||||||
# against real repositories. internal/runner's tests compile and
|
# against real repositories. internal/runner's tests compile and
|
||||||
# run C++ and Python with the image's g++ and python3 (it runs as
|
# run C++ and Python with the image's g++ and python3 (it runs as
|
||||||
@@ -102,7 +113,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/usaco-ci/repo.git
|
CACHE: /home/adamf/.cache/usaco-ci/repo.git
|
||||||
@@ -171,11 +182,15 @@ jobs:
|
|||||||
shell: bash
|
shell: bash
|
||||||
run: rm -rf "$SRC"
|
run: rm -rf "$SRC"
|
||||||
|
|
||||||
|
deploy:
|
||||||
|
needs: publish
|
||||||
|
runs-on: self-hosted
|
||||||
|
steps:
|
||||||
# The runner first, the same way as the site below, so the new
|
# The runner first, the same way as the site below, so the new
|
||||||
# site never talks to an old runner. Pinning
|
# site never talks to an old runner. Pinning
|
||||||
# USACO_RUNNER_IMAGE_TAG in the site's .env makes this a no-op.
|
# USACO_RUNNER_IMAGE_TAG in the site's .env makes this a no-op.
|
||||||
- name: Roll the runner onto the new image
|
- name: Roll the runner 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
|
||||||
@@ -192,11 +207,11 @@ jobs:
|
|||||||
|
|
||||||
# Put the new image live, exactly as job-tracker's workflow does
|
# Put the new image live, exactly as job-tracker's workflow does
|
||||||
# for `jobs`: pull + up of the one service, under .compose.lock, which
|
# for `jobs`: pull + up of the one service, under .compose.lock, which
|
||||||
# web_server's deploy.yaml and maintenance.yaml hold, then wait for the
|
# stpweb's deploy.yaml and maintenance.yaml hold, then wait for the
|
||||||
# image's HEALTHCHECK (process up, repository cloned and indexed).
|
# image's HEALTHCHECK (process up, repository cloned and indexed).
|
||||||
# Pinning USACO_IMAGE_TAG in the site's .env makes this a no-op.
|
# Pinning USACO_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
|
||||||
|
|||||||
Reference in New Issue
Block a user