- Integrated all production features into main application flow - Added metrics, tracing, caching, and health checks to API server - Enhanced trade execution with circuit breakers and retry policies - Integrated database persistence for trades and metrics - Added structured logging and observability - Enhanced middleware with missing validators and rate limiters - Added comprehensive error handling and resilience patterns
4.7 KiB
4.7 KiB
Production Deployment Guide
Complete guide for deploying the Immortal AI Trading Bot to production.
Prerequisites
- Docker and Docker Compose installed
- PostgreSQL database (managed or self-hosted)
- Redis instance (optional but recommended)
- BNB Chain wallet with private key
- OpenRouter API key
- BNB Greenfield account and bucket
Step 1: Environment Setup
1.1 Create Production Environment File
cp .env.example .env.production
1.2 Configure Environment Variables
Edit .env.production:
# Network
NODE_ENV=production
NETWORK=mainnet
CHAIN_ID=56
TRADING_NETWORK=bnb
# Database
DATABASE_URL=postgresql://user:password@host:5432/immortal_bot
# Redis (optional)
REDIS_URL=redis://host:6379
# Wallet
WALLET_PRIVATE_KEY=0x...
WALLET_ADDRESS=0x...
# API Keys
OPENROUTER_API_KEY=sk-or-v1-...
GREENFIELD_BUCKET_NAME=immortal-bot-prod
# Security
JWT_SECRET=<generate-secure-random-string>
API_KEY=<generate-secure-random-string>
# Trading Limits
MAX_TRADE_AMOUNT_BNB=0.5
DAILY_TRADE_LIMIT_BNB=5.0
STOP_LOSS_PERCENTAGE=5
# Monitoring
ENABLE_TRACING=true
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318
1.3 Generate Secure Secrets
# Generate JWT secret
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
# Generate API key
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
Step 2: Database Setup
2.1 Create Database
createdb immortal_bot
2.2 Run Migrations
bunx prisma migrate deploy
2.3 Verify Schema
bunx prisma studio
Step 3: Build and Deploy
3.1 Build Docker Images
docker-compose -f docker-compose.prod.yml build
3.2 Start Services
docker-compose -f docker-compose.prod.yml up -d
3.3 Verify Deployment
# Check health
curl http://localhost:3001/health
# Check logs
docker-compose -f docker-compose.prod.yml logs -f
Step 4: Post-Deployment Verification
4.1 Health Checks
# Basic health
curl http://localhost:3001/health
# Detailed health
curl http://localhost:3001/api/health
# Readiness probe
curl http://localhost:3001/ready
# Liveness probe
curl http://localhost:3001/live
4.2 Test API Endpoints
# Get bot status
curl http://localhost:3001/api/bot-status
# Discover tokens
curl http://localhost:3001/api/discover-tokens?limit=5
4.3 Monitor Metrics
# Prometheus metrics
curl http://localhost:3001/metrics
Step 5: Monitoring Setup
5.1 Configure Prometheus
Update monitoring/prometheus.yml with production targets.
5.2 Set Up Grafana
- Import dashboards from
monitoring/grafana/dashboards/ - Configure data source (Prometheus)
- Set up alerting rules
5.3 Configure Alertmanager
Update monitoring/alertmanager.yml with:
- PagerDuty integration
- Email notifications
- Slack webhooks
Step 6: Backup Configuration
6.1 Set Up Automated Backups
Add to crontab:
# Daily database backup at 2 AM
0 2 * * * /path/to/scripts/backup-database.sh
# Weekly Greenfield backup on Sunday
0 3 * * 0 /path/to/scripts/backup-greenfield.sh
6.2 Test Backup Restoration
# Test restore procedure monthly
./scripts/restore.sh backups/db_backup_YYYYMMDD_HHMMSS.sql.gz
Step 7: Security Hardening
7.1 Enable API Authentication
Update API server to require API keys for sensitive endpoints.
7.2 Configure Rate Limiting
Verify rate limits are appropriate for production traffic.
7.3 Set Up SSL/TLS
Use reverse proxy (nginx/traefik) with Let's Encrypt certificates.
Step 8: Scaling (Optional)
8.1 Horizontal Scaling
docker-compose -f docker-compose.prod.yml up -d --scale backend=3
8.2 Load Balancer
Configure nginx or traefik as load balancer.
Troubleshooting
Service Won't Start
- Check logs:
docker-compose logs backend - Verify environment variables
- Check database connection
- Verify wallet private key format
Database Connection Issues
- Verify DATABASE_URL format
- Check network connectivity
- Verify database credentials
- Check firewall rules
High Memory Usage
- Check for memory leaks
- Increase container memory limits
- Optimize queries
- Enable Redis caching
Rollback Procedure
If deployment fails:
# Rollback to previous version
./scripts/rollback.sh production previous-version
# Or manually
docker-compose -f docker-compose.prod.yml down
docker-compose -f docker-compose.prod.yml up -d
Maintenance Windows
Schedule maintenance during low-traffic periods:
- Notify users
- Enable maintenance mode
- Perform updates
- Run health checks
- Disable maintenance mode
Support
For issues, contact:
- On-call engineer: [Contact]
- Infrastructure team: [Contact]