fix: a refused database move leaves the host as it was
CI / check (pull_request) Successful in 19s

On .50 a deploy refused by the database step had already copied the refused
version's compose files and written its NETORK_VERSION to .env: a hand-typed
`docker compose up -d` would have carried postgres back to the old volume.
The database step now runs before .env is written, the previous compose files
are kept as .prev while the new ones are fetched, and a refusal (exit 3) puts
them back. Checked on .50: checksums of both compose files and .env unchanged
after a refused deploy.
This commit is contained in:
Christian Manivong committed 2026-10-21 00:44:15 +02:00
1 parent 4d3a7eb1f4
commit 1e87478f7f
3 files changed
+56 -17

No files matched your search

+26 -16
View File
@@ -301,7 +301,9 @@ deploy_steps() {
docker run --rm --entrypoint cat '${ENGINE_IMAGE}' /app/deploy/\$f > \$f.new \
|| { rm -f \$f.new; echo \"${ENGINE_IMAGE} carries no /app/deploy/\$f — the tag predates compose files in the engine image\"; exit 3; }; \
done && \
for f in ${COMPOSE_FILES}; do mv \$f.new \$f; done"
for f in ${COMPOSE_FILES}; do \
if [ -f \"\$f\" ]; then cp \"\$f\" \"\$f.prev\"; fi; mv \$f.new \$f; \
done"
# Services running netOrk's own images. flower belongs here: it is the engine
# image with a different command, so leaving it out let the monitoring UI run
@@ -324,6 +326,29 @@ deploy_steps() {
REGISTRY_HOST='${REGISTRY_HOST}' NETORK_VERSION='${SERVER_VERSION}' \
docker compose -f docker-compose.yml -f docker-compose.registry.yml pull ${SERVICES}"
# The bundled database, before .env, broker and engine (remote/database.sh). A
# changed image on the same volume (a minor release) is recreated; a new
# volume (a major release) moves only with --infra-db, and without it the
# deploy stops here, nothing changed and the old engine running. The script
# goes over stdin, so the host needs nothing but bash and docker.
echo "[${SERVER}] Reconciling the database (${DATABASE_MODE})..."
local db_status=0
# shellcheck disable=SC2029 # mode, services and version expand here on purpose
ssh "$SERVER" "REGISTRY_HOST='${REGISTRY_HOST}' NETORK_VERSION='${SERVER_VERSION}' bash -s -- ${DATABASE_MODE} ${SERVICES}" \
< "${HERE}/remote/database.sh" 2>&1 | sed "s/^/[${SERVER}] /" || db_status=$?
if [[ $db_status -eq 3 ]]; then
# Refused, nothing changed: the host keeps the compose files it had, so a
# hand-typed `docker compose up -d` cannot carry the database to the other
# volume. .env is written only after this step.
ssh -n "$SERVER" "cd ~/netork && for f in ${COMPOSE_FILES}; do if [ -f \"\$f.prev\" ]; then mv \"\$f.prev\" \"\$f\"; fi; done" || true
echo "[${SERVER}] FAILED: the database step refused; the host is as it was" >&2
return 1
fi
if [[ $db_status -ne 0 ]]; then
echo "[${SERVER}] FAILED: the database step (its output above says what changed)" >&2
return 1
fi
# docker compose substitutes REGISTRY_HOST / NETORK_VERSION from the project
# .env when they are not in the environment. This script passes both inline,
# but a hand-typed `docker compose up -d flower` on the host needs them there
@@ -360,21 +385,6 @@ for kv in "REGISTRY_HOST=${REGISTRY_HOST}" "NETORK_VERSION=${SERVER_VERSION}"; d
done
REMOTE_ENV
# The bundled database, before broker and engine (remote/database.sh). A
# changed image on the same volume (a minor release) is recreated; a new
# volume (a major release) moves only with --infra-db, and without it the
# deploy stops here, nothing changed and the old engine running. The script
# goes over stdin, so the host needs nothing but bash and docker.
echo "[${SERVER}] Reconciling the database (${DATABASE_MODE})..."
local db_status=0
# shellcheck disable=SC2029 # mode, services and version expand here on purpose
ssh "$SERVER" "REGISTRY_HOST='${REGISTRY_HOST}' NETORK_VERSION='${SERVER_VERSION}' bash -s -- ${DATABASE_MODE} ${SERVICES}" \
< "${HERE}/remote/database.sh" 2>&1 | sed "s/^/[${SERVER}] /" || db_status=$?
if [[ $db_status -ne 0 ]]; then
echo "[${SERVER}] FAILED: the database step (its output above says what changed)" >&2
return 1
fi
# The broker, before the engine that cannot work without it. Plain `up -d`
# recreates it only when its compose definition changed, so an unchanged
# broker keeps running and keeps its queue. It used to be in no list at all,