File size: 10,951 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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
# ============================================
# AudioForge - Professional Presentation Launch
# ============================================
# Enterprise-grade deployment script
# Author: AudioForge Team
# Version: 1.0.0

param(
    [switch]$Clean,
    [switch]$Build,
    [switch]$Monitoring
)

# Colors for output
$ESC = [char]27
$GREEN = "$ESC[32m"
$BLUE = "$ESC[34m"
$YELLOW = "$ESC[33m"
$RED = "$ESC[31m"
$CYAN = "$ESC[36m"
$MAGENTA = "$ESC[35m"
$RESET = "$ESC[0m"
$BOLD = "$ESC[1m"

# Banner
function Show-Banner {
    Write-Host ""
    Write-Host "${CYAN}${BOLD}╔═══════════════════════════════════════════════════════════════╗${RESET}"
    Write-Host "${CYAN}${BOLD}β•‘                                                               β•‘${RESET}"
    Write-Host "${CYAN}${BOLD}β•‘                    ${MAGENTA}🎡 AUDIOFORGE 🎡${CYAN}                        β•‘${RESET}"
    Write-Host "${CYAN}${BOLD}β•‘                                                               β•‘${RESET}"
    Write-Host "${CYAN}${BOLD}β•‘          ${RESET}Open-Source Text-to-Music Generation Platform${CYAN}        β•‘${RESET}"
    Write-Host "${CYAN}${BOLD}β•‘                                                               β•‘${RESET}"
    Write-Host "${CYAN}${BOLD}β•‘              ${GREEN}Production-Ready Enterprise Deployment${CYAN}           β•‘${RESET}"
    Write-Host "${CYAN}${BOLD}β•‘                                                               β•‘${RESET}"
    Write-Host "${CYAN}${BOLD}β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•${RESET}"
    Write-Host ""
}

# Status message
function Write-Status {
    param([string]$Message)
    Write-Host "${BLUE}[INFO]${RESET} $Message"
}

# Success message
function Write-Success {
    param([string]$Message)
    Write-Host "${GREEN}[βœ“]${RESET} $Message"
}

# Warning message
function Write-Warning {
    param([string]$Message)
    Write-Host "${YELLOW}[!]${RESET} $Message"
}

# Error message
function Write-Error-Custom {
    param([string]$Message)
    Write-Host "${RED}[βœ—]${RESET} $Message"
}

# Section header
function Write-Section {
    param([string]$Title)
    Write-Host ""
    Write-Host "${BOLD}${CYAN}═══ $Title ═══${RESET}"
    Write-Host ""
}

# Check prerequisites
function Test-Prerequisites {
    Write-Section "Checking Prerequisites"
    
    $allGood = $true
    
    # Check Docker
    try {
        $dockerVersion = docker --version
        Write-Success "Docker: $dockerVersion"
    } catch {
        Write-Error-Custom "Docker not found. Please install Docker Desktop."
        $allGood = $false
    }
    
    # Check Docker Compose
    try {
        $composeVersion = docker-compose --version
        Write-Success "Docker Compose: $composeVersion"
    } catch {
        Write-Error-Custom "Docker Compose not found."
        $allGood = $false
    }
    
    # Check if Docker is running
    try {
        docker ps | Out-Null
        Write-Success "Docker daemon is running"
    } catch {
        Write-Error-Custom "Docker daemon is not running. Please start Docker Desktop."
        $allGood = $false
    }
    
    return $allGood
}

# Clean up existing containers
function Invoke-Cleanup {
    Write-Section "Cleaning Up Previous Deployment"
    
    Write-Status "Stopping containers..."
    docker-compose down -v 2>$null
    
    Write-Status "Removing unused images..."
    docker image prune -f | Out-Null
    
    Write-Status "Removing unused volumes..."
    docker volume prune -f | Out-Null
    
    Write-Success "Cleanup complete"
}

# Build images
function Invoke-Build {
    Write-Section "Building Docker Images"
    
    Write-Status "Building backend image..."
    docker-compose build backend
    
    Write-Status "Building frontend image..."
    docker-compose build frontend
    
    Write-Success "All images built successfully"
}

# Start services
function Start-Services {
    Write-Section "Starting Services"
    
    Write-Status "Starting database layer (PostgreSQL, Redis)..."
    docker-compose up -d postgres redis
    Start-Sleep -Seconds 5
    
    Write-Status "Starting backend API..."
    docker-compose up -d backend
    Start-Sleep -Seconds 10
    
    Write-Status "Starting frontend application..."
    docker-compose up -d frontend
    
    Write-Success "All services started"
}

