Spaces:
Build error
Build error
File size: 8,679 Bytes
09fa60b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
# AudioForge Master Launch Script (PowerShell)
# Windows equivalent of launch.sh
param(
[string]$Environment = "development",
[switch]$SkipTests = $false,
[switch]$DryRun = $false,
[switch]$Help = $false
)
# Colors
$Colors = @{
Red = "Red"
Green = "Green"
Yellow = "Yellow"
Blue = "Cyan"
Purple = "Magenta"
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 }
function Write-Step {
Write-Host "`nβββ $args βββ`n" -ForegroundColor $Colors.Purple
}
if ($Help) {
Write-Host @"
AudioForge Master Launch Script
Usage:
.\scripts\launch.ps1 [-Environment ENV] [-SkipTests] [-DryRun] [-Help]
Options:
-Environment ENV Target environment (development|staging|production)
-SkipTests Skip test suite (not recommended for production)
-DryRun Show what would be done without executing
-Help Show this help message
"@
exit 0
}
$ProjectRoot = Split-Path -Parent $PSScriptRoot
function Test-Command {
param([string]$Command)
$null = Get-Command $Command -ErrorAction SilentlyContinue
return $?
}
function Invoke-Step {
param([scriptblock]$Action)
if ($DryRun) {
Write-Host "[DRY-RUN] Would execute: $Action" -ForegroundColor Yellow
} else {
& $Action
}
}
# Verify Prerequisites
Write-Step "Verifying Prerequisites"
if (-not (Test-Command python)) {
Write-Error "Python not found!"
exit 1
}
$pythonVersion = python --version
Write-Info "Python version: $pythonVersion"
if (-not (Test-Command node)) {
Write-Error "Node.js not found!"
exit 1
}
$nodeVersion = node --version
Write-Info "Node version: $nodeVersion"
if (-not (Test-Command pnpm)) {
Write-Warning "pnpm not found, installing..."
npm install -g pnpm
}
Write-Success "All prerequisites satisfied"
# Run Verification
Write-Step "Running Verification Checks"
Set-Location $ProjectRoot
if (-not $DryRun) {
python scripts/launch_verification.py --verbose --json launch-verification.json
if ($LASTEXITCODE -ne 0) {
Write-Error "Verification failed!"
exit 1
}
}
Write-Success "Verification checks passed"
# Setup Environment
Write-Step "Setting Up Environment: $Environment"
if (-not (Test-Path "backend\.env")) {
Write-Warning "Backend .env not found, creating from example..."
Copy-Item "backend\.env.example" "backend\.env"
}
if (-not (Test-Path "frontend\.env.local")) {
Write-Warning "Frontend .env.local not found, creating..."
if ($Environment -eq "production") {
"NEXT_PUBLIC_API_URL=https://api.yourdomain.com" | Out-File -FilePath "frontend\.env.local" -Encoding UTF8
} else {
"NEXT_PUBLIC_API_URL=http://localhost:8000" | Out-File -FilePath "frontend\.env.local" -Encoding UTF8
}
}
Write-Success "Environment configured"
# Install Dependencies
Write-Step "Installing Dependencies"
Write-Info "Installing backend dependencies..."
Set-Location "$ProjectRoot\backend"
Invoke-Step { pip install -e ".[dev]" }
Write-Info "Installing frontend dependencies..."
Set-Location "$ProjectRoot\frontend"
Invoke-Step { pnpm install --frozen-lockfile }
Write-Success "Dependencies installed"
# Run Tests
if (-not $SkipTests) {
Write-Step "Running Test Suite"
Write-Info "Running backend tests..."
Set-Location "$ProjectRoot\backend"
Invoke-Step { pytest tests/ -v --cov=app }
Write-Info "Running frontend tests..."
Set-Location "$ProjectRoot\frontend"
Invoke-Step { pnpm test }
Invoke-Step { pnpm run type-check }
Write-Success "All tests passed"
} else {
Write-Warning "Skipping tests (--SkipTests flag)"
}
# Build Applications
Write-Step "Building Applications"
Write-Info "Building frontend..."
Set-Location "$ProjectRoot\frontend"
Invoke-Step { pnpm run build }
Write-Success "Applications built successfully"
# Setup Database
Write-Step "Setting Up Database"
Set-Location "$ProjectRoot\backend"
Write-Info "Running database migrations..."
Invoke-Step { python scripts/init_db.py }
Write-Success "Database initialized"
# Start Services
Write-Step "Starting Services"
Set-Location $ProjectRoot
if (Test-Command docker-compose) {
Write-Info "Starting services with Docker Compose..."
Invoke-Step { docker-compose up -d }
if (-not $DryRun) {
Write-Info "Waiting for services to be healthy..."
Start-Sleep -Seconds 10
# Check backend health
for ($i = 0; $i -lt 30; $i++) {
try {
$response = Invoke-WebRequest -Uri "http://localhost:8000/health" -UseBasicParsing -ErrorAction SilentlyContinue
if ($response.StatusCode -eq 200) {
Write-Success "Backend is healthy"
break
}
} catch {}
Start-Sleep -Seconds 2
}
# Check frontend health
for ($i = 0; $i -lt 30; $i++) {
try {
$response = Invoke-WebRequest -Uri "http://localhost:3000" -UseBasicParsing -ErrorAction SilentlyContinue
if ($response.StatusCode -eq 200) {
Write-Success "Frontend is healthy"
break
}
} catch {}
Start-Sleep -Seconds 2
}
}
} else {
Write-Warning "Docker Compose not available, starting services manually..."
Write-Info "Starting backend..."
Set-Location "$ProjectRoot\backend"
Start-Process -FilePath "uvicorn" -ArgumentList "app.main:app --host 0.0.0.0 --port 8000" -NoNewWindow
Write-Info "Starting frontend..."
Set-Location "$ProjectRoot\frontend"
Start-Process -FilePath "pnpm" -ArgumentList "start" -NoNewWindow
}
Write-Success "Services started"
# Generate Report
Write-Step "Generating Launch Report"
Set-Location $ProjectRoot
Invoke-Step { python scripts/generate_launch_report.py }
Write-Success "Launch report generated: LAUNCH_REPORT.html"
# Post-Launch Verification
Write-Step "Post-Launch Verification"
if (-not $DryRun) {
Write-Info "Testing backend endpoint..."
try {
$response = Invoke-WebRequest -Uri "http://localhost:8000/health" -UseBasicParsing
Write-Success "Backend responding"
} catch {
Write-Error "Backend not responding"
exit 1
}
Write-Info "Testing frontend..."
try {
$response = Invoke-WebRequest -Uri "http://localhost:3000" -UseBasicParsing
Write-Success "Frontend responding"
} catch {
Write-Error "Frontend not responding"
exit 1
}
}
Write-Success "Post-launch verification complete"
# Success Message
Write-Host "`n" -NoNewline
Write-Host "βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ" -ForegroundColor Green
Write-Host "β β" -ForegroundColor Green
Write-Host "β π LAUNCH SUCCESSFUL! π β" -ForegroundColor Green
Write-Host "β β" -ForegroundColor Green
Write-Host "β AudioForge is now running and ready! β" -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/docs"
Write-Success "Launch Report: file://$ProjectRoot/LAUNCH_REPORT.html"
Write-Host ""
if ($Environment -eq "production") {
Write-Warning "Production deployment complete. Monitor logs and metrics closely."
}
Write-Info "πΌβ‘ The panda has spoken. The launch is complete. π΅"
|