feat: the bundled database on every deploy, and --infra-db to move it (NetOrk/netork#1308)
CI / check (pull_request) Failing after 28s

remote/database.sh runs on the host (over ssh's stdin) after .env and before
broker and engine:

- no bundled database: nothing to do;
- the volume it already uses: plain `up -d --wait`, recreated only on a changed
  image or definition, so a new PostgreSQL minor release arrives with the next
  deploy;
- another volume (a new major version): a normal deploy stops there, nothing
  changed; with --infra-db the engine stops, the old database is counted and
  dumped (kept in ~/netork/backups), the new container comes up on the new
  volume, restore, ANALYZE, counts and Alembic revision must match. The old
  volume stays, and deploying the previous version with --infra-db switches
  back onto it without a restore.

Checked on .50 in reconcile mode: the running postgres:16 container stayed as
it was. README describes the steps and the way back.
This commit is contained in:
Christian Manivong committed 2026-10-20 23:15:48 +02:00
1 parent 9513594f1a
commit 6e3ecb8680
5 files changed
+460 -7

No files matched your search

+22 -1
View File
@@ -2,12 +2,17 @@
# Deploy netOrk to one or more servers in parallel.
#
# Usage:
# ./deploy.sh [--version=<tag>] [server1 server2 ...]
# ./deploy.sh [--version=<tag>] [--infra-db] [server1 server2 ...]
#
# --version overrides the per-server NETORK_VERSION from deploy.env for this
# run only — useful to test one commit (--version=main-<sha>) without moving
# a server to a different release channel.
#
# --infra-db lets the bundled PostgreSQL move to the volume the compose files
# name, by dump and restore (a new major version, NetOrk/netork#1308). Without
# it a deploy that would need that move stops before anything changed. Run it
# for one host at an announced time: the engine is down while the data moves.
#
# Default targets and registry credentials are read from deploy.env next to
# this script (see deploy.env.example). DEPLOY_ENV_FILE points elsewhere.
#
@@ -178,6 +183,7 @@ release_host_lock() {
}
VERSION_OVERRIDE=""
DATABASE_MODE=reconcile
EXPLICIT_SERVERS=()
i=1
while [[ $i -le $# ]]; do
@@ -188,6 +194,7 @@ while [[ $i -le $# ]]; do
VERSION_OVERRIDE="${!i:-}"
;;
--version=*) VERSION_OVERRIDE="${arg#--version=}" ;;
--infra-db) DATABASE_MODE=move ;;
-*)
echo "Unknown option: ${arg}" >&2
exit 2
@@ -353,6 +360,20 @@ 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
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,