Roll the site onto each new image from CI
After publishing, the publish job now pulls the image into the web_server stack on the Pi and recreates only the jobs container, under the same flock the site's own deploys and the .env applier take. It then waits for the image's healthcheck and fails the run, with the container's last log lines, if the tracker does not come up. Pinning JOBS_IMAGE_TAG in the site's .env still holds a version, since compose pulls the pinned tag. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -10,10 +10,11 @@
|
||||
# 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. The web_server
|
||||
# stack pulls it (its `jobs` service), so publishing does not by
|
||||
# itself change the live site — see "Deploying" in README.md.
|
||||
# publish main only, after test: builds the image, pushes it to this
|
||||
# Gitea's container registry as :<sha> and :latest, then pulls it
|
||||
# into the web_server stack (its `jobs` service) and waits for it
|
||||
# to be healthy. So a push to main goes live, as web_server's own
|
||||
# pushes do — see "Deploying" in README.md.
|
||||
#
|
||||
# SECRETS (repo settings -> Actions -> Secrets)
|
||||
# REGISTRY_USER a Gitea user that can write packages for adamf
|
||||
@@ -116,3 +117,37 @@ jobs:
|
||||
if: always()
|
||||
shell: bash
|
||||
run: rm -rf "$SRC"
|
||||
|
||||
# Put the new image live. The runner is on the Pi, so this is the
|
||||
# same `pull` + `up` you would type by hand in the site's deploy
|
||||
# directory. Only the `jobs` service is touched (--no-deps), and
|
||||
# compose recreates it only if the pulled image differs.
|
||||
#
|
||||
# Pinning still works: if the site's .env sets JOBS_IMAGE_TAG to a
|
||||
# sha, compose pulls and runs that tag, so this step changes
|
||||
# nothing until the pin is removed.
|
||||
#
|
||||
# flock takes the lock that web_server's deploy.yaml and
|
||||
# env-apply/apply.py hold while they run compose, so this cannot
|
||||
# race a site deploy or an .env change from the admin panel.
|
||||
#
|
||||
# Then it waits for the image's HEALTHCHECK (process up, database
|
||||
# reachable). A tracker that will not start fails the run, which is
|
||||
# the signal to pin JOBS_IMAGE_TAG to the last good sha.
|
||||
- name: Roll the site onto the new image
|
||||
working-directory: /home/adamf/deploy/web_server
|
||||
env:
|
||||
DOCKER_API_VERSION: "1.41"
|
||||
shell: bash
|
||||
run: |
|
||||
set -eu
|
||||
flock env-apply/run/lock sh -c 'docker compose pull jobs && docker compose up -d --no-deps jobs'
|
||||
for i in $(seq 1 30); do
|
||||
status=$(docker inspect -f '{{.State.Health.Status}}' jobs)
|
||||
echo "jobs: $status"
|
||||
[ "$status" = healthy ] && exit 0
|
||||
[ "$status" = unhealthy ] && break
|
||||
sleep 5
|
||||
done
|
||||
docker logs --tail 50 jobs
|
||||
exit 1
|
||||
|
||||
@@ -66,15 +66,15 @@ The site's `docker-compose.yml` runs the published image as service `jobs`, with
|
||||
|
||||
### Deploying
|
||||
|
||||
A push to `main` here runs `.gitea/workflows/ci.yaml`. It tests, then builds and pushes `adam-french.co.uk/adamf/job-tracker:<sha>` and `:latest`.
|
||||
A push to `main` here runs `.gitea/workflows/ci.yaml`. It tests, builds and pushes `adam-french.co.uk/adamf/job-tracker:<sha>` and `:latest`, then rolls the site onto the new image and waits for the container's healthcheck. A tracker that does not come up healthy fails the run, with its last log lines in the output.
|
||||
|
||||
To roll the site onto a new image:
|
||||
The roll-out is the same command you would run by hand on the Pi:
|
||||
|
||||
```
|
||||
cd ~/deploy/web_server && docker compose pull jobs && docker compose up -d jobs
|
||||
cd ~/deploy/web_server && docker compose pull jobs && docker compose up -d --no-deps jobs
|
||||
```
|
||||
|
||||
To pin a version instead of `latest`, set `JOBS_IMAGE_TAG=<sha>` in the site's `.env`.
|
||||
To pin a version, set `JOBS_IMAGE_TAG=<sha>` in the site's `.env`. While it is pinned, pushes here still publish but change nothing live. To roll back, pin the last good sha.
|
||||
|
||||
### One-off: registry setup
|
||||
|
||||
|
||||
Reference in New Issue
Block a user