#!/bin/bash # Orbital Simulator Docker Deployment Script set -e echo "🚀 Orbital Simulator Docker Deployment" echo "======================================" # Check if Docker is installed if ! command -v docker &> /dev/null; then echo "❌ Docker is not installed. Please install Docker first." exit 1 fi # Check if Docker Compose is available 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 # Function to use docker-compose or docker compose docker_compose() { if command -v docker-compose &> /dev/null; then docker-compose "$@" else docker compose "$@" fi } # Parse command line arguments MODE="development" ACTION="up" BUILD="--build" while [[ $# -gt 0 ]]; do case $1 in --production) MODE="production" shift ;; --dev|--development) MODE="development" shift ;; --down) ACTION="down" BUILD="" shift ;; --logs) ACTION="logs" BUILD="" shift ;; --no-build) BUILD="" shift ;; --help) echo "Usage: $0 [OPTIONS]" echo "" echo "Options:" echo " --production Deploy in production mode with Nginx" echo " --dev Deploy in development mode (default)" echo " --down Stop and remove containers" echo " --logs Show container logs" echo " --no-build Skip building images" echo " --help Show this help message" echo "" echo "Examples:" echo " $0 # Start in development mode" echo " $0 --production # Start in production mode" echo " $0 --down # Stop all containers" echo " $0 --logs # View logs" exit 0 ;; *) echo "Unknown option: $1" echo "Use --help for usage information" exit 1 ;; esac done echo "Mode: $MODE" echo "Action: $ACTION" # Handle different actions case $ACTION in "up") echo "🔧 Starting Orbital Simulator..." if [ "$MODE" = "production" ]; then echo "🌐 Production mode: Starting with Nginx reverse proxy" docker_compose --profile production $ACTION $BUILD -d echo "" echo "✅ Orbital Simulator is running in production mode!" echo "🌐 Web Interface: http://localhost" echo "📊 Direct API: http://localhost:3000" else echo "🛠️ Development mode: Starting without reverse proxy" docker_compose $ACTION $BUILD echo "" echo "✅ Orbital Simulator is running in development mode!" echo "🌐 Web Interface: http://localhost:3000" fi echo "" echo "📋 Useful commands:" echo " View logs: $0 --logs" echo " Stop: $0 --down" echo " Health check: docker ps" ;; "down") echo "🛑 Stopping Orbital Simulator..." if [ "$MODE" = "production" ]; then docker_compose --profile production down else docker_compose down fi echo "✅ All containers stopped and removed." ;; "logs") echo "📄 Showing container logs..." if [ "$MODE" = "production" ]; then docker_compose --profile production logs -f else docker_compose logs -f fi ;; esac # Health check function check_health() { echo "🏥 Checking health..." # Wait a moment for containers to start sleep 5 # Check if API is responding if curl -f http://localhost:3000/api/configs &> /dev/null; then echo "✅ API is healthy" else echo "⚠️ API health check failed" echo "🔍 Try: docker ps" echo "🔍 Try: $0 --logs" fi } # Only run health check for 'up' action if [ "$ACTION" = "up" ]; then check_health fi