#!/bin/bash set -e echo "🚀 Deploying Rezepte to production with Traefik..." echo "📍 Target: https://rezepte.fuerst-stuttgart.de" # Check if .env.traefik exists if [ ! -f .env.traefik ]; then echo "❌ Error: .env.traefik file not found!" echo "Please copy .env.traefik.example to .env.traefik and configure it." exit 1 fi # Load environment variables export $(cat .env.traefik | grep -v '^#' | xargs) # Validate required environment variables if [ -z "$MYSQL_PASSWORD" ] || [ -z "$DOMAIN" ] || [ -z "$ACME_EMAIL" ]; then echo "❌ Error: Required environment variables not set in .env.traefik" echo "Please configure MYSQL_PASSWORD, DOMAIN, and ACME_EMAIL" exit 1 fi echo "📥 Pulling latest changes..." git pull origin main echo "🛑 Stopping existing containers..." docker compose -f docker-compose.traefik.yml --env-file .env.traefik down echo "🏗️ Building images..." docker compose -f docker-compose.traefik.yml --env-file .env.traefik build --no-cache echo "🚀 Starting services..." docker compose -f docker-compose.traefik.yml --env-file .env.traefik up -d echo "⏳ Waiting for services to start..." sleep 45 echo "🔍 Checking service health..." HEALTHY_SERVICES=$(docker compose -f docker-compose.traefik.yml --env-file .env.traefik ps --filter "status=running" --format "table {{.Service}}\t{{.Status}}" | grep -c "Up" || true) if [ "$HEALTHY_SERVICES" -ge 3 ]; then echo "✅ Deployment successful!" echo "" echo "🌐 Application URLs:" echo " 📱 Rezepte App: https://rezepte.fuerst-stuttgart.de" echo " 🗄️ phpMyAdmin: https://pma.fuerst-stuttgart.de" echo " ⚙️ Traefik Dashboard: https://traefik.fuerst-stuttgart.de" echo "" echo "📊 Service Status:" docker compose -f docker-compose.traefik.yml --env-file .env.traefik ps echo "" echo "🔐 Let's Encrypt certificates will be automatically generated." echo "🔄 Services are configured with auto-restart policies." else echo "❌ Deployment failed! Check logs:" echo "" echo "🐳 Container Status:" docker compose -f docker-compose.traefik.yml --env-file .env.traefik ps echo "" echo "📋 Recent logs:" docker compose -f docker-compose.traefik.yml --env-file .env.traefik logs --tail=20 exit 1 fi echo "🎉 Production deployment completed successfully!"