#!/bin/bash # LCC Table Tennis Booking - Production Deployment Script # Domain: lcc-tt-booking.mikicvi.com set -e echo "🚀 Starting production deployment for LCC Table Tennis Booking..." # Check if .env.production exists if [ ! -f .env.production ]; then echo "❌ .env.production file not found!" echo "Please create .env.production with your production environment variables." exit 1 fi # Pull latest changes (if using git) if [ -d ".git" ]; then echo "📦 Pulling latest changes..." git pull origin main || echo "⚠️ Git pull failed or not needed" fi # Build and deploy with Docker Compose echo "🐳 Building and deploying containers..." # Stop existing containers docker compose -f docker-compose.production.yml down || echo "No existing containers to stop" # Build and start containers (database initialization is automated) docker compose -f docker-compose.production.yml up -d --build # Wait for health check to pass (container has built-in health checks) echo "⏳ Waiting for application to be ready..." timeout=60 counter=0 while [ $counter -lt $timeout ]; do if docker compose -f docker-compose.production.yml ps tt-booking | grep -q "healthy"; then echo "✅ Application is healthy!" break elif [ $counter -eq $((timeout-10)) ]; then echo "❌ Application failed to become healthy within ${timeout}s" echo "📋 Container logs:" docker compose -f docker-compose.production.yml logs --tail=30 tt-booking exit 1 else echo "⏳ Waiting for health check... (${counter}s/${timeout}s)" sleep 5 counter=$((counter+5)) fi done # Show deployment status echo "📊 Deployment Status:" docker compose -f docker-compose.production.yml ps tt-booking echo "📋 Recent application logs:" docker compose -f docker-compose.production.yml logs --tail=10 tt-booking echo "" echo "🎉 Deployment completed successfully!" echo "" echo "📊 Application Details:" echo " - URL: https://lcc-tt-booking.mikicvi.com" echo " - Local: http://localhost:3036" echo " - Health: http://localhost:3036/api/health" echo "" echo "🔧 Management commands:" echo " - Logs: docker compose -f docker-compose.production.yml logs -f tt-booking" echo " - Restart: docker compose -f docker-compose.production.yml restart tt-booking" echo " - Stop: docker compose -f docker-compose.production.yml down" echo " - Shell: docker compose -f docker-compose.production.yml exec tt-booking sh" echo "" echo "⚠️ Post-deployment checklist:" echo " - Cloudflare Tunnel is configured and running" echo " - Admin password changed from default" echo " - Email settings configured in .env.production" echo ""