Files
websitedev/deploy.sh
T
Do Siki bd7287aa58 fix: address code review findings from 2026-08-17
- scope no-cache headers to non-static routes (restore immutable asset caching)
- reset cached rejected MongoDB promise so retries can succeed
- use last X-Forwarded-For entry in Content Editor rate limiter (anti-spoofing)
- remove weak Mongo defaults from compose files (fail loudly on missing env)
- move staging banner text to common.json content
- read APP_PORT from env file in deploy.sh healthcheck
- filter network noise from staging smoke console assertions

Closes MITHOME-48, MITHOME-49, MITHOME-50, MITHOME-51, MITHOME-52, MITHOME-53, MITHOME-54
2026-08-18 12:21:32 +02:00

64 lines
2.2 KiB
Bash
Executable File

#!/bin/bash
# mozdIT Deploy Script — natív docker compose, Dokploy nélkül
# Használat: ./deploy.sh [staging|production]
# A szerveren fut (git pull + rebuild + indítás).
# Compose fájl és port env-enként különbözik.
set -euo pipefail
ENV="$1"
if [ "$ENV" != "staging" ] && [ "$ENV" != "production" ]; then
echo "Hiba: Hiányzó vagy érvénytelen környezet paraméter."
echo "Használat: ./deploy.sh staging VAGY ./deploy.sh production"
exit 1
fi
# WHY: staging és production külön compose fájlt és portot használ, hogy
# ugyanazon a szerveren ne ütközzenek (prod 8080, staging 8081).
COMPOSE_FILE="docker-compose.${ENV}.yml"
DEFAULT_PORT=8080
if [ "$ENV" = "staging" ]; then
DEFAULT_PORT=8081
fi
echo "🚀 Deploy indítása: [$ENV] környezet (${COMPOSE_FILE})"
# 1. Kód frissítése
echo "📦 Kód frissítése a main ágról..."
git pull origin main
# 2. Környezeti változók (.env.<env>)
ENV_FILE=".env.${ENV}"
if [ ! -f "$ENV_FILE" ]; then
echo "❌ Hiba: $ENV_FILE fájl nem található."
echo " Másold le a .env.staging.example / .env.production.example fájlt $ENV_FILE néven, és töltsd ki."
exit 1
fi
echo "🔑 Környezeti változók betöltése ($ENV_FILE)..."
# WHY: a --env-file kapcsoló csak a compose változó-helyettesítését táplálja;
# a shell nem látja belőle az APP_PORT-ot, ezért a healthcheckhez expliciten kiolvassuk.
APP_PORT_VALUE="$(grep -E '^APP_PORT=' "$ENV_FILE" | tail -n 1 | cut -d= -f2- | tr -d '[:space:]' | tr -d '"' | tr -d "'")"
# 3. Docker konténerek újraépítése és indítása
echo "🐳 Build és indítás..."
# A friss Dockerfile- vagy build-arg-változásoknak is új konténerben kell érvényesülniük.
docker compose --env-file "$ENV_FILE" -f "$COMPOSE_FILE" up --build --force-recreate -d
# 4. Healthcheck
echo "⏳ Healthcheck (max 60s)..."
HEALTH_URL="http://localhost:${APP_PORT_VALUE:-$DEFAULT_PORT}/api/health"
for i in $(seq 1 30); do
if curl -sf "$HEALTH_URL" > /dev/null 2>&1; then
echo "✅ Healthcheck OK: $HEALTH_URL"
echo "✅ Deploy sikeres: [$ENV]"
exit 0
fi
sleep 2
done
echo "❌ Healthcheck sikertelen: $HEALTH_URL"
docker compose -f "$COMPOSE_FILE" logs app --tail 50
exit 1