#!/bin/bash
set -e

COMPOSE_FILE="/aziros/docker-compose.staging.yml"

echo "[deploy] $(date) – Deploy gestartet"
cd /aziros

git pull origin main

docker compose -f "$COMPOSE_FILE" exec -T app npm ci --silent
docker compose -f "$COMPOSE_FILE" exec -T app npm run build:staging

docker compose -f "$COMPOSE_FILE" exec -T app composer install --no-dev --optimize-autoloader --quiet

docker compose -f "$COMPOSE_FILE" exec -T app php artisan migrate --force
docker compose -f "$COMPOSE_FILE" exec -T app php artisan db:seed --class=TranslationSeeder --force

docker compose -f "$COMPOSE_FILE" exec -T app php artisan config:clear
docker compose -f "$COMPOSE_FILE" exec -T app php artisan cache:clear
docker compose -f "$COMPOSE_FILE" exec -T app php artisan view:clear
docker compose -f "$COMPOSE_FILE" exec -T app php artisan route:clear
docker compose -f "$COMPOSE_FILE" exec -T app php artisan config:cache
docker compose -f "$COMPOSE_FILE" exec -T app php artisan route:cache
docker compose -f "$COMPOSE_FILE" exec -T app php artisan view:cache

docker compose -f "$COMPOSE_FILE" restart worker scheduler mail-worker reverb

echo "[deploy] ✅ Deploy fertig"
