Spaces:
Build error
Build error
| # ============================================ | |
| # AudioForge - Professional Presentation Launch | |
| # ============================================ | |
| # Enterprise-grade deployment script | |
| # Author: AudioForge Team | |
| # Version: 1.0.0 | |
| set -e | |
| # Colors | |
| GREEN='\033[0;32m' | |
| BLUE='\033[0;34m' | |
| YELLOW='\033[1;33m' | |
| RED='\033[0;31m' | |
| CYAN='\033[0;36m' | |
| MAGENTA='\033[0;35m' | |
| BOLD='\033[1m' | |
| RESET='\033[0m' | |
| # Parse arguments | |
| CLEAN=false | |
| BUILD=false | |
| MONITORING=false | |
| while [[ $# -gt 0 ]]; do | |
| case $1 in | |
| --clean) CLEAN=true; shift ;; | |
| --build) BUILD=true; shift ;; | |
| --monitoring) MONITORING=true; shift ;; | |
| *) echo "Unknown option: $1"; exit 1 ;; | |
| esac | |
| done | |
| # Banner | |
| show_banner() { | |
| echo "" | |
| echo -e "${CYAN}${BOLD}βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ${RESET}" | |
| echo -e "${CYAN}${BOLD}β β${RESET}" | |
| echo -e "${CYAN}${BOLD}β ${MAGENTA}π΅ AUDIOFORGE π΅${CYAN} β${RESET}" | |
| echo -e "${CYAN}${BOLD}β β${RESET}" | |
| echo -e "${CYAN}${BOLD}β ${RESET}Open-Source Text-to-Music Generation Platform${CYAN} β${RESET}" | |
| echo -e "${CYAN}${BOLD}β β${RESET}" | |
| echo -e "${CYAN}${BOLD}β ${GREEN}Production-Ready Enterprise Deployment${CYAN} β${RESET}" | |
| echo -e "${CYAN}${BOLD}β β${RESET}" | |
| echo -e "${CYAN}${BOLD}βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ${RESET}" | |
| echo "" | |
| } | |
| # Status messages | |
| status() { echo -e "${BLUE}[INFO]${RESET} $1"; } | |
| success() { echo -e "${GREEN}[β]${RESET} $1"; } | |
| warning() { echo -e "${YELLOW}[!]${RESET} $1"; } | |
| error() { echo -e "${RED}[β]${RESET} $1"; } | |
| section() { echo ""; echo -e "${BOLD}${CYAN}βββ $1 βββ${RESET}"; echo ""; } | |
| # Check prerequisites | |
| check_prerequisites() { | |
| section "Checking Prerequisites" | |
| local all_good=true | |
| # Check Docker | |
| if command -v docker &> /dev/null; then | |
| success "Docker: $(docker --version)" | |
| else | |
| error "Docker not found. Please install Docker." | |
| all_good=false | |
| fi | |
| # Check Docker Compose | |
| if command -v docker-compose &> /dev/null; then | |
| success "Docker Compose: $(docker-compose --version)" | |
| else | |
| error "Docker Compose not found." | |
| all_good=false | |
| fi | |
| # Check if Docker is running | |
| if docker ps &> /dev/null; then | |
| success "Docker daemon is running" | |
| else | |
| error "Docker daemon is not running. Please start Docker." | |
| all_good=false | |
| fi | |
| if [ "$all_good" = false ]; then | |
| error "Prerequisites check failed. Please resolve issues and try again." | |
| exit 1 | |
| fi | |
| } | |
| # Clean up | |
| cleanup() { | |
| section "Cleaning Up Previous Deployment" | |
| status "Stopping containers..." | |
| docker-compose down -v 2>/dev/null || true | |
| status "Removing unused images..." | |
| docker image prune -f > /dev/null | |
| status "Removing unused volumes..." | |
| docker volume prune -f > /dev/null | |
| success "Cleanup complete" | |
| } | |
| # Build images | |
| build_images() { | |
| section "Building Docker Images" | |
| status "Building backend image..." | |
| docker-compose build backend | |
| status "Building frontend image..." | |
| docker-compose build frontend | |
| success "All images built successfully" | |
| } | |
| # Start services | |
| start_services() { | |
| section "Starting Services" | |
| status "Starting database layer (PostgreSQL, Redis)..." | |
| docker-compose up -d postgres redis | |
| sleep 5 | |
| status "Starting backend API..." | |
| docker-compose up -d backend | |
| sleep 10 | |
| status "Starting frontend application..." | |
| docker-compose up -d frontend | |
| success "All services started" | |
| } | |
| # Check service health | |
| check_health() { | |
| section "Health Check Status" | |
| local max_retries=30 | |
| local retry_count=0 | |
| # Check PostgreSQL | |
| status "Checking PostgreSQL..." | |
| retry_count=0 | |
| while [ $retry_count -lt $max_retries ]; do | |
| health=$(docker inspect --format='{{.State.Health.Status}}' audioforge-postgres 2>/dev/null || echo "starting") | |
| if [ "$health" = "healthy" ]; then | |
| success "PostgreSQL is healthy" | |
| break | |
| fi | |
| ((retry_count++)) | |
| sleep 2 | |
| done | |
| # Check Redis | |
| status "Checking Redis..." | |
| retry_count=0 | |
| while [ $retry_count -lt $max_retries ]; do | |
| health=$(docker inspect --format='{{.State.Health.Status}}' audioforge-redis 2>/dev/null || echo "starting") | |
| if [ "$health" = "healthy" ]; then | |
| success "Redis is healthy" | |
| break | |
| fi | |
| ((retry_count++)) | |
| sleep 2 | |
| done | |
| # Check Backend | |
| status "Checking Backend API..." | |
| retry_count=0 | |
| while [ $retry_count -lt $max_retries ]; do | |
| if curl -sf http://localhost:8000/health > /dev/null 2>&1; then | |
| success "Backend API is healthy" | |
| break | |
| fi | |
| ((retry_count++)) | |
| sleep 2 | |
| done | |
| # Check Frontend | |
| status "Checking Frontend..." | |
| retry_count=0 | |
| while [ $retry_count -lt $max_retries ]; do | |
| if curl -sf http://localhost:3000 > /dev/null 2>&1; then | |
| success "Frontend is healthy" | |
| break | |
| fi | |
| ((retry_count++)) | |
| sleep 2 | |
| done | |
| } | |
| # Show service status | |
| show_status() { | |
| section "Service Status Dashboard" | |
| docker-compose ps | |
| echo "" | |
| echo -e "${BOLD}Container Resource Usage:${RESET}" | |
| docker stats --no-stream --format "table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.NetIO}}" | |
| } | |
| # Show access information | |
| show_access_info() { | |
| section "Access Information" | |
| echo -e "${BOLD}${GREEN}π Application URLs:${RESET}" | |
| echo "" | |
| echo -e " ${CYAN}Frontend Application:${RESET} http://localhost:3000" | |
| echo -e " ${CYAN}Backend API:${RESET} http://localhost:8000" | |
| echo -e " ${CYAN}API Documentation:${RESET} http://localhost:8000/docs" | |
| echo -e " ${CYAN}API Redoc:${RESET} http://localhost:8000/redoc" | |
| echo -e " ${CYAN}Health Check:${RESET} http://localhost:8000/health" | |
| echo "" | |
| if [ "$MONITORING" = true ]; then | |
| echo -e "${BOLD}${YELLOW}π Monitoring URLs:${RESET}" | |
| echo "" | |
| echo -e " ${CYAN}Prometheus:${RESET} http://localhost:9090" | |
| echo -e " ${CYAN}Grafana:${RESET} http://localhost:3001" | |
| echo -e " ${CYAN}Grafana Credentials:${RESET} admin / admin" | |
| echo "" | |
| fi | |
| echo -e "${BOLD}${MAGENTA}π Database Connections:${RESET}" | |
| echo "" | |
| echo -e " ${CYAN}PostgreSQL:${RESET} localhost:5432" | |
| echo -e " ${CYAN}Database:${RESET} audioforge" | |
| echo -e " ${CYAN}User:${RESET} postgres" | |
| echo "" | |
| echo -e " ${CYAN}Redis:${RESET} localhost:6379" | |
| echo "" | |
| } | |
| # Show logs | |
| show_logs() { | |
| section "Recent Logs" | |
| echo -e "${CYAN}Backend Logs:${RESET}" | |
| docker-compose logs --tail=10 backend | |
| echo "" | |
| echo -e "${CYAN}Frontend Logs:${RESET}" | |
| docker-compose logs --tail=10 frontend | |
| } | |
| # Main execution | |
| main() { | |
| show_banner | |
| # Check prerequisites | |
| check_prerequisites | |
| # Clean up if requested | |
| if [ "$CLEAN" = true ]; then | |
| cleanup | |
| fi | |
| # Build if requested | |
| if [ "$BUILD" = true ]; then | |
| build_images | |
| fi | |
| # Start services | |
| start_services | |
| # Wait for services to be healthy | |
| status "Waiting for services to become healthy..." | |
| sleep 15 | |
| # Check health | |
| check_health | |
| # Show status | |
| show_status | |
| # Show access info | |
| show_access_info | |
| # Show recent logs | |
| show_logs | |
| # Final message | |
| echo "" | |
| echo -e "${BOLD}${GREEN}βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ${RESET}" | |
| echo -e "${BOLD}${GREEN}β β${RESET}" | |
| echo -e "${BOLD}${GREEN}β π AUDIOFORGE IS NOW RUNNING! π β${RESET}" | |
| echo -e "${BOLD}${GREEN}β β${RESET}" | |
| echo -e "${BOLD}${GREEN}β Visit http://localhost:3000 to get started β${RESET}" | |
| echo -e "${BOLD}${GREEN}β β${RESET}" | |
| echo -e "${BOLD}${GREEN}βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ${RESET}" | |
| echo "" | |
| echo -e "${YELLOW}Tip: Use 'docker-compose logs -f' to follow logs${RESET}" | |
| echo -e "${YELLOW}Tip: Use 'docker-compose down' to stop all services${RESET}" | |
| echo "" | |
| } | |
| # Run main function | |
| main | |