93 lines
3.0 KiB
Bash
93 lines
3.0 KiB
Bash
|
#!/bin/bash
|
||
|
# ScriptShare Production Deployment Script
|
||
|
|
||
|
set -e
|
||
|
|
||
|
echo "🚀 Starting ScriptShare deployment..."
|
||
|
|
||
|
# Check if Docker and Docker Compose are installed
|
||
|
if ! command -v docker &> /dev/null; then
|
||
|
echo "❌ Docker is not installed. Please install Docker first."
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
if ! command -v docker-compose &> /dev/null && ! docker compose version &> /dev/null; then
|
||
|
echo "❌ Docker Compose is not installed. Please install Docker Compose first."
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
# Check if environment file exists
|
||
|
if [ ! -f "env.production" ]; then
|
||
|
echo "❌ Environment file 'env.production' not found."
|
||
|
echo "Please copy 'env.production' and configure your settings."
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
# Create necessary directories
|
||
|
echo "📁 Creating required directories..."
|
||
|
mkdir -p logs
|
||
|
mkdir -p certs
|
||
|
mkdir -p backups
|
||
|
|
||
|
# Copy environment file
|
||
|
cp env.production .env
|
||
|
|
||
|
# Pull latest images
|
||
|
echo "📥 Pulling Docker images..."
|
||
|
docker-compose -f docker-compose.prod.yml pull
|
||
|
|
||
|
# Build custom images
|
||
|
echo "🔨 Building application images..."
|
||
|
docker-compose -f docker-compose.prod.yml build --no-cache
|
||
|
|
||
|
# Stop existing containers if running
|
||
|
echo "🛑 Stopping existing containers..."
|
||
|
docker-compose -f docker-compose.prod.yml down
|
||
|
|
||
|
# Start the application
|
||
|
echo "🚀 Starting ScriptShare application..."
|
||
|
docker-compose -f docker-compose.prod.yml up -d
|
||
|
|
||
|
# Wait for services to be healthy
|
||
|
echo "⏳ Waiting for services to start..."
|
||
|
sleep 30
|
||
|
|
||
|
# Check service health
|
||
|
echo "🏥 Checking service health..."
|
||
|
services=("scriptshare-db" "scriptshare-api" "scriptshare-frontend" "scriptshare-proxy")
|
||
|
|
||
|
for service in "${services[@]}"; do
|
||
|
if docker-compose -f docker-compose.prod.yml ps | grep -q "$service.*Up"; then
|
||
|
echo "✅ $service is running"
|
||
|
else
|
||
|
echo "❌ $service failed to start"
|
||
|
echo "Checking logs for $service:"
|
||
|
docker-compose -f docker-compose.prod.yml logs "$service"
|
||
|
exit 1
|
||
|
fi
|
||
|
done
|
||
|
|
||
|
# Run database migrations if needed
|
||
|
echo "🗃️ Running database migrations..."
|
||
|
docker-compose -f docker-compose.prod.yml exec -T scriptshare-api npm run db:migrate:prod || echo "⚠️ Database migrations not available or failed"
|
||
|
|
||
|
# Display deployment information
|
||
|
echo ""
|
||
|
echo "🎉 ScriptShare deployment completed successfully!"
|
||
|
echo ""
|
||
|
echo "📊 Service URLs:"
|
||
|
echo " Frontend: http://localhost:$(grep PROXY_PORT .env | cut -d'=' -f2 | tr -d '"')"
|
||
|
echo " API: http://localhost:$(grep API_PORT .env | cut -d'=' -f2 | tr -d '"')/api/health"
|
||
|
echo " Database: localhost:$(grep DB_PORT .env | cut -d'=' -f2 | tr -d '"')"
|
||
|
echo ""
|
||
|
echo "🔧 Management commands:"
|
||
|
echo " View logs: docker-compose -f docker-compose.prod.yml logs -f"
|
||
|
echo " Stop: docker-compose -f docker-compose.prod.yml down"
|
||
|
echo " Restart: docker-compose -f docker-compose.prod.yml restart"
|
||
|
echo ""
|
||
|
echo "📝 Next steps:"
|
||
|
echo " 1. Configure your domain DNS to point to this server"
|
||
|
echo " 2. Set up SSL certificates in ./certs/"
|
||
|
echo " 3. Update env.production with your domain settings"
|
||
|
echo " 4. Run: docker-compose -f docker-compose.prod.yml restart scriptshare-proxy"
|