# Check service health
function Test-ServiceHealth {
    Write-Section "Health Check Status"
    
    $maxRetries = 30
    $retryCount = 0
    
    # Check PostgreSQL
    Write-Status "Checking PostgreSQL..."
    while ($retryCount -lt $maxRetries) {
        $health = docker inspect --format='{{.State.Health.Status}}' audioforge-postgres 2>$null
        if ($health -eq "healthy") {
            Write-Success "PostgreSQL is healthy"
            break
        }
        $retryCount++
        Start-Sleep -Seconds 2
    }
    
    # Check Redis
    Write-Status "Checking Redis..."
    $retryCount = 0
    while ($retryCount -lt $maxRetries) {
        $health = docker inspect --format='{{.State.Health.Status}}' audioforge-redis 2>$null
        if ($health -eq "healthy") {
            Write-Success "Redis is healthy"
            break
        }
        $retryCount++
        Start-Sleep -Seconds 2
    }
    
    # Check Backend
    Write-Status "Checking Backend API..."
    $retryCount = 0
    while ($retryCount -lt $maxRetries) {
        try {
            $response = Invoke-WebRequest -Uri "http://localhost:8000/health" -UseBasicParsing -TimeoutSec 2 -ErrorAction SilentlyContinue
            if ($response.StatusCode -eq 200) {
                Write-Success "Backend API is healthy"
                break
            }
        } catch {
            # Ignore errors and retry
        }
        $retryCount++
        Start-Sleep -Seconds 2
    }
    
    # Check Frontend
    Write-Status "Checking Frontend..."
    $retryCount = 0
    while ($retryCount -lt $maxRetries) {
        try {
            $response = Invoke-WebRequest -Uri "http://localhost:3000" -UseBasicParsing -TimeoutSec 2 -ErrorAction SilentlyContinue
            if ($response.StatusCode -eq 200) {
                Write-Success "Frontend is healthy"
                break
            }
        } catch {
            # Ignore errors and retry
        }
        $retryCount++
        Start-Sleep -Seconds 2
    }
}

# Show service status
function Show-ServiceStatus {
    Write-Section "Service Status Dashboard"
    
    docker-compose ps
    
    Write-Host ""
    Write-Host "${BOLD}Container Resource Usage:${RESET}"
    docker stats --no-stream --format "table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.NetIO}}"
}

# Show access information
function Show-AccessInfo {
    Write-Section "Access Information"
    
    Write-Host "${BOLD}${GREEN}🌐 Application URLs:${RESET}"
    Write-Host ""
    Write-Host "  ${CYAN}Frontend Application:${RESET}  http://localhost:3000"
    Write-Host "  ${CYAN}Backend API:${RESET}           http://localhost:8000"
    Write-Host "  ${CYAN}API Documentation:${RESET}     http://localhost:8000/docs"
    Write-Host "  ${CYAN}API Redoc:${RESET}             http://localhost:8000/redoc"
    Write-Host "  ${CYAN}Health Check:${RESET}          http://localhost:8000/health"
    Write-Host ""
    
    if ($Monitoring) {
        Write-Host "${BOLD}${YELLOW}πŸ“Š Monitoring URLs:${RESET}"
        Write-Host ""
        Write-Host "  ${CYAN}Prometheus:${RESET}            http://localhost:9090"
        Write-Host "  ${CYAN}Grafana:${RESET}               http://localhost:3001"
        Write-Host "  ${CYAN}Grafana Credentials:${RESET}   admin / admin"
        Write-Host ""
    }
    
    Write-Host "${BOLD}${MAGENTA}πŸ“Š Database Connections:${RESET}"
    Write-Host ""
    Write-Host "  ${CYAN}PostgreSQL:${RESET}            localhost:5432"
    Write-Host "  ${CYAN}Database:${RESET}              audioforge"
    Write-Host "  ${CYAN}User:${RESET}                  postgres"
    Write-Host ""
    Write-Host "  ${CYAN}Redis:${RESET}                 localhost:6379"
    Write-Host ""
}

# Show logs
function Show-Logs {
    Write-Section "Recent Logs"
    
    Write-Host "${CYAN}Backend Logs:${RESET}"
    docker-compose logs --tail=10 backend
    
    Write-Host ""
    Write-Host "${CYAN}Frontend Logs:${RESET}"
    docker-compose logs --tail=10 frontend
}

# Main execution
function Main {
    Show-Banner
    
    # Check prerequisites
    if (-not (Test-Prerequisites)) {
        Write-Error-Custom "Prerequisites check failed. Please resolve issues and try again."
        exit 1
    }
    
    # Clean up if requested
    if ($Clean) {
        Invoke-Cleanup
    }
    
    # Build if requested
    if ($Build) {
        Invoke-Build
    }
    
    # Start services
    Start-Services
    
    # Wait for services to be healthy
    Write-Status "Waiting for services to become healthy..."
    Start-Sleep -Seconds 15
    
    # Check health
    Test-ServiceHealth
    
    # Show status
    Show-ServiceStatus
    
    # Show access info
    Show-AccessInfo
    
    # Show recent logs
    Show-Logs
    
    # Final message
    Write-Host ""
    Write-Host "${BOLD}${GREEN}╔═══════════════════════════════════════════════════════════════╗${RESET}"
    Write-Host "${BOLD}${GREEN}β•‘                                                               β•‘${RESET}"
    Write-Host "${BOLD}${GREEN}β•‘              πŸŽ‰ AUDIOFORGE IS NOW RUNNING! πŸŽ‰                 β•‘${RESET}"
    Write-Host "${BOLD}${GREEN}β•‘                                                               β•‘${RESET}"
    Write-Host "${BOLD}${GREEN}β•‘         Visit http://localhost:3000 to get started            β•‘${RESET}"
    Write-Host "${BOLD}${GREEN}β•‘                                                               β•‘${RESET}"
    Write-Host "${BOLD}${GREEN}β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•${RESET}"
    Write-Host ""
    Write-Host "${YELLOW}Tip: Use 'docker-compose logs -f' to follow logs${RESET}"
    Write-Host "${YELLOW}Tip: Use 'docker-compose down' to stop all services${RESET}"
    Write-Host ""
}

# Run main function
Main