Improve deployment scripts with better error handling and SSL setup
This commit is contained in:
103
deploy.sh
103
deploy.sh
@@ -1,27 +1,61 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Game Tracker Deployment Script
|
||||
# Game Tracker Deployment Script with improved error handling
|
||||
|
||||
echo "=== Game Tracker Deployment ==="
|
||||
set -e # Exit on error
|
||||
|
||||
# Bold text function
|
||||
bold() {
|
||||
echo -e "\033[1m$1\033[0m"
|
||||
}
|
||||
|
||||
# Print section header
|
||||
header() {
|
||||
echo
|
||||
bold "=== $1 ==="
|
||||
}
|
||||
|
||||
# Print error message and exit
|
||||
error() {
|
||||
echo -e "\033[31mERROR: $1\033[0m" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Check if a command exists
|
||||
command_exists() {
|
||||
command -v "$1" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
header "Game Tracker Deployment"
|
||||
|
||||
# Check requirements
|
||||
echo "Checking requirements..."
|
||||
|
||||
if ! command_exists docker; then
|
||||
error "Docker is not installed. Please install Docker first."
|
||||
fi
|
||||
|
||||
if ! command_exists docker-compose; then
|
||||
error "Docker Compose is not installed. Please install Docker Compose first."
|
||||
fi
|
||||
|
||||
# Default settings
|
||||
DEPLOY_MODE=${DEPLOY_MODE:-local}
|
||||
|
||||
# Check if .env file exists
|
||||
echo "Checking environment..."
|
||||
if [ ! -f .env ]; then
|
||||
echo "ERROR: .env file not found!"
|
||||
echo "Please create a .env file with your IGDB credentials:"
|
||||
echo "IGDB_CLIENT_ID=your_client_id_here"
|
||||
echo "IGDB_CLIENT_SECRET=your_client_secret_here"
|
||||
exit 1
|
||||
error "'.env' file not found! Please create a .env file with your IGDB credentials:\nIGDB_CLIENT_ID=your_client_id_here\nIGDB_CLIENT_SECRET=your_client_secret_here"
|
||||
fi
|
||||
|
||||
# Make sure database directory exists
|
||||
# Make sure necessary directories exist
|
||||
echo "Creating required directories..."
|
||||
mkdir -p instance
|
||||
mkdir -p nginx
|
||||
|
||||
# Check deployment mode
|
||||
if [ "$1" = "--ssl" ] || [ "$DEPLOY_MODE" = "ssl" ]; then
|
||||
echo "Deploying with SSL (for production use)..."
|
||||
header "SSL Deployment (Production Mode)"
|
||||
|
||||
# Check for domain name
|
||||
if [ -z "$DOMAIN" ]; then
|
||||
@@ -35,10 +69,25 @@ if [ "$1" = "--ssl" ] || [ "$DEPLOY_MODE" = "ssl" ]; then
|
||||
export EMAIL
|
||||
fi
|
||||
|
||||
# Verify domain
|
||||
echo "Verifying domain '$DOMAIN' is properly configured..."
|
||||
host_ip=$(dig +short "$DOMAIN" 2>/dev/null || echo "")
|
||||
|
||||
if [ -z "$host_ip" ]; then
|
||||
echo "WARNING: Could not resolve domain '$DOMAIN'. DNS might not be configured correctly."
|
||||
read -p "Continue anyway? (y/n): " answer
|
||||
if [[ "$answer" != [Yy]* ]]; then
|
||||
error "Deployment cancelled. Please configure DNS correctly and try again."
|
||||
fi
|
||||
else
|
||||
echo "Domain '$DOMAIN' resolves to IP: $host_ip"
|
||||
fi
|
||||
|
||||
# Run the SSL setup script
|
||||
echo "Running SSL setup script..."
|
||||
./init-letsencrypt.sh
|
||||
|
||||
echo "=== SSL Deployment Complete ==="
|
||||
header "SSL Deployment Complete"
|
||||
echo "Your Game Tracker is now running at: https://$DOMAIN"
|
||||
echo ""
|
||||
echo "SSL certificates will auto-renew every 90 days"
|
||||
@@ -46,28 +95,36 @@ if [ "$1" = "--ssl" ] || [ "$DEPLOY_MODE" = "ssl" ]; then
|
||||
echo "To stop the server: docker-compose down"
|
||||
|
||||
else
|
||||
echo "Deploying locally (for development/testing)..."
|
||||
header "Local Deployment (Development Mode)"
|
||||
|
||||
# Create a simpler nginx config for local deployment
|
||||
mkdir -p nginx
|
||||
echo "Generating local nginx configuration..."
|
||||
cat > nginx/app.conf << EOF
|
||||
server {
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
|
||||
location / {
|
||||
proxy_pass http://web:8000;
|
||||
proxy_set_header Host \$host;
|
||||
proxy_set_header X-Real-IP \$remote_addr;
|
||||
}
|
||||
}
|
||||
server {
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
|
||||
location / {
|
||||
proxy_pass http://web:8000;
|
||||
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
|
||||
|
||||
# Build and start Docker containers
|
||||
echo "Building and starting Docker containers..."
|
||||
docker-compose down 2>/dev/null || true # Ignore errors if no containers are running
|
||||
docker-compose up --build -d
|
||||
|
||||
echo "=== Local Deployment Complete ==="
|
||||
# Check if containers started successfully
|
||||
if ! docker-compose ps | grep -q "Up"; then
|
||||
error "Failed to start containers. Check logs with 'docker-compose logs'."
|
||||
fi
|
||||
|
||||
header "Local Deployment Complete"
|
||||
echo "Your Game Tracker is now running at: http://localhost"
|
||||
echo ""
|
||||
echo "To view logs: docker-compose logs -f"
|
||||
|
||||
Reference in New Issue
Block a user