Files
tt-booking/deploy.sh
T
mikicv 2d31c49235 Refactor production setup and database management
- Updated Dockerfile for production to ensure proper database permissions and improved startup script.
- Removed outdated PRODUCTION_README.md and consolidated relevant information into other documentation.
- Enhanced deploy.sh script to fix database permissions and streamline deployment process.
- Modified docker-compose configuration to use a dedicated production file and adjusted port mappings.
- Removed legacy docker-compose.yml file to avoid confusion.
- Improved session management by refining secure cookie settings based on environment variables.
- Deleted obsolete Nginx configuration and old seed scripts to clean up the project structure.
- Updated database setup scripts to reflect new structure and removed old seed data scripts.
- Adjusted reset-db script to use environment variable for database path.
- Enhanced setup-database script to provide dynamic admin credentials in the summary.
- Removed unnecessary backup file for SQLite database.
2025-09-28 16:32:31 +01:00

97 lines
3.1 KiB
Bash
Executable File

#!/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 ""