891 lines
24 KiB
Bash
891 lines
24 KiB
Bash
#!/bin/bash
|
|
|
|
# VIP Coordinator - Standalone Setup Script
|
|
# This script deploys VIP Coordinator directly from Docker Hub
|
|
# No GitHub repository required!
|
|
|
|
set -e
|
|
|
|
clear
|
|
echo "🚀 VIP Coordinator - Standalone Setup"
|
|
echo "====================================="
|
|
echo ""
|
|
echo "This script will deploy VIP Coordinator directly from Docker Hub:"
|
|
echo " ✅ No GitHub repository needed"
|
|
echo " ✅ Uses pre-built images from Docker Hub"
|
|
echo " ✅ Interactive configuration setup"
|
|
echo " ✅ Complete deployment in minutes"
|
|
echo ""
|
|
|
|
# Check if Docker is installed
|
|
if ! command -v docker &> /dev/null; then
|
|
echo "❌ Docker is not installed. Please install Docker first."
|
|
echo " Ubuntu: sudo apt install docker.io docker-compose"
|
|
echo " Visit: https://docs.docker.com/get-docker/"
|
|
exit 1
|
|
fi
|
|
|
|
# Check if Docker Compose is installed
|
|
if ! command -v docker-compose &> /dev/null; then
|
|
echo "❌ Docker Compose is not installed. Please install Docker Compose first."
|
|
echo " Ubuntu: sudo apt install docker-compose"
|
|
echo " Visit: https://docs.docker.com/compose/install/"
|
|
exit 1
|
|
fi
|
|
|
|
echo "✅ Docker and Docker Compose are installed"
|
|
echo ""
|
|
|
|
# Function to prompt for input with default value
|
|
prompt_input() {
|
|
local prompt="$1"
|
|
local default="$2"
|
|
local var_name="$3"
|
|
|
|
if [ -n "$default" ]; then
|
|
read -p "$prompt [$default]: " input
|
|
if [ -z "$input" ]; then
|
|
input="$default"
|
|
fi
|
|
else
|
|
while [ -z "$input" ]; do
|
|
read -p "$prompt: " input
|
|
if [ -z "$input" ]; then
|
|
echo "This field is required. Please enter a value."
|
|
fi
|
|
done
|
|
fi
|
|
|
|
eval "$var_name='$input'"
|
|
}
|
|
|
|
# Function to generate random password
|
|
generate_password() {
|
|
if command -v openssl &> /dev/null; then
|
|
openssl rand -base64 32 | tr -d "=+/" | cut -c1-25
|
|
else
|
|
# Fallback if openssl is not available
|
|
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 25 | head -n 1
|
|
fi
|
|
}
|
|
|
|
echo "📋 Configuration Setup"
|
|
echo "====================="
|
|
echo ""
|
|
|
|
# Deployment type
|
|
echo "1. Deployment Type"
|
|
echo "------------------"
|
|
echo "Choose your deployment type:"
|
|
echo " 1) Local development (localhost)"
|
|
echo " 2) Production with custom domain"
|
|
echo ""
|
|
read -p "Select option [1-2]: " deployment_type
|
|
|
|
if [ "$deployment_type" = "2" ]; then
|
|
echo ""
|
|
echo "2. Domain Configuration"
|
|
echo "----------------------"
|
|
prompt_input "Enter your main domain (e.g., mycompany.com)" "" DOMAIN
|
|
prompt_input "Enter your API subdomain (e.g., api.mycompany.com)" "api.$DOMAIN" API_DOMAIN
|
|
|
|
FRONTEND_URL="https://$DOMAIN"
|
|
VITE_API_URL="https://$API_DOMAIN"
|
|
GOOGLE_REDIRECT_URI="https://$API_DOMAIN/auth/google/callback"
|
|
else
|
|
DOMAIN="localhost"
|
|
API_DOMAIN="localhost:3000"
|
|
FRONTEND_URL="http://localhost"
|
|
VITE_API_URL="http://localhost:3000"
|
|
GOOGLE_REDIRECT_URI="http://localhost:3000/auth/google/callback"
|
|
fi
|
|
|
|
echo ""
|
|
echo "3. Security Configuration"
|
|
echo "-------------------------"
|
|
DB_PASSWORD=$(generate_password)
|
|
ADMIN_PASSWORD=$(generate_password)
|
|
|
|
echo "Generated secure passwords:"
|
|
echo " Database Password: $DB_PASSWORD"
|
|
echo " Admin Password: $ADMIN_PASSWORD"
|
|
echo ""
|
|
read -p "Use these generated passwords? [Y/n]: " use_generated
|
|
if [[ $use_generated =~ ^[Nn]$ ]]; then
|
|
prompt_input "Enter database password" "" DB_PASSWORD
|
|
prompt_input "Enter admin password" "" ADMIN_PASSWORD
|
|
fi
|
|
|
|
echo ""
|
|
echo "4. Google OAuth Setup"
|
|
echo "--------------------"
|
|
echo "To set up Google OAuth:"
|
|
echo " 1. Go to https://console.cloud.google.com/"
|
|
echo " 2. Create a new project or select existing"
|
|
echo " 3. Enable Google+ API"
|
|
echo " 4. Go to Credentials → Create Credentials → OAuth 2.0 Client IDs"
|
|
echo " 5. Set application type to 'Web application'"
|
|
echo " 6. Add authorized redirect URI: $GOOGLE_REDIRECT_URI"
|
|
echo " 7. Copy the Client ID and Client Secret from Google"
|
|
echo ""
|
|
echo "⚠️ IMPORTANT: Enter the actual credentials from Google Cloud Console"
|
|
echo " - Client ID looks like: 123456789-abcdefg.apps.googleusercontent.com"
|
|
echo " - Client Secret looks like: GOCSPX-abcdefghijklmnopqrstuvwxyz"
|
|
echo ""
|
|
|
|
# Collect Google OAuth Client ID
|
|
while [ -z "$GOOGLE_CLIENT_ID" ]; do
|
|
read -p "Enter Google OAuth Client ID (from Google Cloud Console): " GOOGLE_CLIENT_ID
|
|
if [ -z "$GOOGLE_CLIENT_ID" ]; then
|
|
echo "This field is required. Please enter your Google OAuth Client ID."
|
|
fi
|
|
done
|
|
|
|
# Validate Client ID format
|
|
if [[ ! "$GOOGLE_CLIENT_ID" =~ \.apps\.googleusercontent\.com$ ]]; then
|
|
echo "⚠️ Warning: Client ID should end with '.apps.googleusercontent.com'"
|
|
echo " You entered: $GOOGLE_CLIENT_ID"
|
|
read -p "Continue anyway? [y/N]: " continue_anyway
|
|
if [[ ! $continue_anyway =~ ^[Yy]$ ]]; then
|
|
echo "Please re-run the script with the correct Google OAuth Client ID"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
# Collect Google OAuth Client Secret
|
|
while [ -z "$GOOGLE_CLIENT_SECRET" ]; do
|
|
read -p "Enter Google OAuth Client Secret (from Google Cloud Console): " GOOGLE_CLIENT_SECRET
|
|
if [ -z "$GOOGLE_CLIENT_SECRET" ]; then
|
|
echo "This field is required. Please enter your Google OAuth Client Secret."
|
|
fi
|
|
done
|
|
|
|
# Validate Client Secret format
|
|
if [[ ! "$GOOGLE_CLIENT_SECRET" =~ ^GOCSPX- ]]; then
|
|
echo "⚠️ Warning: Client Secret should start with 'GOCSPX-'"
|
|
echo " You entered: $GOOGLE_CLIENT_SECRET"
|
|
read -p "Continue anyway? [y/N]: " continue_anyway
|
|
if [[ ! $continue_anyway =~ ^[Yy]$ ]]; then
|
|
echo "Please re-run the script with the correct Google OAuth Client Secret"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
echo ""
|
|
echo "✅ OAuth credentials collected:"
|
|
echo " Client ID: $GOOGLE_CLIENT_ID"
|
|
echo " Client Secret: ${GOOGLE_CLIENT_SECRET:0:10}..."
|
|
|
|
echo ""
|
|
echo "5. Optional Configuration"
|
|
echo "------------------------"
|
|
prompt_input "Enter AviationStack API Key (optional, for flight data)" "optional" AVIATIONSTACK_API_KEY
|
|
if [ "$AVIATIONSTACK_API_KEY" = "optional" ]; then
|
|
AVIATIONSTACK_API_KEY=""
|
|
fi
|
|
|
|
# Generate .env file
|
|
echo ""
|
|
echo "📝 Generating configuration files..."
|
|
|
|
cat > .env << EOF
|
|
# VIP Coordinator Environment Configuration
|
|
# Generated by standalone setup script on $(date)
|
|
|
|
# Database Configuration
|
|
DB_PASSWORD=$DB_PASSWORD
|
|
|
|
# Domain Configuration
|
|
DOMAIN=$DOMAIN
|
|
VITE_API_URL=$VITE_API_URL
|
|
|
|
# Google OAuth Configuration
|
|
GOOGLE_CLIENT_ID=$GOOGLE_CLIENT_ID
|
|
GOOGLE_CLIENT_SECRET=$GOOGLE_CLIENT_SECRET
|
|
GOOGLE_REDIRECT_URI=$GOOGLE_REDIRECT_URI
|
|
|
|
# Frontend URL
|
|
FRONTEND_URL=$FRONTEND_URL
|
|
|
|
# Admin Configuration
|
|
ADMIN_PASSWORD=$ADMIN_PASSWORD
|
|
|
|
# Flight API Configuration
|
|
AVIATIONSTACK_API_KEY=$AVIATIONSTACK_API_KEY
|
|
|
|
# Port Configuration
|
|
PORT=3000
|
|
EOF
|
|
|
|
# Generate docker-compose.yml with Docker Hub images
|
|
cat > docker-compose.yml << 'EOF'
|
|
version: '3.8'
|
|
|
|
services:
|
|
|
|
db:
|
|
image: postgres:15
|
|
environment:
|
|
POSTGRES_DB: vip_coordinator
|
|
POSTGRES_PASSWORD: ${DB_PASSWORD}
|
|
volumes:
|
|
- postgres-data:/var/lib/postgresql/data
|
|
restart: unless-stopped
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "pg_isready -U postgres"]
|
|
interval: 30s
|
|
timeout: 10s
|
|
retries: 3
|
|
|
|
redis:
|
|
image: redis:7
|
|
restart: unless-stopped
|
|
healthcheck:
|
|
test: ["CMD", "redis-cli", "ping"]
|
|
interval: 30s
|
|
timeout: 10s
|
|
retries: 3
|
|
|
|
backend:
|
|
image: t72chevy/vip-coordinator:backend-latest
|
|
environment:
|
|
DATABASE_URL: postgresql://postgres:${DB_PASSWORD}@db:5432/vip_coordinator
|
|
REDIS_URL: redis://redis:6379
|
|
GOOGLE_CLIENT_ID: ${GOOGLE_CLIENT_ID}
|
|
GOOGLE_CLIENT_SECRET: ${GOOGLE_CLIENT_SECRET}
|
|
GOOGLE_REDIRECT_URI: ${GOOGLE_REDIRECT_URI}
|
|
FRONTEND_URL: ${FRONTEND_URL}
|
|
ADMIN_PASSWORD: ${ADMIN_PASSWORD}
|
|
PORT: 3000
|
|
ports:
|
|
- "3000:3000"
|
|
depends_on:
|
|
db:
|
|
condition: service_healthy
|
|
redis:
|
|
condition: service_healthy
|
|
restart: unless-stopped
|
|
|
|
frontend:
|
|
image: t72chevy/vip-coordinator:frontend-latest
|
|
ports:
|
|
- "80:80"
|
|
depends_on:
|
|
- backend
|
|
restart: unless-stopped
|
|
|
|
volumes:
|
|
postgres-data:
|
|
EOF
|
|
|
|
# Generate SSL certificate automation for production deployments
|
|
if [ "$deployment_type" = "2" ]; then
|
|
echo ""
|
|
echo "🔒 Setting up SSL certificate automation..."
|
|
|
|
# Generate SSL setup script
|
|
cat > setup-ssl.sh << EOF
|
|
#!/bin/bash
|
|
|
|
# SSL Certificate Setup for VIP Coordinator
|
|
# Uses Let's Encrypt with certbot Docker container
|
|
|
|
set -e
|
|
|
|
echo "🔒 Setting up SSL certificates with Let's Encrypt..."
|
|
echo "=================================================="
|
|
echo ""
|
|
echo "Domain: $DOMAIN"
|
|
echo "API Domain: $API_DOMAIN"
|
|
echo ""
|
|
|
|
# Check if certificates already exist
|
|
if [ -d "./ssl/live/$DOMAIN" ]; then
|
|
echo "⚠️ SSL certificates already exist for $DOMAIN"
|
|
read -p "Renew certificates? [y/N]: " renew_certs
|
|
if [[ ! \$renew_certs =~ ^[Yy]\$ ]]; then
|
|
echo "Skipping SSL setup. Existing certificates will be used."
|
|
exit 0
|
|
fi
|
|
fi
|
|
|
|
# Create SSL directory structure
|
|
mkdir -p ssl/live ssl/archive ssl/renewal
|
|
|
|
# Generate certificates using certbot Docker container
|
|
echo "📋 Generating SSL certificates..."
|
|
echo "This may take a few minutes..."
|
|
|
|
# Stop any running nginx to free port 80
|
|
docker-compose stop frontend 2>/dev/null || true
|
|
|
|
# Run certbot to get certificates
|
|
docker run --rm \\
|
|
-v "\$(pwd)/ssl:/etc/letsencrypt" \\
|
|
-p 80:80 \\
|
|
certbot/certbot certonly \\
|
|
--standalone \\
|
|
--email admin@$DOMAIN \\
|
|
--agree-tos \\
|
|
--no-eff-email \\
|
|
-d $DOMAIN \\
|
|
-d $API_DOMAIN
|
|
|
|
if [ \$? -eq 0 ]; then
|
|
echo "✅ SSL certificates generated successfully!"
|
|
|
|
# Set proper permissions
|
|
sudo chown -R \$(whoami):\$(whoami) ssl/
|
|
|
|
# Generate nginx SSL configuration
|
|
cat > nginx-ssl.conf << 'NGINX_EOF'
|
|
# Nginx SSL configuration for VIP Coordinator
|
|
# Generated automatically by setup-ssl.sh
|
|
|
|
# Redirect HTTP to HTTPS
|
|
server {
|
|
listen 80;
|
|
server_name $DOMAIN $API_DOMAIN;
|
|
return 301 https://\\\$server_name\\\$request_uri;
|
|
}
|
|
|
|
# Frontend with SSL
|
|
server {
|
|
listen 443 ssl http2;
|
|
server_name $DOMAIN;
|
|
|
|
# SSL configuration
|
|
ssl_certificate /etc/letsencrypt/live/$DOMAIN/fullchain.pem;
|
|
ssl_certificate_key /etc/letsencrypt/live/$DOMAIN/privkey.pem;
|
|
|
|
# SSL security settings
|
|
ssl_protocols TLSv1.2 TLSv1.3;
|
|
ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384;
|
|
ssl_prefer_server_ciphers off;
|
|
ssl_session_cache shared:SSL:10m;
|
|
ssl_session_timeout 10m;
|
|
|
|
# Security headers
|
|
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
|
add_header X-Frame-Options DENY always;
|
|
add_header X-Content-Type-Options nosniff always;
|
|
add_header X-XSS-Protection "1; mode=block" always;
|
|
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
|
|
|
location / {
|
|
proxy_pass http://localhost:80;
|
|
proxy_set_header Host \\\$host;
|
|
proxy_set_header X-Real-IP \\\$remote_addr;
|
|
proxy_set_header X-Forwarded-For \\\$proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto \\\$scheme;
|
|
}
|
|
}
|
|
|
|
# Backend API with SSL
|
|
server {
|
|
listen 443 ssl http2;
|
|
server_name $API_DOMAIN;
|
|
|
|
# SSL configuration
|
|
ssl_certificate /etc/letsencrypt/live/$DOMAIN/fullchain.pem;
|
|
ssl_certificate_key /etc/letsencrypt/live/$DOMAIN/privkey.pem;
|
|
|
|
# SSL security settings
|
|
ssl_protocols TLSv1.2 TLSv1.3;
|
|
ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384;
|
|
ssl_prefer_server_ciphers off;
|
|
ssl_session_cache shared:SSL:10m;
|
|
ssl_session_timeout 10m;
|
|
|
|
# Security headers
|
|
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
|
add_header X-Frame-Options DENY always;
|
|
add_header X-Content-Type-Options nosniff always;
|
|
add_header X-XSS-Protection "1; mode=block" always;
|
|
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
|
|
|
location / {
|
|
proxy_pass http://localhost:3000;
|
|
proxy_set_header Host \\\$host;
|
|
proxy_set_header X-Real-IP \\\$remote_addr;
|
|
proxy_set_header X-Forwarded-For \\\$proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto \\\$scheme;
|
|
}
|
|
}
|
|
NGINX_EOF
|
|
|
|
echo ""
|
|
echo "📄 Generated nginx-ssl.conf with SSL configuration"
|
|
echo " Copy this file to your nginx sites-available directory"
|
|
echo " Example: sudo cp nginx-ssl.conf /etc/nginx/sites-available/vip-coordinator"
|
|
echo " Then: sudo ln -s /etc/nginx/sites-available/vip-coordinator /etc/nginx/sites-enabled/"
|
|
echo " Finally: sudo nginx -t && sudo systemctl reload nginx"
|
|
|
|
else
|
|
echo "❌ Failed to generate SSL certificates"
|
|
echo "Please check:"
|
|
echo " - Domain DNS points to this server"
|
|
echo " - Port 80 is accessible from the internet"
|
|
echo " - No firewall blocking port 80"
|
|
exit 1
|
|
fi
|
|
|
|
echo ""
|
|
echo "🔄 Setting up automatic certificate renewal..."
|
|
|
|
# Create renewal script
|
|
cat > renew-ssl.sh << 'RENEW_EOF'
|
|
#!/bin/bash
|
|
|
|
# SSL Certificate Renewal Script
|
|
# Run this monthly via cron
|
|
|
|
echo "🔄 Renewing SSL certificates..."
|
|
|
|
# Stop frontend to free port 80
|
|
docker-compose stop frontend
|
|
|
|
# Renew certificates
|
|
docker run --rm \\
|
|
-v "\$(pwd)/ssl:/etc/letsencrypt" \\
|
|
-p 80:80 \\
|
|
certbot/certbot renew \\
|
|
--standalone
|
|
|
|
# Restart frontend
|
|
docker-compose start frontend
|
|
|
|
# Reload nginx if it's running
|
|
if systemctl is-active --quiet nginx; then
|
|
sudo systemctl reload nginx
|
|
echo "✅ Nginx reloaded with new certificates"
|
|
fi
|
|
|
|
echo "✅ Certificate renewal completed"
|
|
RENEW_EOF
|
|
|
|
chmod +x renew-ssl.sh
|
|
|
|
# Add to crontab for automatic renewal
|
|
echo "📅 Setting up automatic renewal (monthly)..."
|
|
(crontab -l 2>/dev/null; echo "0 3 1 * * cd \$(pwd) && ./renew-ssl.sh >> ssl-renewal.log 2>&1") | crontab -
|
|
|
|
echo ""
|
|
echo "✅ SSL setup completed successfully!"
|
|
echo "=================================="
|
|
echo ""
|
|
echo "📄 Generated files:"
|
|
echo " - nginx-ssl.conf (nginx configuration with SSL)"
|
|
echo " - renew-ssl.sh (certificate renewal script)"
|
|
echo ""
|
|
echo "🔧 Next steps:"
|
|
echo " 1. Copy nginx-ssl.conf to your nginx configuration"
|
|
echo " 2. Restart nginx to use SSL configuration"
|
|
echo " 3. Test your HTTPS setup: https://$DOMAIN"
|
|
echo ""
|
|
echo "🔄 Automatic renewal:"
|
|
echo " - Certificates will auto-renew monthly via cron"
|
|
echo " - Check renewal logs: tail ssl-renewal.log"
|
|
echo ""
|
|
EOF
|
|
|
|
chmod +x setup-ssl.sh
|
|
|
|
# Generate production nginx configuration template
|
|
cat > nginx-production.conf << EOF
|
|
# Production Nginx Configuration for VIP Coordinator
|
|
# Copy this to /etc/nginx/sites-available/vip-coordinator
|
|
# Then: sudo ln -s /etc/nginx/sites-available/vip-coordinator /etc/nginx/sites-enabled/
|
|
|
|
# Redirect HTTP to HTTPS
|
|
server {
|
|
listen 80;
|
|
server_name $DOMAIN $API_DOMAIN;
|
|
return 301 https://\$server_name\$request_uri;
|
|
}
|
|
|
|
# Frontend with SSL
|
|
server {
|
|
listen 443 ssl http2;
|
|
server_name $DOMAIN;
|
|
|
|
# SSL configuration (update after running setup-ssl.sh)
|
|
ssl_certificate /path/to/ssl/live/$DOMAIN/fullchain.pem;
|
|
ssl_certificate_key /path/to/ssl/live/$DOMAIN/privkey.pem;
|
|
|
|
# SSL security settings
|
|
ssl_protocols TLSv1.2 TLSv1.3;
|
|
ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384;
|
|
ssl_prefer_server_ciphers off;
|
|
ssl_session_cache shared:SSL:10m;
|
|
ssl_session_timeout 10m;
|
|
|
|
# Security headers
|
|
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
|
add_header X-Frame-Options DENY always;
|
|
add_header X-Content-Type-Options nosniff always;
|
|
add_header X-XSS-Protection "1; mode=block" always;
|
|
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
|
|
|
location / {
|
|
proxy_pass http://localhost:80;
|
|
proxy_set_header Host \$host;
|
|
proxy_set_header X-Real-IP \$remote_addr;
|
|
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto \$scheme;
|
|
}
|
|
}
|
|
|
|
# Backend API with SSL
|
|
server {
|
|
listen 443 ssl http2;
|
|
server_name $API_DOMAIN;
|
|
|
|
# SSL configuration (update after running setup-ssl.sh)
|
|
ssl_certificate /path/to/ssl/live/$DOMAIN/fullchain.pem;
|
|
ssl_certificate_key /path/to/ssl/live/$DOMAIN/privkey.pem;
|
|
|
|
# SSL security settings
|
|
ssl_protocols TLSv1.2 TLSv1.3;
|
|
ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384;
|
|
ssl_prefer_server_ciphers off;
|
|
ssl_session_cache shared:SSL:10m;
|
|
ssl_session_timeout 10m;
|
|
|
|
# Security headers
|
|
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
|
add_header X-Frame-Options DENY always;
|
|
add_header X-Content-Type-Options nosniff always;
|
|
add_header X-XSS-Protection "1; mode=block" always;
|
|
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
|
|
|
location / {
|
|
proxy_pass http://localhost:3000;
|
|
proxy_set_header Host \$host;
|
|
proxy_set_header X-Real-IP \$remote_addr;
|
|
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto \$scheme;
|
|
}
|
|
}
|
|
EOF
|
|
|
|
fi
|
|
|
|
# Generate management scripts
|
|
cat > start.sh << EOF
|
|
#!/bin/bash
|
|
|
|
echo "🚀 Starting VIP Coordinator..."
|
|
|
|
# Pull latest images from Docker Hub
|
|
echo "📥 Pulling latest images from Docker Hub..."
|
|
docker-compose pull
|
|
|
|
# Start services
|
|
echo "🔄 Starting services..."
|
|
docker-compose up -d
|
|
|
|
# Wait for services
|
|
echo "⏳ Waiting for services to start..."
|
|
sleep 15
|
|
|
|
# Check status
|
|
echo "📊 Service Status:"
|
|
docker-compose ps
|
|
|
|
echo ""
|
|
echo "🎉 VIP Coordinator is running!"
|
|
echo "=============================="
|
|
echo "Frontend: $FRONTEND_URL"
|
|
echo "Backend API: $VITE_API_URL"
|
|
echo ""
|
|
echo "The first user to log in will become the administrator."
|
|
echo "Admin password: $ADMIN_PASSWORD"
|
|
EOF
|
|
|
|
chmod +x start.sh
|
|
|
|
cat > stop.sh << 'EOF'
|
|
#!/bin/bash
|
|
|
|
echo "🛑 Stopping VIP Coordinator..."
|
|
docker-compose down
|
|
|
|
echo "✅ VIP Coordinator stopped."
|
|
EOF
|
|
|
|
chmod +x stop.sh
|
|
|
|
cat > update.sh << 'EOF'
|
|
#!/bin/bash
|
|
|
|
echo "🔄 Updating VIP Coordinator..."
|
|
|
|
# Pull latest images from Docker Hub
|
|
echo "📥 Pulling latest images from Docker Hub..."
|
|
docker-compose pull
|
|
|
|
# Restart with new images
|
|
echo "🔄 Restarting services..."
|
|
docker-compose up -d
|
|
|
|
echo "✅ VIP Coordinator updated to latest version!"
|
|
EOF
|
|
|
|
chmod +x update.sh
|
|
|
|
# Generate logs script
|
|
cat > logs.sh << 'EOF'
|
|
#!/bin/bash
|
|
|
|
echo "📋 VIP Coordinator Logs"
|
|
echo "======================="
|
|
echo ""
|
|
echo "Choose log view:"
|
|
echo " 1) All services"
|
|
echo " 2) Backend only"
|
|
echo " 3) Frontend only"
|
|
echo " 4) Database only"
|
|
echo " 5) Follow all logs (real-time)"
|
|
echo ""
|
|
read -p "Select option [1-5]: " log_choice
|
|
|
|
case $log_choice in
|
|
1) docker-compose logs ;;
|
|
2) docker-compose logs backend ;;
|
|
3) docker-compose logs frontend ;;
|
|
4) docker-compose logs db ;;
|
|
5) docker-compose logs -f ;;
|
|
*) echo "Invalid option" ;;
|
|
esac
|
|
EOF
|
|
|
|
chmod +x logs.sh
|
|
|
|
# Generate status script
|
|
cat > status.sh << 'EOF'
|
|
#!/bin/bash
|
|
|
|
echo "📊 VIP Coordinator Status"
|
|
echo "========================="
|
|
echo ""
|
|
|
|
# Check if containers are running
|
|
echo "🐳 Container Status:"
|
|
docker-compose ps
|
|
|
|
echo ""
|
|
echo "🏥 Health Checks:"
|
|
|
|
# Check backend health
|
|
if curl -s http://localhost:3000/health > /dev/null 2>&1; then
|
|
echo "✅ Backend: Healthy"
|
|
else
|
|
echo "❌ Backend: Not responding"
|
|
fi
|
|
|
|
# Check frontend
|
|
if curl -s http://localhost/ > /dev/null 2>&1; then
|
|
echo "✅ Frontend: Accessible"
|
|
else
|
|
echo "❌ Frontend: Not accessible"
|
|
fi
|
|
|
|
echo ""
|
|
echo "💾 Disk Usage:"
|
|
docker system df
|
|
|
|
echo ""
|
|
echo "🔧 Management Commands:"
|
|
echo " ./start.sh - Start VIP Coordinator"
|
|
echo " ./stop.sh - Stop VIP Coordinator"
|
|
echo " ./update.sh - Update to latest version"
|
|
echo " ./logs.sh - View logs"
|
|
echo " ./status.sh - Show this status"
|
|
EOF
|
|
|
|
chmod +x status.sh
|
|
|
|
# Generate README
|
|
cat > README.md << EOF
|
|
# VIP Coordinator - Standalone Deployment
|
|
|
|
This directory contains your VIP Coordinator deployment using Docker Hub images.
|
|
|
|
## 🚀 Quick Start
|
|
|
|
\`\`\`bash
|
|
# Start VIP Coordinator
|
|
./start.sh
|
|
|
|
# Check status
|
|
./status.sh
|
|
|
|
# View logs
|
|
./logs.sh
|
|
|
|
# Stop when needed
|
|
./stop.sh
|
|
\`\`\`
|
|
|
|
## 📋 Configuration
|
|
|
|
Your configuration is stored in \`.env\`:
|
|
|
|
- **Frontend URL**: $FRONTEND_URL
|
|
- **Backend API**: $VITE_API_URL
|
|
- **Admin Password**: $ADMIN_PASSWORD
|
|
- **Database Password**: $DB_PASSWORD
|
|
|
|
## 🔐 First Time Setup
|
|
|
|
EOF
|
|
|
|
if [ "$deployment_type" = "2" ]; then
|
|
cat >> README.md << EOF
|
|
### Production Setup (with SSL)
|
|
|
|
1. Set up SSL certificates: \`./setup-ssl.sh\`
|
|
2. Configure nginx with the generated configuration
|
|
3. Run \`./start.sh\` to start the application
|
|
4. Open $FRONTEND_URL in your browser
|
|
5. Click "Continue with Google" to set up your admin account
|
|
6. The first user to log in becomes the administrator
|
|
|
|
### SSL Certificate Management
|
|
|
|
- **Setup**: \`./setup-ssl.sh\` - Generate Let's Encrypt certificates
|
|
- **Renewal**: Automatic monthly renewal via cron job
|
|
- **Manual Renewal**: \`./renew-ssl.sh\`
|
|
- **Logs**: Check \`ssl-renewal.log\` for renewal status
|
|
|
|
EOF
|
|
else
|
|
cat >> README.md << EOF
|
|
### Local Development Setup
|
|
|
|
1. Run \`./start.sh\` to start the application
|
|
2. Open $FRONTEND_URL in your browser
|
|
3. Click "Continue with Google" to set up your admin account
|
|
4. The first user to log in becomes the administrator
|
|
|
|
EOF
|
|
fi
|
|
|
|
cat >> README.md << EOF
|
|
|
|
## 🛠️ Management
|
|
|
|
- **Start**: \`./start.sh\`
|
|
- **Stop**: \`./stop.sh\`
|
|
- **Update**: \`./update.sh\`
|
|
- **Status**: \`./status.sh\`
|
|
- **Logs**: \`./logs.sh\`
|
|
|
|
## 🔄 Updates
|
|
|
|
To update to the latest version:
|
|
|
|
\`\`\`bash
|
|
./update.sh
|
|
\`\`\`
|
|
|
|
This pulls the latest images from Docker Hub and restarts the services.
|
|
|
|
## 🐳 Docker Hub Images
|
|
|
|
This deployment uses these pre-built images:
|
|
|
|
- **Backend**: \`t72chevy/vip-coordinator:backend-latest\`
|
|
- **Frontend**: \`t72chevy/vip-coordinator:frontend-latest\`
|
|
- **Database**: \`postgres:15\`
|
|
- **Cache**: \`redis:7\`
|
|
|
|
## 🔧 Troubleshooting
|
|
|
|
### Check Status
|
|
\`\`\`bash
|
|
./status.sh
|
|
\`\`\`
|
|
|
|
### View Logs
|
|
\`\`\`bash
|
|
./logs.sh
|
|
\`\`\`
|
|
|
|
### Restart Services
|
|
\`\`\`bash
|
|
./stop.sh
|
|
./start.sh
|
|
\`\`\`
|
|
|
|
### Reset Everything (⚠️ Deletes all data)
|
|
\`\`\`bash
|
|
docker-compose down -v
|
|
./start.sh
|
|
\`\`\`
|
|
|
|
## 📞 Support
|
|
|
|
If you encounter issues:
|
|
|
|
1. Check \`./status.sh\` for service health
|
|
2. Review \`./logs.sh\` for error messages
|
|
3. Ensure ports 80 and 3000 are available
|
|
4. Verify Docker and Docker Compose are installed
|
|
|
|
## 🎉 Success!
|
|
|
|
Your VIP Coordinator is now running with:
|
|
- ✅ Google OAuth authentication
|
|
- ✅ Mobile-friendly interface
|
|
- ✅ Real-time scheduling
|
|
- ✅ User management
|
|
- ✅ Automatic updates from Docker Hub
|
|
|
|
EOF
|
|
|
|
echo ""
|
|
echo "✅ Standalone setup completed successfully!"
|
|
echo "=========================================="
|
|
echo ""
|
|
echo "Generated files:"
|
|
echo " 📄 .env - Environment configuration"
|
|
echo " 📄 docker-compose.yml - Docker services (using Docker Hub images)"
|
|
echo " 📄 start.sh - Start VIP Coordinator"
|
|
echo " 📄 stop.sh - Stop VIP Coordinator"
|
|
echo " 📄 update.sh - Update from Docker Hub"
|
|
echo " 📄 status.sh - Check system status"
|
|
echo " 📄 logs.sh - View application logs"
|
|
echo " 📄 README.md - Documentation"
|
|
|
|
if [ "$deployment_type" = "2" ]; then
|
|
echo " 🔒 setup-ssl.sh - SSL certificate automation"
|
|
echo " 🔒 nginx-production.conf - Production nginx configuration"
|
|
fi
|
|
|
|
echo ""
|
|
echo "🚀 Next steps:"
|
|
if [ "$deployment_type" = "2" ]; then
|
|
echo " 1. Set up SSL certificates: ./setup-ssl.sh"
|
|
echo " 2. Configure nginx with the generated nginx-production.conf"
|
|
echo " 3. Run: ./start.sh"
|
|
echo " 4. Open: $FRONTEND_URL"
|
|
echo " 5. Login with Google to set up your admin account"
|
|
else
|
|
echo " 1. Run: ./start.sh"
|
|
echo " 2. Open: $FRONTEND_URL"
|
|
echo " 3. Login with Google to set up your admin account"
|
|
fi
|
|
echo ""
|
|
echo "💡 Important credentials:"
|
|
echo " - Admin password: $ADMIN_PASSWORD"
|
|
echo " - Database password: $DB_PASSWORD"
|
|
echo " - Keep these passwords secure!"
|
|
echo ""
|
|
echo "🎉 VIP Coordinator is ready to deploy from Docker Hub!"
|
|
echo ""
|
|
echo "📦 This deployment uses pre-built images from Docker Hub:"
|
|
echo " - t72chevy/vip-coordinator:backend-latest"
|
|
echo " - t72chevy/vip-coordinator:frontend-latest"
|
|
echo " - No GitHub repository required!" |