CoolFace
Apppublic

OnyxMunk/AudioForge

sourceHugging Facemitupdated 8mo agoView on Hugging Face
0likes
presentation_launch.ps1333 linesDownload Raw Back to scripts
1# ============================================
2# AudioForge - Professional Presentation Launch
3# ============================================
4# Enterprise-grade deployment script
5# Author: AudioForge Team
6# Version: 1.0.0
7
8param(
9    [switch]$Clean,
10    [switch]$Build,
11    [switch]$Monitoring
12)
13
14# Colors for output
15$ESC = [char]27
16$GREEN = "$ESC[32m"
17$BLUE = "$ESC[34m"
18$YELLOW = "$ESC[33m"
19$RED = "$ESC[31m"
20$CYAN = "$ESC[36m"
21$MAGENTA = "$ESC[35m"
22$RESET = "$ESC[0m"
23$BOLD = "$ESC[1m"
24
25# Banner
26function Show-Banner {
27    Write-Host ""
28    Write-Host "${CYAN}${BOLD}╔═══════════════════════════════════════════════════════════════╗${RESET}"
29    Write-Host "${CYAN}${BOLD}║                                                               ║${RESET}"
30    Write-Host "${CYAN}${BOLD}║                    ${MAGENTA}🎵 AUDIOFORGE 🎵${CYAN}                        ║${RESET}"
31    Write-Host "${CYAN}${BOLD}║                                                               ║${RESET}"
32    Write-Host "${CYAN}${BOLD}║          ${RESET}Open-Source Text-to-Music Generation Platform${CYAN}        ║${RESET}"
33    Write-Host "${CYAN}${BOLD}║                                                               ║${RESET}"
34    Write-Host "${CYAN}${BOLD}║              ${GREEN}Production-Ready Enterprise Deployment${CYAN}           ║${RESET}"
35    Write-Host "${CYAN}${BOLD}║                                                               ║${RESET}"
36    Write-Host "${CYAN}${BOLD}╚═══════════════════════════════════════════════════════════════╝${RESET}"
37    Write-Host ""
38}
39
40# Status message
41function Write-Status {
42    param([string]$Message)
43    Write-Host "${BLUE}[INFO]${RESET} $Message"
44}
45
46# Success message
47function Write-Success {
48    param([string]$Message)
49    Write-Host "${GREEN}[✓]${RESET} $Message"
50}
51
52# Warning message
53function Write-Warning {
54    param([string]$Message)
55    Write-Host "${YELLOW}[!]${RESET} $Message"
56}
57
58# Error message
59function Write-Error-Custom {
60    param([string]$Message)
61    Write-Host "${RED}[✗]${RESET} $Message"
62}
63
64# Section header
65function Write-Section {
66    param([string]$Title)
67    Write-Host ""
68    Write-Host "${BOLD}${CYAN}═══ $Title ═══${RESET}"
69    Write-Host ""
70}
71
72# Check prerequisites
73function Test-Prerequisites {
74    Write-Section "Checking Prerequisites"
75    
76    $allGood = $true
77    
78    # Check Docker
79    try {
80        $dockerVersion = docker --version
81        Write-Success "Docker: $dockerVersion"
82    } catch {
83        Write-Error-Custom "Docker not found. Please install Docker Desktop."
84        $allGood = $false
85    }
86    
87    # Check Docker Compose
88    try {
89        $composeVersion = docker-compose --version
90        Write-Success "Docker Compose: $composeVersion"
91    } catch {
92        Write-Error-Custom "Docker Compose not found."
93        $allGood = $false
94    }
95    
96    # Check if Docker is running
97    try {
98        docker ps | Out-Null
99        Write-Success "Docker daemon is running"
100    } catch {
101        Write-Error-Custom "Docker daemon is not running. Please start Docker Desktop."
102        $allGood = $false
103    }
104    
105    return $allGood
106}
107
108# Clean up existing containers
109function Invoke-Cleanup {
110    Write-Section "Cleaning Up Previous Deployment"
111    
112    Write-Status "Stopping containers..."
113    docker-compose down -v 2>$null
114    
115    Write-Status "Removing unused images..."
116    docker image prune -f | Out-Null
117    
118    Write-Status "Removing unused volumes..."
119    docker volume prune -f | Out-Null
120    
121    Write-Success "Cleanup complete"
122}
123
124# Build images
125function Invoke-Build {
126    Write-Section "Building Docker Images"
127    
128    Write-Status "Building backend image..."
129    docker-compose build backend
130    
131    Write-Status "Building frontend image..."
132    docker-compose build frontend
133    
134    Write-Success "All images built successfully"
135}
136
137# Start services
138function Start-Services {
139    Write-Section "Starting Services"
140    
141    Write-Status "Starting database layer (PostgreSQL, Redis)..."
142    docker-compose up -d postgres redis
143    Start-Sleep -Seconds 5
144    
145    Write-Status "Starting backend API..."
146    docker-compose up -d backend
147    Start-Sleep -Seconds 10
148    
149    Write-Status "Starting frontend application..."
150    docker-compose up -d frontend
151    
152    Write-Success "All services started"
153}
154
155# Check service health
156function Test-ServiceHealth {
157    Write-Section "Health Check Status"
158    
159    $maxRetries = 30
160    $retryCount = 0
161    
162    # Check PostgreSQL
163    Write-Status "Checking PostgreSQL..."
164    while ($retryCount -lt $maxRetries) {
165        $health = docker inspect --format='{{.State.Health.Status}}' audioforge-postgres 2>$null
166        if ($health -eq "healthy") {
167            Write-Success "PostgreSQL is healthy"
168            break
169        }
170        $retryCount++
171        Start-Sleep -Seconds 2
172    }
173    
174    # Check Redis
175    Write-Status "Checking Redis..."
176    $retryCount = 0
177    while ($retryCount -lt $maxRetries) {
178        $health = docker inspect --format='{{.State.Health.Status}}' audioforge-redis 2>$null
179        if ($health -eq "healthy") {
180            Write-Success "Redis is healthy"
181            break
182        }
183        $retryCount++
184        Start-Sleep -Seconds 2
185    }
186    
187    # Check Backend
188    Write-Status "Checking Backend API..."
189    $retryCount = 0
190    while ($retryCount -lt $maxRetries) {
191        try {
192            $response = Invoke-WebRequest -Uri "http://localhost:8000/health" -UseBasicParsing -TimeoutSec 2 -ErrorAction SilentlyContinue
193            if ($response.StatusCode -eq 200) {
194                Write-Success "Backend API is healthy"
195                break
196            }
197        } catch {
198            # Ignore errors and retry
199        }
200        $retryCount++
201        Start-Sleep -Seconds 2
202    }
203    
204    # Check Frontend
205    Write-Status "Checking Frontend..."
206    $retryCount = 0
207    while ($retryCount -lt $maxRetries) {
208        try {
209            $response = Invoke-WebRequest -Uri "http://localhost:3000" -UseBasicParsing -TimeoutSec 2 -ErrorAction SilentlyContinue
210            if ($response.StatusCode -eq 200) {
211                Write-Success "Frontend is healthy"
212                break
213            }
214        } catch {
215            # Ignore errors and retry
216        }
217        $retryCount++
218        Start-Sleep -Seconds 2
219    }
220}
221
222# Show service status
223function Show-ServiceStatus {
224    Write-Section "Service Status Dashboard"
225    
226    docker-compose ps
227    
228    Write-Host ""
229    Write-Host "${BOLD}Container Resource Usage:${RESET}"
230    docker stats --no-stream --format "table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.NetIO}}"
231}
232
233# Show access information
234function Show-AccessInfo {
235    Write-Section "Access Information"
236    
237    Write-Host "${BOLD}${GREEN}🌐 Application URLs:${RESET}"
238    Write-Host ""
239    Write-Host "  ${CYAN}Frontend Application:${RESET}  http://localhost:3000"
240    Write-Host "  ${CYAN}Backend API:${RESET}           http://localhost:8000"
241    Write-Host "  ${CYAN}API Documentation:${RESET}     http://localhost:8000/docs"
242    Write-Host "  ${CYAN}API Redoc:${RESET}             http://localhost:8000/redoc"
243    Write-Host "  ${CYAN}Health Check:${RESET}          http://localhost:8000/health"
244    Write-Host ""
245    
246    if ($Monitoring) {
247        Write-Host "${BOLD}${YELLOW}📊 Monitoring URLs:${RESET}"
248        Write-Host ""
249        Write-Host "  ${CYAN}Prometheus:${RESET}            http://localhost:9090"
250        Write-Host "  ${CYAN}Grafana:${RESET}               http://localhost:3001"
251        Write-Host "  ${CYAN}Grafana Credentials:${RESET}   admin / admin"
252        Write-Host ""
253    }
254    
255    Write-Host "${BOLD}${MAGENTA}📊 Database Connections:${RESET}"
256    Write-Host ""
257    Write-Host "  ${CYAN}PostgreSQL:${RESET}            localhost:5432"
258    Write-Host "  ${CYAN}Database:${RESET}              audioforge"
259    Write-Host "  ${CYAN}User:${RESET}                  postgres"
260    Write-Host ""
261    Write-Host "  ${CYAN}Redis:${RESET}                 localhost:6379"
262    Write-Host ""
263}
264
265# Show logs
266function Show-Logs {
267    Write-Section "Recent Logs"
268    
269    Write-Host "${CYAN}Backend Logs:${RESET}"
270    docker-compose logs --tail=10 backend
271    
272    Write-Host ""
273    Write-Host "${CYAN}Frontend Logs:${RESET}"
274    docker-compose logs --tail=10 frontend
275}
276
277# Main execution
278function Main {
279    Show-Banner
280    
281    # Check prerequisites
282    if (-not (Test-Prerequisites)) {
283        Write-Error-Custom "Prerequisites check failed. Please resolve issues and try again."
284        exit 1
285    }
286    
287    # Clean up if requested
288    if ($Clean) {
289        Invoke-Cleanup
290    }
291    
292    # Build if requested
293    if ($Build) {
294        Invoke-Build
295    }
296    
297    # Start services
298    Start-Services
299    
300    # Wait for services to be healthy
301    Write-Status "Waiting for services to become healthy..."
302    Start-Sleep -Seconds 15
303    
304    # Check health
305    Test-ServiceHealth
306    
307    # Show status
308    Show-ServiceStatus
309    
310    # Show access info
311    Show-AccessInfo
312    
313    # Show recent logs
314    Show-Logs
315    
316    # Final message
317    Write-Host ""
318    Write-Host "${BOLD}${GREEN}╔═══════════════════════════════════════════════════════════════╗${RESET}"
319    Write-Host "${BOLD}${GREEN}║                                                               ║${RESET}"
320    Write-Host "${BOLD}${GREEN}║              🎉 AUDIOFORGE IS NOW RUNNING! 🎉                 ║${RESET}"
321    Write-Host "${BOLD}${GREEN}║                                                               ║${RESET}"
322    Write-Host "${BOLD}${GREEN}║         Visit http://localhost:3000 to get started            ║${RESET}"
323    Write-Host "${BOLD}${GREEN}║                                                               ║${RESET}"
324    Write-Host "${BOLD}${GREEN}╚═══════════════════════════════════════════════════════════════╝${RESET}"
325    Write-Host ""
326    Write-Host "${YELLOW}Tip: Use 'docker-compose logs -f' to follow logs${RESET}"
327    Write-Host "${YELLOW}Tip: Use 'docker-compose down' to stop all services${RESET}"
328    Write-Host ""
329}
330
331# Run main function
332Main
333