AudioForge / scripts /presentation_launch.ps1
OnyxlMunkey's picture
c618549
# ============================================
# 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