#!/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 # Create necessary directories echo "📁 Creating necessary directories..." mkdir -p data backups logs # Set proper permissions echo "🔒 Setting directory permissions..." chmod 755 data backups logs # 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 # Setup database echo "🛠️ Setting up the database..." npx tsx scripts/setup-database.ts # Fix database permissions for container echo "🔒 Fixing database permissions for container..." if [ -f "data/sqlite.db" ]; then chmod 666 data/sqlite.db fi chmod 777 data backups logs # Build and deploy with Docker Compose echo "🐳 Building and starting Docker containers..." # Stop existing containers docker compose -f docker-compose.production.yml down || echo "No existing containers to stop" # Build and start containers docker compose -f docker-compose.production.yml up -d --build # Wait for containers to be healthy echo "⏳ Waiting for containers to be healthy..." sleep 30 # Check health echo "🔍 Checking application health..." for i in {1..10}; do if curl -f http://localhost:3036/api/health >/dev/null 2>&1; then echo "✅ Application is healthy!" break elif [ $i -eq 10 ]; then echo "❌ Application health check failed after 10 attempts" echo "📋 Container logs:" docker compose -f docker-compose.production.yml logs tt-booking exit 1 else echo "⏳ Attempt $i/10: Application not ready yet, waiting..." sleep 10 fi done # Show running containers echo "📊 Running containers:" docker compose -f docker-compose.production.yml ps # Show logs echo "📋 Recent application logs:" docker compose -f docker-compose.production.yml logs --tail=20 tt-booking echo "" echo "🎉 Deployment completed successfully!" echo "" echo "📊 Application Status:" echo " • URL: https://lcc-tt-booking.mikicvi.com" echo " • Health Check: http://localhost:3036/api/health" echo " • Container Status: $(docker compose -f docker-compose.production.yml ps -q tt-booking | xargs docker inspect -f '{{.State.Status}}')" echo "" echo "🔧 Useful commands:" echo " • View 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 "" echo "⚠️ Don't forget to:" echo " 1. Set up Cloudflare Tunnel to expose your application" echo " 2. Update your .env.production with real email credentials" echo " 3. Change the default admin password" echo ""