OnyxMunk/AudioForge
0
1#!/bin/bash2 3# ============================================4# AudioForge - Professional Presentation Launch5# ============================================6# Enterprise-grade deployment script7# Author: AudioForge Team8# Version: 1.0.09 10set -e11 12# Colors13GREEN='\033[0;32m'14BLUE='\033[0;34m'15YELLOW='\033[1;33m'16RED='\033[0;31m'17CYAN='\033[0;36m'18MAGENTA='\033[0;35m'19BOLD='\033[1m'20RESET='\033[0m'21 22# Parse arguments23CLEAN=false24BUILD=false25MONITORING=false26 27while [[ $# -gt 0 ]]; do28 case $1 in29 --clean) CLEAN=true; shift ;;30 --build) BUILD=true; shift ;;31 --monitoring) MONITORING=true; shift ;;32 *) echo "Unknown option: $1"; exit 1 ;;33 esac34done35 36# Banner37show_banner() {38 echo ""39 echo -e "${CYAN}${BOLD}╔═══════════════════════════════════════════════════════════════╗${RESET}"40 echo -e "${CYAN}${BOLD}║ ║${RESET}"41 echo -e "${CYAN}${BOLD}║ ${MAGENTA}🎵 AUDIOFORGE 🎵${CYAN} ║${RESET}"42 echo -e "${CYAN}${BOLD}║ ║${RESET}"43 echo -e "${CYAN}${BOLD}║ ${RESET}Open-Source Text-to-Music Generation Platform${CYAN} ║${RESET}"44 echo -e "${CYAN}${BOLD}║ ║${RESET}"45 echo -e "${CYAN}${BOLD}║ ${GREEN}Production-Ready Enterprise Deployment${CYAN} ║${RESET}"46 echo -e "${CYAN}${BOLD}║ ║${RESET}"47 echo -e "${CYAN}${BOLD}╚═══════════════════════════════════════════════════════════════╝${RESET}"48 echo ""49}50 51# Status messages52status() { echo -e "${BLUE}[INFO]${RESET} $1"; }53success() { echo -e "${GREEN}[✓]${RESET} $1"; }54warning() { echo -e "${YELLOW}[!]${RESET} $1"; }55error() { echo -e "${RED}[✗]${RESET} $1"; }56section() { echo ""; echo -e "${BOLD}${CYAN}═══ $1 ═══${RESET}"; echo ""; }57 58# Check prerequisites59check_prerequisites() {60 section "Checking Prerequisites"61 62 local all_good=true63 64 # Check Docker65 if command -v docker &> /dev/null; then66 success "Docker: $(docker --version)"67 else68 error "Docker not found. Please install Docker."69 all_good=false70 fi71 72 # Check Docker Compose73 if command -v docker-compose &> /dev/null; then74 success "Docker Compose: $(docker-compose --version)"75 else76 error "Docker Compose not found."77 all_good=false78 fi79 80 # Check if Docker is running81 if docker ps &> /dev/null; then82 success "Docker daemon is running"83 else84 error "Docker daemon is not running. Please start Docker."85 all_good=false86 fi87 88 if [ "$all_good" = false ]; then89 error "Prerequisites check failed. Please resolve issues and try again."90 exit 191 fi92}93 94# Clean up95cleanup() {96 section "Cleaning Up Previous Deployment"97 98 status "Stopping containers..."99 docker-compose down -v 2>/dev/null || true100 101 status "Removing unused images..."102 docker image prune -f > /dev/null103 104 status "Removing unused volumes..."105 docker volume prune -f > /dev/null106 107 success "Cleanup complete"108}109 110# Build images111build_images() {112 section "Building Docker Images"113 114 status "Building backend image..."115 docker-compose build backend116 117 status "Building frontend image..."118 docker-compose build frontend119 120 success "All images built successfully"121}122 123# Start services124start_services() {125 section "Starting Services"126 127 status "Starting database layer (PostgreSQL, Redis)..."128 docker-compose up -d postgres redis129 sleep 5130 131 status "Starting backend API..."132 docker-compose up -d backend133 sleep 10134 135 status "Starting frontend application..."136 docker-compose up -d frontend137 138 success "All services started"139}140 141# Check service health142check_health() {143 section "Health Check Status"144 145 local max_retries=30146 local retry_count=0147 148 # Check PostgreSQL149 status "Checking PostgreSQL..."150 retry_count=0151 while [ $retry_count -lt $max_retries ]; do152 health=$(docker inspect --format='{{.State.Health.Status}}' audioforge-postgres 2>/dev/null || echo "starting")153 if [ "$health" = "healthy" ]; then154 success "PostgreSQL is healthy"155 break156 fi157 ((retry_count++))158 sleep 2159 done160 161 # Check Redis162 status "Checking Redis..."163 retry_count=0164 while [ $retry_count -lt $max_retries ]; do165 health=$(docker inspect --format='{{.State.Health.Status}}' audioforge-redis 2>/dev/null || echo "starting")166 if [ "$health" = "healthy" ]; then167 success "Redis is healthy"168 break169 fi170 ((retry_count++))171 sleep 2172 done173 174 # Check Backend175 status "Checking Backend API..."176 retry_count=0177 while [ $retry_count -lt $max_retries ]; do178 if curl -sf http://localhost:8000/health > /dev/null 2>&1; then179 success "Backend API is healthy"180 break181 fi182 ((retry_count++))183 sleep 2184 done185 186 # Check Frontend187 status "Checking Frontend..."188 retry_count=0189 while [ $retry_count -lt $max_retries ]; do190 if curl -sf http://localhost:3000 > /dev/null 2>&1; then191 success "Frontend is healthy"192 break193 fi194 ((retry_count++))195 sleep 2196 done197}198 199# Show service status200show_status() {201 section "Service Status Dashboard"202 203 docker-compose ps204 205 echo ""206 echo -e "${BOLD}Container Resource Usage:${RESET}"207 docker stats --no-stream --format "table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.NetIO}}"208}209 210# Show access information211show_access_info() {212 section "Access Information"213 214 echo -e "${BOLD}${GREEN}🌐 Application URLs:${RESET}"215 echo ""216 echo -e " ${CYAN}Frontend Application:${RESET} http://localhost:3000"217 echo -e " ${CYAN}Backend API:${RESET} http://localhost:8000"218 echo -e " ${CYAN}API Documentation:${RESET} http://localhost:8000/docs"219 echo -e " ${CYAN}API Redoc:${RESET} http://localhost:8000/redoc"220 echo -e " ${CYAN}Health Check:${RESET} http://localhost:8000/health"221 echo ""222 223 if [ "$MONITORING" = true ]; then224 echo -e "${BOLD}${YELLOW}📊 Monitoring URLs:${RESET}"225 echo ""226 echo -e " ${CYAN}Prometheus:${RESET} http://localhost:9090"227 echo -e " ${CYAN}Grafana:${RESET} http://localhost:3001"228 echo -e " ${CYAN}Grafana Credentials:${RESET} admin / admin"229 echo ""230 fi231 232 echo -e "${BOLD}${MAGENTA}📊 Database Connections:${RESET}"233 echo ""234 echo -e " ${CYAN}PostgreSQL:${RESET} localhost:5432"235 echo -e " ${CYAN}Database:${RESET} audioforge"236 echo -e " ${CYAN}User:${RESET} postgres"237 echo ""238 echo -e " ${CYAN}Redis:${RESET} localhost:6379"239 echo ""240}241 242# Show logs243show_logs() {244 section "Recent Logs"245 246 echo -e "${CYAN}Backend Logs:${RESET}"247 docker-compose logs --tail=10 backend248 249 echo ""250 echo -e "${CYAN}Frontend Logs:${RESET}"251 docker-compose logs --tail=10 frontend252}253 254# Main execution255main() {256 show_banner257 258 # Check prerequisites259 check_prerequisites260 261 # Clean up if requested262 if [ "$CLEAN" = true ]; then263 cleanup264 fi265 266 # Build if requested267 if [ "$BUILD" = true ]; then268 build_images269 fi270 271 # Start services272 start_services273 274 # Wait for services to be healthy275 status "Waiting for services to become healthy..."276 sleep 15277 278 # Check health279 check_health280 281 # Show status282 show_status283 284 # Show access info285 show_access_info286 287 # Show recent logs288 show_logs289 290 # Final message291 echo ""292 echo -e "${BOLD}${GREEN}╔═══════════════════════════════════════════════════════════════╗${RESET}"293 echo -e "${BOLD}${GREEN}║ ║${RESET}"294 echo -e "${BOLD}${GREEN}║ 🎉 AUDIOFORGE IS NOW RUNNING! 🎉 ║${RESET}"295 echo -e "${BOLD}${GREEN}║ ║${RESET}"296 echo -e "${BOLD}${GREEN}║ Visit http://localhost:3000 to get started ║${RESET}"297 echo -e "${BOLD}${GREEN}║ ║${RESET}"298 echo -e "${BOLD}${GREEN}╚═══════════════════════════════════════════════════════════════╝${RESET}"299 echo ""300 echo -e "${YELLOW}Tip: Use 'docker-compose logs -f' to follow logs${RESET}"301 echo -e "${YELLOW}Tip: Use 'docker-compose down' to stop all services${RESET}"302 echo ""303}304 305# Run main function306main307 