Spaces:
Build error
Build error
| # AudioForge Production Startup Script | |
| # Starts all services in production mode using Docker Compose | |
| param( | |
| [switch]$SkipBuild = $false, | |
| [switch]$Help = $false | |
| ) | |
| $Colors = @{ | |
| Red = "Red" | |
| Green = "Green" | |
| Yellow = "Yellow" | |
| Blue = "Cyan" | |
| Cyan = "Cyan" | |
| } | |
| function Write-Info { Write-Host "[INFO] $args" -ForegroundColor $Colors.Blue } | |
| function Write-Success { Write-Host "[SUCCESS] $args" -ForegroundColor $Colors.Green } | |
| function Write-Warning { Write-Host "[WARNING] $args" -ForegroundColor $Colors.Yellow } | |
| function Write-Error { Write-Host "[ERROR] $args" -ForegroundColor $Colors.Red } | |
| if ($Help) { | |
| Write-Host @" | |
| AudioForge Production Startup Script | |
| Usage: | |
| .\scripts\prod_start.ps1 [-SkipBuild] [-Help] | |
| Options: | |
| -SkipBuild Skip building Docker images (use existing images) | |
| -Help Show this help message | |
| This script will: | |
| 1. Build Docker images (unless skipped) | |
| 2. Start all services in production mode | |
| 3. Wait for services to be ready | |
| 4. Display service URLs and status | |
| "@ | |
| exit 0 | |
| } | |
| $ProjectRoot = Split-Path -Parent $PSScriptRoot | |
| Set-Location $ProjectRoot | |
| # Check if Docker is available | |
| Write-Info "Checking Docker availability..." | |
| try { | |
| $null = docker ps 2>&1 | Out-Null | |
| if ($LASTEXITCODE -ne 0) { | |
| Write-Error "Docker Desktop is not running!" | |
| Write-Warning "Please start Docker Desktop and try again" | |
| exit 1 | |
| } | |
| } catch { | |
| Write-Error "Cannot connect to Docker daemon!" | |
| Write-Warning "Please start Docker Desktop and try again" | |
| exit 1 | |
| } | |
| Write-Success "Docker is running" | |
| # Step 1: Build Docker images (if not skipped) | |
| if (-not $SkipBuild) { | |
| Write-Info "Building Docker images for production..." | |
| Write-Info "This may take several minutes on first run..." | |
| docker-compose build --no-cache | |
| if ($LASTEXITCODE -ne 0) { | |
| Write-Error "Failed to build Docker images!" | |
| exit 1 | |
| } | |
| Write-Success "Docker images built successfully!" | |
| } else { | |
| Write-Info "Skipping Docker build (using existing images)" | |
| } | |
| # Step 2: Start all services | |
| Write-Info "Starting AudioForge in production mode..." | |
| docker-compose up -d | |
| if ($LASTEXITCODE -ne 0) { | |
| Write-Error "Failed to start services!" | |
| exit 1 | |
| } | |
| Write-Success "Services started!" | |
| # Step 3: Wait for services to be ready | |
| Write-Info "Waiting for services to be ready..." | |
| Start-Sleep -Seconds 10 | |
| # Check PostgreSQL | |
| Write-Info "Checking PostgreSQL..." | |
| $maxAttempts = 30 | |
| $attempt = 0 | |
| $postgresReady = $false | |
| while ($attempt -lt $maxAttempts -and -not $postgresReady) { | |
| try { | |
| $result = docker exec audioforge-postgres pg_isready -U postgres 2>&1 | |
| if ($LASTEXITCODE -eq 0) { | |
| $postgresReady = $true | |
| Write-Success "PostgreSQL is ready!" | |
| } | |
| } catch { | |
| # Continue waiting | |
| } | |
| if (-not $postgresReady) { | |
| Start-Sleep -Seconds 2 | |
| $attempt++ | |
| Write-Host "." -NoNewline | |
| } | |
| } | |
| Write-Host "" | |
| if (-not $postgresReady) { | |
| Write-Warning "PostgreSQL health check timed out, but continuing..." | |
| } | |
| # Check Redis | |
| Write-Info "Checking Redis..." | |
| try { | |
| $result = docker exec audioforge-redis redis-cli ping 2>&1 | |
| if ($LASTEXITCODE -eq 0) { | |
| Write-Success "Redis is ready!" | |
| } | |
| } catch { | |
| Write-Warning "Redis health check failed, but continuing..." | |
| } | |
| # Check Backend | |
| Write-Info "Checking Backend API..." | |
| $maxAttempts = 30 | |
| $attempt = 0 | |
| $backendReady = $false | |
| while ($attempt -lt $maxAttempts -and -not $backendReady) { | |
| try { | |
| $response = Invoke-WebRequest -Uri "http://localhost:8000/health" -TimeoutSec 5 -UseBasicParsing -ErrorAction SilentlyContinue | |
| if ($response.StatusCode -eq 200) { | |
| $backendReady = $true | |
| Write-Success "Backend API is ready!" | |
| } | |
| } catch { | |
| # Continue waiting | |
| } | |
| if (-not $backendReady) { | |
| Start-Sleep -Seconds 2 | |
| $attempt++ | |
| Write-Host "." -NoNewline | |
| } | |
| } | |
| Write-Host "" | |
| if (-not $backendReady) { | |
| Write-Warning "Backend health check timed out, but continuing..." | |
| } | |
| # Check Frontend | |
| Write-Info "Checking Frontend..." | |
| $maxAttempts = 20 | |
| $attempt = 0 | |
| $frontendReady = $false | |
| while ($attempt -lt $maxAttempts -and -not $frontendReady) { | |
| try { | |
| $response = Invoke-WebRequest -Uri "http://localhost:3000" -TimeoutSec 5 -UseBasicParsing -ErrorAction SilentlyContinue | |
| if ($response.StatusCode -eq 200) { | |
| $frontendReady = $true | |
| Write-Success "Frontend is ready!" | |
| } | |
| } catch { | |
| # Continue waiting | |
| } | |
| if (-not $frontendReady) { | |
| Start-Sleep -Seconds 2 | |
| $attempt++ | |
| Write-Host "." -NoNewline | |
| } | |
| } | |
| Write-Host "" | |
| if (-not $frontendReady) { | |
| Write-Warning "Frontend health check timed out, but continuing..." | |
| } | |
| # Step 4: Initialize database (if needed) | |
| Write-Info "Initializing database..." | |
| docker exec audioforge-backend python scripts/init_db.py | |
| if ($LASTEXITCODE -eq 0) { | |
| Write-Success "Database initialized!" | |
| } else { | |
| Write-Warning "Database initialization may have failed (might already be initialized)" | |
| } | |
| # Final status | |
| Write-Host "" | |
| Write-Host "βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ" -ForegroundColor Green | |
| Write-Host "β β" -ForegroundColor Green | |
| Write-Host "β π AudioForge Production Mode Started! π β" -ForegroundColor Green | |
| Write-Host "β β" -ForegroundColor Green | |
| Write-Host "βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ" -ForegroundColor Green | |
| Write-Host "" | |
| Write-Success "Backend: http://localhost:8000" | |
| Write-Success "Frontend: http://localhost:3000" | |
| Write-Success "API Docs: http://localhost:8000/api/docs" | |
| Write-Host "" | |
| Write-Info "View logs: docker-compose logs -f" | |
| Write-Info "Stop services: docker-compose down" | |
| Write-Info "View status: docker-compose ps" | |
| Write-Host "" | |
| Write-Info "Ready to test music generation!" | |
| Write-Host "" | |