diff --git a/deploy.sh b/deploy.sh index c0bd430..a82777f 100755 --- a/deploy.sh +++ b/deploy.sh @@ -35,9 +35,40 @@ echo "==> Running migrations..." $COMPOSE --profile "$TARGET" run --rm "${TARGET}-app" \ python -m padelnomics.migrations.migrate +# ── Ensure router is healthy before waiting ────────────────── +# nginx -t resolves upstream hostnames — if the config points to a stopped +# slot, the health check fails. Write config for the CURRENT live slot +# (which is still running) so the router stays healthy during --wait. + +_write_router_conf() { + local SLOT="$1" + mkdir -p "$(dirname "$ROUTER_CONF")" + cat > "$ROUTER_CONF" < Resetting router to current slot ($CURRENT)..." + _write_router_conf "$CURRENT" + $COMPOSE restart router +fi + # ── Start & health check ─────────────────────────────────── -# Router config is NOT written yet — router keeps old config so it stays -# healthy while we wait for the new slot to pass its own health check. echo "==> Starting $TARGET (waiting for health check)..." if ! $COMPOSE --profile "$TARGET" up -d --wait; then @@ -62,27 +93,8 @@ fi # ── Write router config and reload (new slot is healthy) ──── -echo "==> Writing router config for $TARGET..." -mkdir -p "$(dirname "$ROUTER_CONF")" -cat > "$ROUTER_CONF" < Reloading router..." +echo "==> Switching router to $TARGET..." +_write_router_conf "$TARGET" $COMPOSE exec router nginx -s reload # ── Cleanup old pre-deploy backups (keep last 3) ─────────────