diff --git a/docker-compose.staging.yml b/docker-compose.staging.yml index cfbc862..6a267f8 100644 --- a/docker-compose.staging.yml +++ b/docker-compose.staging.yml @@ -39,6 +39,12 @@ services: NTFY_TOPIC: ${NTFY_TOPIC:-} NTFY_TOKEN: ${NTFY_TOKEN:-} 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: db: condition: service_healthy diff --git a/docker-compose.yml b/docker-compose.yml index 7c4b62b..671d375 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -40,6 +40,12 @@ services: NTFY_TOPIC: ${NTFY_TOPIC:-} NTFY_TOKEN: ${NTFY_TOKEN:-} 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: db: condition: service_healthy diff --git a/scripts/update-prod.sh b/scripts/update-prod.sh index 5a769f3..25b1add 100755 --- a/scripts/update-prod.sh +++ b/scripts/update-prod.sh @@ -65,7 +65,7 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" VERSION_FILE="$REPO_ROOT/VERSION" DEFAULT_VERSION="0.1.0.0" -MAX_WAIT=35 +MAX_WAIT=90 REMOTE_USER="${REMOTE_USER:-root}" @@ -304,13 +304,19 @@ COUNTER=0 IS_READY=false 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 IS_READY=true break 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 COUNTER=$((COUNTER + 1)) printf "." diff --git a/scripts/update-staging.sh b/scripts/update-staging.sh index 807e8a5..d695d8f 100755 --- a/scripts/update-staging.sh +++ b/scripts/update-staging.sh @@ -1,5 +1,16 @@ #!/bin/bash # Backward-compatible wrapper — prefer: ./scripts/update-prod.sh -dest stage 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)" exec "$SCRIPT_DIR/update-prod.sh" -dest stage "$@"