Spaces:
Build error
Build error
| # AudioForge Production Startup Script (Manual - No Docker) | |
| # Starts PostgreSQL/Redis, initializes DB, then starts backend and frontend in production mode | |
| param( | |
| [switch]$SkipServices = $false, | |
| [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 (Manual) | |
| Usage: | |
| .\scripts\prod_start_manual.ps1 [-SkipServices] [-SkipBuild] [-Help] | |
| Options: | |
| -SkipServices Skip starting PostgreSQL/Redis (assume they're already running) | |
| -SkipBuild Skip building frontend (use existing build) | |
| -Help Show this help message | |
| This script will: | |
| 1. Start PostgreSQL and Redis (if not skipped) | |
| 2. Wait for services to be ready | |
| 3. Initialize the database | |
| 4. Build frontend for production (if not skipped) | |
| 5. Start backend server in production mode (4 workers) | |
| 6. Start frontend server in production mode | |
| "@ | |
| exit 0 | |
| } | |
| $ProjectRoot = Split-Path -Parent $PSScriptRoot | |
| Set-Location $ProjectRoot | |
| # Step 1: Start PostgreSQL and Redis | |
| if (-not $SkipServices) { | |
| Write-Info "Starting PostgreSQL and Redis..." | |
| # Check if Docker is available and running | |
| 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" | |
| Write-Info "You can skip this step with -SkipServices if services are already running" | |
| exit 1 | |
| } | |
| } catch { | |
| Write-Error "Cannot connect to Docker daemon!" | |
| Write-Warning "Please start Docker Desktop and try again" | |
| Write-Info "You can skip this step with -SkipServices if services are already running" | |
| exit 1 | |
| } | |
| # Start only postgres and redis services | |
| Write-Info "Starting PostgreSQL and Redis containers..." | |
| docker-compose up -d postgres redis | |
| if ($LASTEXITCODE -ne 0) { | |
| Write-Error "Failed to start services!" | |
| Write-Info "Make sure Docker Desktop is running" | |
| exit 1 | |
| } | |
| Write-Info "Waiting for PostgreSQL to be ready..." | |
| $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 1 | |
| $attempt++ | |
| Write-Host "." -NoNewline | |
| } | |
| } | |
| Write-Host "" | |
| if (-not $postgresReady) { | |
| Write-Error "PostgreSQL failed to start within timeout!" | |
| exit 1 | |
| } | |
| Write-Info "Waiting for Redis to be ready..." | |
| Start-Sleep -Seconds 2 | |
| try { | |
| $null = 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..." | |
| } | |
| } else { | |
| Write-Info "Skipping service startup (assuming PostgreSQL/Redis are running)" | |
| } | |
| # Step 2: Setup Backend Environment | |
| Write-Info "Setting up backend environment..." | |
| Set-Location "$ProjectRoot\backend" | |
| # Check for Python 3.11 venv first (for ML support), then fall back to regular venv | |
| $venvPath = if (Test-Path ".venv311") { ".venv311" } elseif (Test-Path ".venv") { ".venv" } else { $null } | |
| if ($null -eq $venvPath) { | |
| Write-Warning "Virtual environment not found! Creating .venv..." | |
| python -m venv .venv | |
| $venvPath = ".venv" | |
| & "$venvPath\Scripts\Activate.ps1" | |
| pip install -e ".[dev]" | |
| } else { | |
| Write-Info "Using virtual environment: $venvPath" | |
| # Activate venv for subsequent commands | |
| & "$venvPath\Scripts\Activate.ps1" | |
| } | |
| # Step 3: Initialize Database | |
| Write-Info "Initializing database..." | |
| # Check if .env exists | |
| if (-not (Test-Path ".env")) { | |
| Write-Warning ".env file not found! Running setup_env.py..." | |
| Set-Location $ProjectRoot | |
| python scripts/setup_env.py | |
| Set-Location "$ProjectRoot\backend" | |
| } | |
| # Use venv's Python explicitly for database initialization | |
| & "$venvPath\Scripts\python.exe" scripts/init_db.py | |
| if ($LASTEXITCODE -ne 0) { | |
| Write-Error "Database initialization failed!" | |
| Write-Info "Make sure PostgreSQL is running and DATABASE_URL is correct in backend/.env" | |
| exit 1 | |
| } | |
| Write-Success "Database initialized successfully!" | |
| # Step 4: Build Frontend for Production | |
| if (-not $SkipBuild) { | |
| Write-Info "Building frontend for production..." | |
| Set-Location "$ProjectRoot\frontend" | |
| # Check if node_modules exists | |
| if (-not (Test-Path "node_modules")) { | |
| Write-Warning "Frontend dependencies not installed! Installing..." | |
| pnpm install | |
| } | |
| # Ensure .env.local exists | |
| if (-not (Test-Path ".env.local")) { | |
| Write-Info "Creating frontend .env.local..." | |
| "NEXT_PUBLIC_API_URL=http://localhost:8000" | Out-File -FilePath ".env.local" -Encoding UTF8 | |
| } | |
| # Set production environment | |
| $env:NODE_ENV = "production" | |
| Write-Info "Running production build (this may take a few minutes)..." | |
| pnpm build | |
| if ($LASTEXITCODE -ne 0) { | |
| Write-Error "Frontend build failed!" | |
| exit 1 | |
| } | |
| Write-Success "Frontend built successfully!" | |
| } else { | |
| Write-Info "Skipping frontend build (using existing build)" | |
| } | |
| # Step 5: Start Backend in Production Mode | |
| Write-Info "Starting backend server in production mode..." | |
| Set-Location "$ProjectRoot\backend" | |
| # Check for Python 3.11 venv first (for ML support), then fall back to regular venv | |
| $venvPath = if (Test-Path ".venv311") { ".venv311" } elseif (Test-Path ".venv") { ".venv" } else { $null } | |
| if ($null -eq $venvPath) { | |
| Write-Warning "Virtual environment not found! Creating .venv..." | |
| python -m venv .venv | |
| $venvPath = ".venv" | |
| & "$venvPath\Scripts\Activate.ps1" | |
| pip install -e ".[dev]" | |
| } else { | |
| Write-Info "Using virtual environment: $venvPath" | |
| } | |
| # Set production environment variables | |
| $env:ENVIRONMENT = "production" | |
| $env:LOG_LEVEL = "info" | |
| # Start backend in production mode with 4 workers | |
| $backendJob = Start-Process powershell -ArgumentList @( | |
| "-NoExit", | |
| "-Command", | |
| "cd '$ProjectRoot\backend'; `$env:ENVIRONMENT='production'; `$env:LOG_LEVEL='info'; `$venv = if (Test-Path .venv311) { '.venv311' } elseif (Test-Path .venv) { '.venv' } else { `$null }; if (`$venv) { & `"`$venv\Scripts\Activate.ps1`" }; uvicorn app.main:app --host 0.0.0.0 --port 8000 --workers 4 --log-level info" | |
| ) -PassThru | |
| Write-Success "Backend starting in production mode (PID: $($backendJob.Id))" | |
| Write-Info "Backend will be available at http://localhost:8000" | |
| # Step 6: Start Frontend in Production Mode | |
| Write-Info "Starting frontend server in production mode..." | |
| Set-Location "$ProjectRoot\frontend" | |
| # Ensure .env.local exists | |
| if (-not (Test-Path ".env.local")) { | |
| Write-Info "Creating frontend .env.local..." | |
| "NEXT_PUBLIC_API_URL=http://localhost:8000" | Out-File -FilePath ".env.local" -Encoding UTF8 | |
| } | |
| # Set production environment | |
| $env:NODE_ENV = "production" | |
| # Start frontend in production mode | |
| $frontendJob = Start-Process powershell -ArgumentList @( | |
| "-NoExit", | |
| "-Command", | |
| "cd '$ProjectRoot\frontend'; `$env:NODE_ENV='production'; pnpm start" | |
| ) -PassThru | |
| Write-Success "Frontend starting in production mode (PID: $($frontendJob.Id))" | |
| Write-Info "Frontend will be available at http://localhost:3000" | |
| # Wait a bit for services to start | |
| Write-Info "Waiting for services to initialize..." | |
| Start-Sleep -Seconds 10 | |
| # 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 (4 workers)" | |
| Write-Success "Frontend: http://localhost:3000 (production build)" | |
| Write-Success "API Docs: http://localhost:8000/api/docs" | |
| Write-Host "" | |
| Write-Info "Backend and Frontend are running in separate PowerShell windows" | |
| Write-Info "Close those windows to stop the servers" | |
| Write-Host "" | |
| Write-Info "To stop PostgreSQL/Redis: docker-compose down" | |
| Write-Host "" | |
| Write-Info "Ready to test music generation!" | |
| Write-Host "" | |