Spaces:
Build error
Build error
File size: 16,788 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 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 |
# π AudioForge Production Launch Guide
**Complete step-by-step guide for launching AudioForge to production**
---
## π Pre-Launch Requirements
### System Requirements
- **Python**: 3.11+
- **Node.js**: 18+
- **pnpm**: 8+
- **Docker**: 24+ (optional, for containerized deployment)
- **PostgreSQL**: 16+
- **Redis**: 7+
### Hardware Recommendations
- **CPU**: 4+ cores (8+ recommended for music generation)
- **RAM**: 8GB minimum (16GB+ recommended)
- **Storage**: 50GB+ (models require ~10GB, audio storage scales with usage)
- **GPU**: Optional but highly recommended (CUDA-compatible for faster generation)
---
## π Step 1: Automated Verification
Run the comprehensive verification script to check all systems:
```bash
# From project root
python scripts/launch_verification.py --verbose
# Auto-fix common issues
python scripts/launch_verification.py --fix
# Export results to JSON
python scripts/launch_verification.py --json launch-report.json
```
**Expected Output**: 100% success rate on all checks
---
## π οΈ Step 2: Environment Setup
### Backend Configuration
1. **Create `.env` file**:
```bash
cd backend
cp .env.example .env
```
2. **Configure environment variables**:
```bash
# Database
DATABASE_URL=postgresql+asyncpg://user:password@localhost:5432/audioforge
# Redis
REDIS_URL=redis://localhost:6379/0
# AI Models
MUSICGEN_DEVICE=cuda # or 'cpu'
BARK_DEVICE=cuda # or 'cpu'
DEMUCS_DEVICE=cuda # or 'cpu'
# Application
DEBUG=false
ENVIRONMENT=production
SECRET_KEY=<generate-secure-key>
ALLOWED_ORIGINS=https://yourdomain.com
# Optional: Monitoring
SENTRY_DSN=<your-sentry-dsn>
```
3. **Generate secure secret key**:
```bash
python -c "import secrets; print(secrets.token_urlsafe(32))"
```
### Frontend Configuration
1. **Create `.env.local`**:
```bash
cd frontend
echo "NEXT_PUBLIC_API_URL=https://api.yourdomain.com" > .env.local
```
2. **For production build**:
```bash
# .env.production
NEXT_PUBLIC_API_URL=https://api.yourdomain.com
NEXT_PUBLIC_SENTRY_DSN=<your-sentry-dsn>
```
---
## π¦ Step 3: Install Dependencies
### Backend
```bash
cd backend
# Using uv (recommended)
uv pip install -e ".[dev]"
# Or using pip
pip install -e ".[dev]"
# Verify installation
python scripts/verify_setup.py
```
### Frontend
```bash
cd frontend
# Install dependencies
pnpm install
# Verify no errors
pnpm run type-check
pnpm run lint
```
---
## ποΈ Step 4: Database Setup
### Initialize Database
```bash
cd backend
# Run migrations
python scripts/init_db.py
# Verify connection
python -c "from app.db.database import engine; print('β
Database connected')"
```
### Create Required Tables
The `init_db.py` script automatically creates:
- `generations` table
- Indexes on frequently queried fields
- Initial schema
### Backup Strategy
```bash
# Create backup
pg_dump audioforge > backup_$(date +%Y%m%d).sql
# Restore backup
psql audioforge < backup_20260116.sql
```
---
## π΅ Step 5: Download AI Models
### Automatic Download (Recommended)
Models will download automatically on first use. To pre-download:
```bash
cd backend
python -c "
from app.services.music_generation import MusicGenerationService
service = MusicGenerationService()
print('β
Models downloaded')
"
```
### Manual Download
If automatic download fails:
1. **MusicGen** (~2GB):
```bash
python -c "
from transformers import AutoProcessor, MusicgenForConditionalGeneration
model = MusicgenForConditionalGeneration.from_pretrained('facebook/musicgen-small')
processor = AutoProcessor.from_pretrained('facebook/musicgen-small')
"
```
2. **Bark** (for vocals, ~3GB):
```bash
python -c "
from transformers import AutoProcessor, BarkModel
model = BarkModel.from_pretrained('suno/bark-small')
processor = AutoProcessor.from_pretrained('suno/bark-small')
"
```
3. **Demucs** (for separation, ~300MB):
```bash
python -c "
import torch
torch.hub.load('facebookresearch/demucs', 'demucs')
"
```
---
## π§ͺ Step 6: Run Tests
### Backend Tests
```bash
cd backend
pytest tests/ -v --cov=app --cov-report=html
# Run specific test
pytest tests/test_prompt_understanding.py -v
```
### Frontend Tests
```bash
cd frontend
# Unit tests
pnpm test
# Integration tests
pnpm test src/test/integration.test.tsx
# Coverage report
pnpm test:coverage
# Watch mode during development
pnpm test:watch
```
### Integration Tests
```bash
# Ensure both services are running
# Terminal 1: Backend
cd backend && uvicorn app.main:app --reload
# Terminal 2: Frontend
cd frontend && pnpm dev
# Terminal 3: Run E2E tests
python scripts/launch_verification.py --section integration
```
---
## π Step 7: Build for Production
### Backend
```bash
cd backend
# No build step needed for Python
# Ensure all dependencies are installed
pip freeze > requirements-lock.txt
```
### Frontend
```bash
cd frontend
# Production build
pnpm run build
# Test production build locally
pnpm run start
# Verify at http://localhost:3000
```
### Build Verification
```bash
# Check build output
ls -lh frontend/.next/
# Expected: optimized bundles, static assets
# Build should complete in < 2 minutes
```
---
## π³ Step 8: Docker Deployment (Recommended)
### Build Images
```bash
# Build all services
docker-compose build
# Build specific service
docker-compose build backend
docker-compose build frontend
```
### Start Services
```bash
# Start all services
docker-compose up -d
# Check status
docker-compose ps
# View logs
docker-compose logs -f
# Stop services
docker-compose down
```
### Health Checks
```bash
# Backend health
curl http://localhost:8000/health
# Frontend health
curl http://localhost:3000
# Database health
docker-compose exec postgres pg_isready
# Redis health
docker-compose exec redis redis-cli ping
```
---
## π§ Step 9: Manual Deployment
### Backend Deployment
1. **Using systemd** (Linux):
Create `/etc/systemd/system/audioforge-backend.service`:
```ini
[Unit]
Description=AudioForge Backend API
After=network.target postgresql.service redis.service
[Service]
Type=simple
User=audioforge
WorkingDirectory=/opt/audioforge/backend
Environment="PATH=/opt/audioforge/venv/bin"
ExecStart=/opt/audioforge/venv/bin/uvicorn app.main:app --host 0.0.0.0 --port 8000 --workers 4
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
```
Enable and start:
```bash
sudo systemctl enable audioforge-backend
sudo systemctl start audioforge-backend
sudo systemctl status audioforge-backend
```
2. **Using Gunicorn** (alternative):
```bash
gunicorn app.main:app \
--workers 4 \
--worker-class uvicorn.workers.UvicornWorker \
--bind 0.0.0.0:8000 \
--access-logfile - \
--error-logfile -
```
### Frontend Deployment
1. **Using PM2**:
```bash
cd frontend
# Install PM2
npm install -g pm2
# Start application
pm2 start pnpm --name "audioforge-frontend" -- start
# Save configuration
pm2 save
# Setup startup script
pm2 startup
```
2. **Using systemd**:
Create `/etc/systemd/system/audioforge-frontend.service`:
```ini
[Unit]
Description=AudioForge Frontend
After=network.target
[Service]
Type=simple
User=audioforge
WorkingDirectory=/opt/audioforge/frontend
Environment="NODE_ENV=production"
ExecStart=/usr/bin/pnpm start
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
```
---
## π Step 10: Reverse Proxy Setup
### Nginx Configuration
Create `/etc/nginx/sites-available/audioforge`:
```nginx
# Backend API
upstream backend {
server localhost:8000;
}
# Frontend
upstream frontend {
server localhost:3000;
}
# Redirect HTTP to HTTPS
server {
listen 80;
server_name yourdomain.com api.yourdomain.com;
return 301 https://$server_name$request_uri;
}
# Frontend HTTPS
server {
listen 443 ssl http2;
server_name yourdomain.com;
ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
# Security headers
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
location / {
proxy_pass http://frontend;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
# Backend API HTTPS
server {
listen 443 ssl http2;
server_name api.yourdomain.com;
ssl_certificate /etc/letsencrypt/live/api.yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/api.yourdomain.com/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
# Security headers
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
add_header X-Content-Type-Options "nosniff" always;
# CORS headers (if needed)
add_header Access-Control-Allow-Origin "https://yourdomain.com" always;
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS" always;
add_header Access-Control-Allow-Headers "Authorization, Content-Type" always;
location / {
proxy_pass http://backend;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# Increase timeouts for long-running generation requests
proxy_read_timeout 300s;
proxy_connect_timeout 75s;
}
# API documentation
location /docs {
proxy_pass http://backend/docs;
proxy_set_header Host $host;
}
}
```
Enable and reload:
```bash
sudo ln -s /etc/nginx/sites-available/audioforge /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
```
### SSL Certificates (Let's Encrypt)
```bash
# Install certbot
sudo apt install certbot python3-certbot-nginx
# Obtain certificates
sudo certbot --nginx -d yourdomain.com -d api.yourdomain.com
# Auto-renewal is configured automatically
# Test renewal
sudo certbot renew --dry-run
```
---
## π Step 11: Monitoring Setup
### Application Monitoring
1. **Sentry** (Error Tracking):
```bash
# Backend
pip install sentry-sdk[fastapi]
# Add to app/main.py
import sentry_sdk
sentry_sdk.init(dsn="YOUR_SENTRY_DSN")
# Frontend
pnpm add @sentry/nextjs
# Configure in next.config.js
```
2. **Prometheus** (Metrics):
```bash
# Install prometheus client
pip install prometheus-client
# Expose metrics endpoint
# Already configured in app/core/metrics.py
```
3. **Grafana** (Dashboards):
```bash
docker run -d \
-p 3001:3000 \
--name=grafana \
-e "GF_SECURITY_ADMIN_PASSWORD=admin" \
grafana/grafana
```
### System Monitoring
```bash
# Install monitoring tools
sudo apt install htop iotop nethogs
# Monitor processes
htop
# Monitor disk I/O
iotop
# Monitor network
nethogs
```
### Log Aggregation
```bash
# Using journalctl
sudo journalctl -u audioforge-backend -f
sudo journalctl -u audioforge-frontend -f
# Centralized logging (optional)
# Configure with ELK stack or similar
```
---
## β
Step 12: Final Verification
### Automated Checks
```bash
# Run full verification
python scripts/launch_verification.py --verbose
# Expected: 100% pass rate
```
### Manual Verification Checklist
- [ ] Backend health endpoint responds: `curl https://api.yourdomain.com/health`
- [ ] Frontend loads: Visit `https://yourdomain.com`
- [ ] API documentation accessible: `https://api.yourdomain.com/docs`
- [ ] Create test generation works
- [ ] Audio playback works
- [ ] Status updates in real-time
- [ ] Error messages are user-friendly
- [ ] Mobile responsive design works
- [ ] All animations smooth (60fps)
- [ ] SSL certificates valid
- [ ] Monitoring dashboards active
### Performance Benchmarks
```bash
# Backend API response time
ab -n 1000 -c 10 https://api.yourdomain.com/health
# Frontend load time
lighthouse https://yourdomain.com --view
# Expected metrics:
# - Backend: < 200ms average
# - Frontend FCP: < 1.5s
# - Frontend TTI: < 3s
# - Lighthouse score: > 90
```
---
## π¨ Step 13: Launch Day Procedures
### T-1 Hour
```bash
# 1. Final backup
pg_dump audioforge > pre-launch-backup.sql
# 2. Final verification
python scripts/launch_verification.py
# 3. Monitor system resources
htop
# 4. Clear logs
sudo journalctl --vacuum-time=1d
# 5. Notify team
echo "Launch in 1 hour" | mail -s "AudioForge Launch" team@example.com
```
### Launch (T=0)
```bash
# 1. Start services (if not already running)
docker-compose up -d
# 2. Verify all services healthy
docker-compose ps
# 3. Test end-to-end flow
curl -X POST https://api.yourdomain.com/api/v1/generations \
-H "Content-Type: application/json" \
-d '{"prompt": "Launch test", "duration": 10}'
# 4. Monitor logs
docker-compose logs -f
```
### T+1 Hour
```bash
# 1. Check error rates
curl https://api.yourdomain.com/metrics | grep error_total
# 2. Check generation success rate
# View in monitoring dashboard
# 3. Review user feedback
# Check support channels
# 4. Monitor system resources
htop
```
---
## π§ Troubleshooting
### Backend Won't Start
```bash
# Check logs
docker-compose logs backend
# Common issues:
# 1. Database connection
docker-compose exec postgres pg_isready
# 2. Missing dependencies
cd backend && pip install -e ".[dev]"
# 3. Port already in use
sudo lsof -i :8000
```
### Frontend Won't Build
```bash
# Check Node version
node --version # Should be 18+
# Clear cache
rm -rf frontend/.next frontend/node_modules
cd frontend && pnpm install
# Check for TypeScript errors
pnpm run type-check
```
### Generation Fails
```bash
# Check model files
ls -lh ~/.cache/huggingface/
# Check GPU availability
python -c "import torch; print(torch.cuda.is_available())"
# Check disk space
df -h
# Check memory
free -h
```
### High CPU/Memory Usage
```bash
# Identify process
top -o %CPU
# Restart service
docker-compose restart backend
# Scale workers
# Edit docker-compose.yml: --workers 2
```
---
## π Post-Launch Monitoring
### Daily Checks
- [ ] Error rate < 5%
- [ ] Average response time < 200ms
- [ ] Generation success rate > 95%
- [ ] Disk space > 20% free
- [ ] Database connections healthy
- [ ] SSL certificates valid (> 30 days)
### Weekly Tasks
- [ ] Review user feedback
- [ ] Analyze performance metrics
- [ ] Update dependencies
- [ ] Database backup verification
- [ ] Security audit
### Monthly Tasks
- [ ] Performance optimization review
- [ ] Cost analysis
- [ ] Feature roadmap update
- [ ] Team retrospective
---
## π Success Metrics
### Week 1 Goals
- 100+ generations created
- < 5% error rate
- Average processing time < 60s
- 90%+ user satisfaction
### Month 1 Goals
- 1,000+ total generations
- 100+ active users
- Feature requests collected
- Roadmap for v2 defined
---
## π Support
### Emergency Contacts
- **Backend Issues**: Check `/var/log/audioforge/backend.log`
- **Frontend Issues**: Check browser console + Next.js logs
- **Database Issues**: Check PostgreSQL logs
- **Infrastructure**: Contact DevOps team
### Useful Commands
```bash
# Restart everything
docker-compose restart
# View all logs
docker-compose logs -f --tail=100
# Check service status
systemctl status audioforge-*
# Database backup
pg_dump audioforge > backup.sql
# Restore from backup
psql audioforge < backup.sql
```
---
**πΌβ‘ You're ready to launch! The panda believes in you.** π΅
*Remember: Launch is just the beginning. Listen to users, iterate fast, and keep the creative energy flowing.*
|