-
Notifications
You must be signed in to change notification settings - Fork 0
Deployment
See also: Configuration-Reference | Troubleshooting | Architecture-Overview
- Pre-Deployment Checklist
- Docker Deployment
- Manual Deployment
- Environment Setup
- Database Setup
- Security Considerations
- Monitoring
- Scaling
- Change all default passwords
- Set strong, unique database passwords
- Configure production environment variables
- Enable only required Discord intents
- Set up database migrations
- Configure logging level appropriately
- Set up monitoring and health checks
- Test in staging environment
- Review security settings
- Document deployment process
The framework includes docker-compose.prod.yml with production-ready settings:
docker-compose -f docker-compose.prod.yml up -d- Security hardening (non-root user, read-only filesystem)
- Resource limits
- Health checks
- Migration service that runs before the bot
- Proper restart policies
Create .env.prod with production values:
# Copy example
cp .env.prod.example .env.prod
# Edit with production values
# ⚠️ Never use default passwords!Migrations run automatically before the bot starts:
docker-compose -f docker-compose.prod.yml --profile migrate up migrateThe bot includes health checks:
docker-compose -f docker-compose.prod.yml pspip install wisp-framework[all]# Create production environment file
cp .env.prod.example .env.prod
# Edit .env.prod with production values
# ⚠️ Set strong, unique passwords!# Set DATABASE_URL in environment
export DATABASE_URL=postgresql+asyncpg://user:password@host:5432/db
# Run migrations
alembic upgrade head# Using the runner
wisp-framework-runner
# Or using Python
python -m runner_bot.mainUse a process manager like systemd or supervisor:
[Unit]
Description=Wisp Framework Bot
After=network.target postgresql.service
[Service]
Type=simple
User=discord-bot
WorkingDirectory=/opt/wisp-bot
Environment="ENV=production"
ExecStart=/usr/bin/python3 -m runner_bot.main
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target# Required
DISCORD_TOKEN=your_production_token
# Database (change passwords!)
DATABASE_URL=postgresql+asyncpg://user:strong_password@host:5432/db
POSTGRES_USER=production_user
POSTGRES_PASSWORD=strong_unique_password
POSTGRES_DB=production_db
# Redis (if used)
REDIS_URL=redis://strong_password@host:6379/0
# Logging
LOG_LEVEL=WARNING
# Intents (only enable what you need)
INTENTS_GUILDS=true
INTENTS_MEMBERS=true
INTENTS_MESSAGES=false
INTENTS_MESSAGE_CONTENT=false
# Owner
OWNER_ID=your_discord_user_id-
Never commit
.env.prodto version control - Use secret management (AWS Secrets Manager, HashiCorp Vault, etc.)
- Rotate passwords regularly
- Use strong passwords (minimum 32 characters)
- Limit database access to necessary IPs
- Enable SSL/TLS for database connections
- Use read-only database users when possible
# Create database
createdb discord_bot
# Run migrations
alembic upgrade head# Create new migration
alembic revision --autogenerate -m "description"
# Review migration file
# Edit if needed
# Apply migration
alembic upgrade head
# Rollback if needed
alembic downgrade -1# Backup database
pg_dump -h host -U user -d database > backup.sql
# Restore database
psql -h host -U user -d database < backup.sqlConfigure connection pool size based on load:
DB_POOL_SIZE=20
DB_MAX_OVERFLOW=30
DB_POOL_TIMEOUT=60The production Docker setup includes:
- Non-root user execution
- Read-only filesystem
- Dropped capabilities
- Resource limits
- Security options
- Use private networks for database/Redis
- Enable firewall rules
- Use VPN or SSH tunnels for database access
- Limit exposed ports
- Validate all user input
- Use parameterized queries
- Implement rate limiting
- Log security events
- Monitor for anomalies
Never store secrets in code or configuration files:
- Use environment variables
- Use secret management services
- Rotate secrets regularly
- Audit secret access
The framework provides health check endpoints:
# Check bot health
/health command
# Check service health
health_service.check_service("db")Configure logging for production:
LOG_LEVEL=WARNINGLog to files or centralized logging:
import logging
# File handler
file_handler = logging.FileHandler("bot.log")
logger.addHandler(file_handler)Use the metrics service for monitoring:
metrics = ctx.services.get("metrics")
metrics.increment("commands.executed")
metrics.timing("command.duration", duration)Set up alerts for:
- Bot downtime
- High error rates
- Database connection failures
- Resource usage
Discord bots typically don't need horizontal scaling, but if needed:
- Use shared database
- Use Redis for shared state
- Implement stateless modules
- Use load balancer for webhooks
Increase resources:
- More CPU for command processing
- More memory for caching
- Larger database connection pool
- More Redis connections
- Use caching for frequently accessed data
- Optimize database queries
- Use connection pooling
- Implement rate limiting
- Monitor performance metrics
See Troubleshooting for common deployment issues.
- Review Configuration-Reference for configuration details
- Check Architecture-Overview for deployment context
- See API-Reference for deployment-related APIs