fix(deploy): a deploy failing after the switch brings the containers back
All checks were successful
CI / check (push) Successful in 15m42s
CI / deploy (push) Successful in 15s

A failed deploy put the checkout back at the deployed commit but left
the containers as the new one had made them: when Caddy couldn't start
on the new network (2026-10-14), learn.halkyon.eu stayed down until they
were brought back by hand. Failing after the switch, the deploy now also
starts the containers as the deployed commit has them, on the new
images, which fit the database the migrations have changed. Before the
switch, the running containers are never touched, as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
This commit is contained in:
Tizian 「ティツィアーン」 2026-10-14 00:59:44 +02:00
commit 9d2a93a648
Signed by: raisondetredev
GPG key ID: 07F6FCF405488B64

View file

@ -56,7 +56,7 @@ main() {
echo "Deploying $commit (was $deployed)."
git merge -q --ff-only "$commit"
trap 'git reset -q --hard "$deployed"; echo "The checkout is back at $deployed." >&2' EXIT
trap back_out EXIT
cd deploy
# Build while the running server keeps serving; then dump, migrate, switch.
docker compose build -q server dictionaries
@ -67,6 +67,7 @@ main() {
# serving the schema it knows. (Until the switch, the old server serves the new
# schema; migrations that only add, as they should, keep that harmless.)
docker compose run --rm --no-deps -e role=maintenance server --apply-migrations
switched=yes
docker compose up -d --remove-orphans
# Caddy reads its Caddyfile when it starts, and `up` doesn't restart it for a
# changed file it mounts. Nor would `caddy reload` see the change: Docker
@ -126,6 +127,22 @@ wait_until_answering() {
fail "the server doesn't answer a minute after the switch"
}
# A failed deploy puts the checkout back at the deployed commit, so running the CI job
# again retries. Failing after the switch, it also brings the containers back as that
# commit has them (found 2026-10-14: Caddy couldn't start on the new network, and the
# instance stayed down until they were brought back by hand), on the new images, which
# fit the database the migrations have changed. Before the switch, the running
# containers were never touched.
back_out() {
cd "$HOME/halkyon-learn"
git reset -q --hard "$deployed"
echo "The checkout is back at $deployed." >&2
if [ "${switched:-}" = yes ]; then
(cd deploy && docker compose up -d --remove-orphans) >&2 &&
echo "The containers are back as $deployed has them." >&2
fi
}
fail() {
echo "Error: $*" >&2
exit 1