feat: the bundled database on every deploy, and --infra-db to move it (NetOrk/netork#1308) #14
No files matched your search
@@ -102,7 +102,9 @@ started earlier pulls whatever image the registry held before, which is stale.
|
||||
over ssh's stdin). On the volume it already uses, it is recreated only if its image
|
||||
or definition changed, so a new minor release arrives with the next deploy. If the
|
||||
compose files name another volume (a new major version), a normal deploy stops
|
||||
here before anything changed; see *Moving the bundled database*.
|
||||
here before anything changed: the host keeps its previous compose files and
|
||||
`.env`, so a hand-typed `docker compose up -d` cannot move the database either.
|
||||
See *Moving the bundled database*. This step runs before `.env` is written.
|
||||
6. Reconciles the broker, `redis` (Valkey): recreated only if its definition changed,
|
||||
and waited for until healthy, before the engine comes up against it. If it does
|
||||
not get healthy within 120 s, the deploy stops with the old engine running.
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -82,3 +82,30 @@ def test_a_refusal_stops_the_deploy_before_the_engine(tmp_path: Path) -> None:
|
||||
assert result.returncode != 0
|
||||
assert not any("--force-recreate" in c for c in commands)
|
||||
assert not any("redis" in c and "up -d" in c for c in commands)
|
||||
|
||||
|
||||
def test_the_database_is_checked_before_env_names_the_new_version(tmp_path: Path) -> None:
|
||||
"""A refused deploy must leave .env as it was: the check runs first."""
|
||||
_, commands = _deploy(tmp_path)
|
||||
|
||||
env_write = next(i for i, c in enumerate(commands) if c.strip() == "bash -s")
|
||||
assert _index(commands, "bash -s -- reconcile") < env_write
|
||||
|
||||
|
||||
def test_the_previous_compose_files_are_kept_while_the_new_ones_are_fetched(tmp_path: Path) -> None:
|
||||
_, commands = _deploy(tmp_path)
|
||||
|
||||
fetch = commands[_index(commands, "/app/deploy/")]
|
||||
assert 'cp "$f" "$f.prev"' in fetch
|
||||
|
||||
|
||||
def test_a_refusal_puts_the_previous_compose_files_back(tmp_path: Path) -> None:
|
||||
"""Refused (exit 3) means nothing changed; the host's compose files must not
|
||||
name the refused version either, or a hand-typed `docker compose up -d`
|
||||
would carry the database to the other volume (seen on .50, 2026-10-21)."""
|
||||
result, commands = _deploy(tmp_path, db_exit=3)
|
||||
|
||||
assert result.returncode != 0
|
||||
restore = [c for c in commands if 'mv "$f.prev" "$f"' in c]
|
||||
assert restore, "the previous compose files are not put back"
|
||||
assert _index(commands, 'mv "$f.prev" "$f"') > _index(commands, "bash -s -- reconcile")
|
||||
Reference in new issue
Block a user