Deploy MusicLab to AWS EC2 t3.micro (Free Tier) with Docker.
- AWS account with Free Tier
- Basic AWS knowledge (EC2, Security Groups)
- SSH key pair for EC2 access
-
Go to EC2 Dashboard β Launch Instance
-
Choose settings:
- Name:
musiclab-production - AMI: Ubuntu Server 24.04 LTS (Free Tier eligible)
- Instance Type:
t3.micro(1 vCPU, 1GB RAM) - Key pair: Select existing or create new SSH key
- Storage: 20GB gp3 (default)
- Name:
-
Network Settings - Configure Security Group:
Inbound Rules:
ββββββββββββ¬βββββββββ¬βββββββββββββ¬ββββββββββββββββββββββββββββββββββ
β Type β Port β Source β Description β
ββββββββββββΌβββββββββΌβββββββββββββΌββββββββββββββββββββββββββββββββββ€
β SSH β 22 β My IP β SSH access (your IP only) β
β HTTP β 80 β 0.0.0.0/0 β Frontend public access β
β Custom β 8001 β 0.0.0.0/0 β Backend API (optional: restrict)β
ββββββββββββ΄βββββββββ΄βββββββββββββ΄ββββββββββββββββββββββββββββββββββ
Outbound Rules:
- All traffic β 0.0.0.0/0 (default)
- Launch Instance
Elastic IP ensures your instance keeps the same public IP after restarts.
# In AWS Console:
1. EC2 β Elastic IPs β "Allocate Elastic IP address"
2. Select new IP β Actions β "Associate Elastic IP address"
3. Choose your instance: musiclab-production
4. Note the IP address (e.g., 13.48.16.109)Benefits:
- β Permanent IP (survives instance stop/start)
- β Free while associated with running instance
- β Can point custom domain to it
# Replace with your key file and Elastic IP
ssh -i ~/.ssh/your-key.pem ubuntu@YOUR_ELASTIC_IP
# Example:
ssh -i ~/.ssh/musiclab-aws.pem ubuntu@13.48.16.109Why needed:
- Docker build requires ~2GB memory (peaks during backend build)
- Model loading (PyTorch + EnCodec) needs ~1GB
- Total: Need 3GB, but we only have 1GB RAM β 4GB swap ensures safety
# Create 4GB swap file
sudo fallocate -l 4G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
# Verify swap is active
free -h
# Should show:
# total used free shared buff/cache available
# Mem: 951Mi 180Mi 600Mi 1.0Mi 170Mi 620Mi
# Swap: 4.0Gi 0B 4.0Gi
# Make swap permanent (survives reboots)
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
# Optimize swap usage (use swap only when really needed)
sudo sysctl vm.swappiness=10
echo 'vm.swappiness=10' | sudo tee -a /etc/sysctl.conf# Update system
sudo apt update && sudo apt upgrade -y
# Install Docker
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
# Add ubuntu user to docker group (no need for sudo docker)
sudo usermod -aG docker ubuntu
# Start Docker service
sudo systemctl enable docker
sudo systemctl start docker
# IMPORTANT: Log out and back in for group changes to take effect
exit
# SSH back in
ssh -i ~/.ssh/your-key.pem ubuntu@YOUR_ELASTIC_IP
# Verify Docker works without sudo
docker --version
# Docker version 27.x.x
docker compose version
# Docker Compose version v2.x.x# Install Git (if not installed)
sudo apt install -y git
# Clone MusicLab repository
git clone https://github.com/Vlasenko2006/PowerMuse.git
cd PowerMuse
# Verify files
ls -la
# Should see: docker-compose.yml, Dockerfile.backend, Dockerfile.frontend, backend/, frontend/# Create .env file with your Groq API key
nano .envPaste this content (replace with your actual API key):
GROQ_API_KEY=your_groq_api_key_here
BACKEND_PORT=8001
FRONTEND_PORT=80Save and exit (Ctrl+X, then Y, then Enter)
# Create backend config with API key
nano backend/config/config_key.yamlPaste this content (replace with your actual API key):
groq:
api_key: "your_groq_api_key_here"
model: "llama-3.3-70b-versatile"
musiclab:
system_prompt: |
You are Rita (Π ΠΈΡΠ° in Russian), an expert music AI assistant for MusicLab.
Your role:
- ALWAYS respond in the language specified by the user's language preference
- If user asks to speak in a specific language, switch to that language immediately
- When responding in Russian, introduce yourself as "Π ΠΈΡΠ°" (Rita)
- Help users understand how MusicLab works
- Explain pattern selection and fusion techniques
- Provide music theory insights
- Answer technical questions about the AI model
- Be friendly, knowledgeable, and encouraging
MusicLab Overview:
- Users upload two 16-second audio patterns
- AI fuses them into a new unique composition
- Uses transformer-based architecture with EnCodec
- Supports various musical styles and combinations
Key Features:
- Pattern fusion preserves characteristics of both inputs
- Sliding window for precise segment selection
- Real-time preview and playback
- Download results as WAV files
Always be helpful, clear, and passionate about music creation!Save and exit.
Note: Initial build takes ~15-20 minutes on t3.micro due to:
- Backend: 3.5GB image (PyTorch CPU, models, dependencies)
- Frontend: 88MB image (nginx + static files)
# Build and start containers
docker compose up -d --build
# Monitor build progress (optional)
docker compose logs -f
# Wait for completion - you'll see:
# β Container musiclab-backend Started
# β Container musiclab-frontend StartedExpected build time:
- Backend: ~12-15 minutes (downloading PyTorch, installing deps, copying model)
- Frontend: ~30 seconds
- Total: ~15-20 minutes
# Check containers are running
docker compose ps
# Should show both containers as "Up" and "healthy"
# Check backend health
curl http://localhost:8001/health | python3 -m json.tool
# Should return:
# {
# "status": "healthy",
# "model_loaded": true,
# "encodec_loaded": true,
# "device": "cpu",
# "timestamp": "2025-12-19T..."
# }
# Check frontend
curl http://localhost
# Should return HTML contentOpen your browser:
Frontend: http://YOUR_ELASTIC_IP
- Example: http://13.48.16.109
Backend API: http://YOUR_ELASTIC_IP:8001
- Health: http://13.48.16.109:8001/health
- Docs: http://13.48.16.109:8001/docs
# View logs
docker compose logs -f # All containers
docker compose logs -f backend # Backend only
docker compose logs -f frontend # Frontend only
# Restart services
docker compose restart
# Stop services
docker compose stop
# Start services
docker compose start
# Rebuild after code changes
git pull origin main
docker compose down
docker compose up -d --build
# Check disk usage
df -h
docker system df
# Clean up unused images/containers (frees space)
docker system prune -f# Check system memory
free -h
# Check Docker container memory
docker stats
# If backend crashes with OOM:
# 1. Increase swap to 8GB:
sudo swapoff /swapfile
sudo fallocate -l 8G /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile# If backend is unhealthy:
docker logs musiclab-backend --tail 100
# Common issues:
# - Model download timeout β wait longer (EnCodec downloads ~50MB)
# - OOM error β increase swap
# - Port already in use β docker compose down && docker compose up -d
# If frontend shows 502 Bad Gateway:
# - Backend not ready yet (wait 2-3 minutes after start)
# - Check backend health: curl http://localhost:8001/health# Reduce memory usage in docker-compose.yml:
# backend:
# deploy:
# resources:
# limits:
# memory: 1.5G # Instead of 2G
# Frontend can use less:
# frontend:
# deploy:
# resources:
# limits:
# memory: 128M # Instead of 256M# 1. Setup firewall
sudo ufw enable
sudo ufw allow 22/tcp # SSH
sudo ufw allow 80/tcp # HTTP
sudo ufw allow 8001/tcp # Backend API
# 2. Auto-updates
sudo apt install unattended-upgrades
sudo dpkg-reconfigure -plow unattended-upgrades
# 3. Change default SSH port (optional)
sudo nano /etc/ssh/sshd_config
# Change: Port 22 β Port 2222
sudo systemctl restart sshd
# 4. Setup HTTPS with Let's Encrypt (if you have domain)
# See: https://certbot.eff.org/Free Tier Usage (12 months):
- β t3.micro: 750 hours/month (1 instance 24/7)
- β 30GB EBS storage
- β Elastic IP (free while associated)
- β 100GB outbound data/month
After Free Tier (~$9-12/month):
- t3.micro: ~$7.50/month
- 20GB EBS: ~$2/month
- Data transfer: ~$1-3/month
Reduce costs:
- Stop instance when not in use (Elastic IP stays free)
- Use t3.micro only (don't upgrade unless needed)
- Monitor CloudWatch for usage
# 1. SSH to instance
ssh -i ~/.ssh/your-key.pem ubuntu@YOUR_ELASTIC_IP
# 2. Navigate to project
cd PowerMuse
# 3. Pull latest changes
git pull origin main
# 4. Rebuild and restart
docker compose down
docker compose up -d --build
# 5. Verify
curl http://localhost:8001/health# Backup configuration
cp .env .env.backup
cp backend/config/config_key.yaml backend/config/config_key.yaml.backup
# Backup uploads (if any)
tar -czf uploads_backup_$(date +%Y%m%d).tar.gz backend/uploads/
# Download backup to local machine
scp -i ~/.ssh/your-key.pem ubuntu@YOUR_ELASTIC_IP:~/PowerMuse/uploads_backup*.tar.gz ~/backups/- β Test all features - upload tracks, generate music, chatbot
- π Setup custom domain (optional):
- Point A record to Elastic IP
- Setup nginx reverse proxy
- Add SSL with Let's Encrypt
- π Monitor performance:
- CloudWatch metrics
- Docker stats
- Application logs
- π Enhance security:
- Restrict port 8001 to localhost only
- Setup HTTPS
- Enable AWS CloudWatch alarms
- GitHub: https://github.com/Vlasenko2006/PowerMuse
- Issues: Report bugs via GitHub Issues
- Email: [andrey.vlasenko2006@gmail.com]
Deployed Successfully! π
Your MusicLab is now live at: http://coming soon ))