fix(deploy): Backend-Healthcheck und Staging-Wrapper absichern
Expliziter Compose-Healthcheck für das Backend, curl-Fallback und längeres MAX_WAIT im Deploy-Skript; update-staging.sh lehnt -dest ab. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -39,6 +39,12 @@ services:
|
|||||||
NTFY_TOPIC: ${NTFY_TOPIC:-}
|
NTFY_TOPIC: ${NTFY_TOPIC:-}
|
||||||
NTFY_TOKEN: ${NTFY_TOKEN:-}
|
NTFY_TOKEN: ${NTFY_TOKEN:-}
|
||||||
command: sh -c "npx prisma db push && node dist/index.js"
|
command: sh -c "npx prisma db push && node dist/index.js"
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "node", "-e", "const http = require('http'); http.get('http://localhost:5000/api/health', (res) => { process.exit(res.statusCode === 200 ? 0 : 1); }).on('error', () => process.exit(1));"]
|
||||||
|
interval: 15s
|
||||||
|
timeout: 5s
|
||||||
|
start_period: 60s
|
||||||
|
retries: 5
|
||||||
depends_on:
|
depends_on:
|
||||||
db:
|
db:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
|
|||||||
@@ -40,6 +40,12 @@ services:
|
|||||||
NTFY_TOPIC: ${NTFY_TOPIC:-}
|
NTFY_TOPIC: ${NTFY_TOPIC:-}
|
||||||
NTFY_TOKEN: ${NTFY_TOKEN:-}
|
NTFY_TOKEN: ${NTFY_TOKEN:-}
|
||||||
command: sh -c "npx prisma db push && node dist/index.js"
|
command: sh -c "npx prisma db push && node dist/index.js"
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "node", "-e", "const http = require('http'); http.get('http://localhost:5000/api/health', (res) => { process.exit(res.statusCode === 200 ? 0 : 1); }).on('error', () => process.exit(1));"]
|
||||||
|
interval: 15s
|
||||||
|
timeout: 5s
|
||||||
|
start_period: 60s
|
||||||
|
retries: 5
|
||||||
depends_on:
|
depends_on:
|
||||||
db:
|
db:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|||||||
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||||
VERSION_FILE="$REPO_ROOT/VERSION"
|
VERSION_FILE="$REPO_ROOT/VERSION"
|
||||||
DEFAULT_VERSION="0.1.0.0"
|
DEFAULT_VERSION="0.1.0.0"
|
||||||
MAX_WAIT=35
|
MAX_WAIT=90
|
||||||
|
|
||||||
REMOTE_USER="${REMOTE_USER:-root}"
|
REMOTE_USER="${REMOTE_USER:-root}"
|
||||||
|
|
||||||
@@ -304,13 +304,19 @@ COUNTER=0
|
|||||||
IS_READY=false
|
IS_READY=false
|
||||||
|
|
||||||
while [ $COUNTER -lt $MAX_WAIT ]; do
|
while [ $COUNTER -lt $MAX_WAIT ]; do
|
||||||
STATUS=$(docker inspect --format='{{.State.Health.Status}}' "$BACKEND_CONTAINER" 2>/dev/null)
|
STATUS=$(docker inspect --format='{{if .State.Health}}{{.State.Health.Status}}{{end}}' "$BACKEND_CONTAINER" 2>/dev/null || true)
|
||||||
|
|
||||||
if [ "$STATUS" = "healthy" ]; then
|
if [ "$STATUS" = "healthy" ]; then
|
||||||
IS_READY=true
|
IS_READY=true
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# End-to-end fallback via frontend nginx (covers missing/stale container health state)
|
||||||
|
if curl -sf "http://127.0.0.1/api/health" | grep -q '"status":"ok"'; then
|
||||||
|
IS_READY=true
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
|
||||||
sleep 1
|
sleep 1
|
||||||
COUNTER=$((COUNTER + 1))
|
COUNTER=$((COUNTER + 1))
|
||||||
printf "."
|
printf "."
|
||||||
|
|||||||
@@ -1,5 +1,16 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Backward-compatible wrapper — prefer: ./scripts/update-prod.sh -dest stage
|
# Backward-compatible wrapper — prefer: ./scripts/update-prod.sh -dest stage
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
|
for arg in "$@"; do
|
||||||
|
case "$arg" in
|
||||||
|
-dest|-dest=*)
|
||||||
|
echo "Error: update-staging.sh always deploys to staging." >&2
|
||||||
|
echo " Use ./scripts/update-prod.sh -dest prod for production." >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
exec "$SCRIPT_DIR/update-prod.sh" -dest stage "$@"
|
exec "$SCRIPT_DIR/update-prod.sh" -dest stage "$@"
|
||||||
|
|||||||
Reference in New Issue
Block a user