CoolFace
Apppublic

OnyxMunk/AudioForge

sourceHugging Facemitupdated 8mo agoView on Hugging Face
0likes
prod_start.ps1223 linesDownload Raw Back to scripts
1# AudioForge Production Startup Script
2# Starts all services in production mode using Docker Compose
3
4param(
5    [switch]$SkipBuild = $false,
6    [switch]$Help = $false
7)
8
9$Colors = @{
10    Red = "Red"
11    Green = "Green"
12    Yellow = "Yellow"
13    Blue = "Cyan"
14    Cyan = "Cyan"
15}
16
17function Write-Info { Write-Host "[INFO] $args" -ForegroundColor $Colors.Blue }
18function Write-Success { Write-Host "[SUCCESS] $args" -ForegroundColor $Colors.Green }
19function Write-Warning { Write-Host "[WARNING] $args" -ForegroundColor $Colors.Yellow }
20function Write-Error { Write-Host "[ERROR] $args" -ForegroundColor $Colors.Red }
21
22if ($Help) {
23    Write-Host @"
24AudioForge Production Startup Script
25
26Usage:
27    .\scripts\prod_start.ps1 [-SkipBuild] [-Help]
28
29Options:
30    -SkipBuild    Skip building Docker images (use existing images)
31    -Help         Show this help message
32
33This script will:
341. Build Docker images (unless skipped)
352. Start all services in production mode
363. Wait for services to be ready
374. Display service URLs and status
38"@
39    exit 0
40}
41
42$ProjectRoot = Split-Path -Parent $PSScriptRoot
43Set-Location $ProjectRoot
44
45# Check if Docker is available
46Write-Info "Checking Docker availability..."
47try {
48    $null = docker ps 2>&1 | Out-Null
49    if ($LASTEXITCODE -ne 0) {
50        Write-Error "Docker Desktop is not running!"
51        Write-Warning "Please start Docker Desktop and try again"
52        exit 1
53    }
54} catch {
55    Write-Error "Cannot connect to Docker daemon!"
56    Write-Warning "Please start Docker Desktop and try again"
57    exit 1
58}
59
60Write-Success "Docker is running"
61
62# Step 1: Build Docker images (if not skipped)
63if (-not $SkipBuild) {
64    Write-Info "Building Docker images for production..."
65    Write-Info "This may take several minutes on first run..."
66    
67    docker-compose build --no-cache
68    
69    if ($LASTEXITCODE -ne 0) {
70        Write-Error "Failed to build Docker images!"
71        exit 1
72    }
73    
74    Write-Success "Docker images built successfully!"
75} else {
76    Write-Info "Skipping Docker build (using existing images)"
77}
78
79# Step 2: Start all services
80Write-Info "Starting AudioForge in production mode..."
81docker-compose up -d
82
83if ($LASTEXITCODE -ne 0) {
84    Write-Error "Failed to start services!"
85    exit 1
86}
87
88Write-Success "Services started!"
89
90# Step 3: Wait for services to be ready
91Write-Info "Waiting for services to be ready..."
92Start-Sleep -Seconds 10
93
94# Check PostgreSQL
95Write-Info "Checking PostgreSQL..."
96$maxAttempts = 30
97$attempt = 0
98$postgresReady = $false
99
100while ($attempt -lt $maxAttempts -and -not $postgresReady) {
101    try {
102        $result = docker exec audioforge-postgres pg_isready -U postgres 2>&1
103        if ($LASTEXITCODE -eq 0) {
104            $postgresReady = $true
105            Write-Success "PostgreSQL is ready!"
106        }
107    } catch {
108        # Continue waiting
109    }
110    
111    if (-not $postgresReady) {
112        Start-Sleep -Seconds 2
113        $attempt++
114        Write-Host "." -NoNewline
115    }
116}
117
118Write-Host ""
119
120if (-not $postgresReady) {
121    Write-Warning "PostgreSQL health check timed out, but continuing..."
122}
123
124# Check Redis
125Write-Info "Checking Redis..."
126try {
127    $result = docker exec audioforge-redis redis-cli ping 2>&1
128    if ($LASTEXITCODE -eq 0) {
129        Write-Success "Redis is ready!"
130    }
131} catch {
132    Write-Warning "Redis health check failed, but continuing..."
133}
134
135# Check Backend
136Write-Info "Checking Backend API..."
137$maxAttempts = 30
138$attempt = 0
139$backendReady = $false
140
141while ($attempt -lt $maxAttempts -and -not $backendReady) {
142    try {
143        $response = Invoke-WebRequest -Uri "http://localhost:8000/health" -TimeoutSec 5 -UseBasicParsing -ErrorAction SilentlyContinue
144        if ($response.StatusCode -eq 200) {
145            $backendReady = $true
146            Write-Success "Backend API is ready!"
147        }
148    } catch {
149        # Continue waiting
150    }
151    
152    if (-not $backendReady) {
153        Start-Sleep -Seconds 2
154        $attempt++
155        Write-Host "." -NoNewline
156    }
157}
158
159Write-Host ""
160
161if (-not $backendReady) {
162    Write-Warning "Backend health check timed out, but continuing..."
163}
164
165# Check Frontend
166Write-Info "Checking Frontend..."
167$maxAttempts = 20
168$attempt = 0
169$frontendReady = $false
170
171while ($attempt -lt $maxAttempts -and -not $frontendReady) {
172    try {
173        $response = Invoke-WebRequest -Uri "http://localhost:3000" -TimeoutSec 5 -UseBasicParsing -ErrorAction SilentlyContinue
174        if ($response.StatusCode -eq 200) {
175            $frontendReady = $true
176            Write-Success "Frontend is ready!"
177        }
178    } catch {
179        # Continue waiting
180    }
181    
182    if (-not $frontendReady) {
183        Start-Sleep -Seconds 2
184        $attempt++
185        Write-Host "." -NoNewline
186    }
187}
188
189Write-Host ""
190
191if (-not $frontendReady) {
192    Write-Warning "Frontend health check timed out, but continuing..."
193}
194
195# Step 4: Initialize database (if needed)
196Write-Info "Initializing database..."
197docker exec audioforge-backend python scripts/init_db.py
198
199if ($LASTEXITCODE -eq 0) {
200    Write-Success "Database initialized!"
201} else {
202    Write-Warning "Database initialization may have failed (might already be initialized)"
203}
204
205# Final status
206Write-Host ""
207Write-Host "╔═══════════════════════════════════════════════════════════╗" -ForegroundColor Green
208Write-Host "║                                                           ║" -ForegroundColor Green
209Write-Host "║      🎉 AudioForge Production Mode Started! 🎉            ║" -ForegroundColor Green
210Write-Host "║                                                           ║" -ForegroundColor Green
211Write-Host "╚═══════════════════════════════════════════════════════════╝" -ForegroundColor Green
212Write-Host ""
213Write-Success "Backend:  http://localhost:8000"
214Write-Success "Frontend: http://localhost:3000"
215Write-Success "API Docs: http://localhost:8000/api/docs"
216Write-Host ""
217Write-Info "View logs: docker-compose logs -f"
218Write-Info "Stop services: docker-compose down"
219Write-Info "View status: docker-compose ps"
220Write-Host ""
221Write-Info "Ready to test music generation!"
222Write-Host ""
223