feat(deployment): add production Docker deployment with auto-restart and on-boot startup
Add comprehensive production deployment infrastructure with Docker auto-restart and systemd on-boot startup capabilities. Changes: - Add deploy-production-docker.sh: Automated deployment script with Docker validation - Add install-systemd-service.sh: Systemd service installer for auto-start on boot - Add scripts/mev-bot.service: Systemd service definition for MEV bot - Update docker-compose.yml: Enable logs volume mount and metrics port - Update PRODUCTION_QUICKSTART.md: Simplified deployment documentation Features: - Docker auto-restart on failure (restart: always policy) - Systemd auto-start on system boot - Persistent logs via volume mount - Health checks and resource limits - Comprehensive deployment validation - Easy-to-use installation scripts Usage: ./scripts/deploy-production-docker.sh # Deploy with Docker sudo ./scripts/install-systemd-service.sh # Enable auto-start on boot 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
285
PRODUCTION_QUICKSTART.md
Normal file
285
PRODUCTION_QUICKSTART.md
Normal file
@@ -0,0 +1,285 @@
|
||||
# MEV Bot - Production Quick Start
|
||||
|
||||
This guide will help you deploy the MEV Bot in production with Docker, auto-restart, and on-boot capabilities.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- Docker and Docker Compose installed
|
||||
- Git repository cloned
|
||||
- Root/sudo access (for systemd auto-start on boot)
|
||||
|
||||
## Quick Deployment
|
||||
|
||||
### Option 1: One-Step Deployment (Recommended)
|
||||
|
||||
```bash
|
||||
# Run the simplified deployment script
|
||||
./scripts/deploy-production-docker.sh
|
||||
```
|
||||
|
||||
This script will:
|
||||
1. Verify Docker and Docker Compose are installed
|
||||
2. Create/verify `.env` file from `.env.production` or `.env.example`
|
||||
3. Build the Docker image
|
||||
4. Start the container with auto-restart (`restart: always`)
|
||||
5. Provide instructions for systemd auto-start on boot
|
||||
|
||||
**For auto-start on boot (requires sudo):**
|
||||
```bash
|
||||
sudo ./scripts/install-systemd-service.sh
|
||||
```
|
||||
|
||||
### Option 2: Manual Deployment
|
||||
|
||||
```bash
|
||||
# 1. Create environment file
|
||||
cp .env.production .env # or use .env.example
|
||||
nano .env # Edit with your configuration if needed
|
||||
|
||||
# 2. Build and start with auto-restart
|
||||
docker compose up -d
|
||||
|
||||
# 3. Setup auto-start on boot (optional)
|
||||
sudo ./scripts/install-systemd-service.sh
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
Edit `.env` file with your settings:
|
||||
|
||||
```bash
|
||||
# Required: Update with your RPC endpoint
|
||||
ARBITRUM_RPC_ENDPOINT=https://arbitrum-rpc.publicnode.com
|
||||
|
||||
# Optional: Adjust log level
|
||||
LOG_LEVEL=info
|
||||
|
||||
# Optional: Change port
|
||||
PORT=8080
|
||||
```
|
||||
|
||||
## Verify Deployment
|
||||
|
||||
```bash
|
||||
# Check container status
|
||||
docker compose ps
|
||||
|
||||
# View logs
|
||||
docker compose logs -f mev-bot
|
||||
|
||||
# Check health
|
||||
curl http://localhost:8080/health
|
||||
|
||||
# View systemd status (if configured)
|
||||
sudo systemctl status mev-bot
|
||||
```
|
||||
|
||||
## Production Features
|
||||
|
||||
The production deployment includes:
|
||||
|
||||
- **Auto-Restart**: Container restarts automatically on failure (`restart: always`)
|
||||
- **Auto-Start on Boot**: Systemd service starts container on system boot
|
||||
- **Health Checks**: Automatic health monitoring every 30 seconds
|
||||
- **Resource Limits**: CPU and memory limits to prevent resource exhaustion
|
||||
- **Security Hardening**: Runs as non-root user with minimal privileges
|
||||
- **Read-Only Config**: Configuration mounted as read-only
|
||||
|
||||
## Managing the Bot
|
||||
|
||||
### Docker Compose Commands
|
||||
|
||||
```bash
|
||||
# View logs (follow mode)
|
||||
docker compose logs -f mev-bot
|
||||
|
||||
# Restart
|
||||
docker compose restart mev-bot
|
||||
|
||||
# Stop
|
||||
docker compose down
|
||||
|
||||
# Update and restart
|
||||
git pull origin master
|
||||
docker compose up -d --build
|
||||
|
||||
# View container stats
|
||||
docker stats mev-bot-production
|
||||
```
|
||||
|
||||
### Systemd Commands (if configured)
|
||||
|
||||
```bash
|
||||
# Check status
|
||||
sudo systemctl status mev-bot
|
||||
|
||||
# Restart
|
||||
sudo systemctl restart mev-bot
|
||||
|
||||
# Stop
|
||||
sudo systemctl stop mev-bot
|
||||
|
||||
# View logs
|
||||
journalctl -u mev-bot -f
|
||||
|
||||
# Disable auto-start
|
||||
sudo systemctl disable mev-bot
|
||||
```
|
||||
|
||||
## Monitoring
|
||||
|
||||
### Container Logs
|
||||
```bash
|
||||
# Live logs
|
||||
docker compose logs -f mev-bot
|
||||
|
||||
# Last 100 lines
|
||||
docker compose logs --tail=100 mev-bot
|
||||
|
||||
# Logs since 1 hour ago
|
||||
docker compose logs --since 1h mev-bot
|
||||
```
|
||||
|
||||
### Health Check
|
||||
```bash
|
||||
# Simple health check
|
||||
curl http://localhost:8080/health
|
||||
|
||||
# Expected response: {"status": "ok"} or similar
|
||||
```
|
||||
|
||||
### Resource Usage
|
||||
```bash
|
||||
# Real-time stats
|
||||
docker stats mev-bot-production
|
||||
|
||||
# Shows: CPU %, Memory, Network I/O, Block I/O
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Container won't start
|
||||
```bash
|
||||
# Check logs for errors
|
||||
docker compose logs mev-bot
|
||||
|
||||
# Verify .env file exists and is configured
|
||||
cat .env
|
||||
|
||||
# Check if port is already in use
|
||||
sudo netstat -tulpn | grep 8080
|
||||
```
|
||||
|
||||
### Auto-start not working
|
||||
```bash
|
||||
# Verify systemd service is enabled
|
||||
sudo systemctl is-enabled mev-bot
|
||||
|
||||
# Check service status
|
||||
sudo systemctl status mev-bot
|
||||
|
||||
# View systemd logs
|
||||
journalctl -u mev-bot -n 50
|
||||
```
|
||||
|
||||
### High resource usage
|
||||
```bash
|
||||
# Check current usage
|
||||
docker stats mev-bot-production
|
||||
|
||||
# Adjust limits in docker-compose.yml:
|
||||
# deploy.resources.limits.cpus
|
||||
# deploy.resources.limits.memory
|
||||
```
|
||||
|
||||
## Updating the Bot
|
||||
|
||||
### Manual Updates
|
||||
```bash
|
||||
# Pull latest code
|
||||
git pull origin master
|
||||
|
||||
# Rebuild and restart
|
||||
docker compose up -d --build
|
||||
|
||||
# Or using systemd
|
||||
sudo systemctl reload mev-bot
|
||||
```
|
||||
|
||||
### Automatic Updates (Recommended)
|
||||
|
||||
Setup auto-updates to automatically pull, rebuild, and restart when master branch changes:
|
||||
|
||||
```bash
|
||||
# Enable auto-updates
|
||||
sudo ./scripts/setup-auto-update.sh
|
||||
```
|
||||
|
||||
This enables:
|
||||
- ✅ Auto-rebuild after manual `git pull`
|
||||
- ✅ Periodic update checks every 5 minutes
|
||||
- ✅ Automatic pull, rebuild, and restart
|
||||
- ✅ Detailed logging of all updates
|
||||
|
||||
**Manage auto-updates:**
|
||||
```bash
|
||||
# Check auto-update status
|
||||
sudo systemctl status mev-bot-auto-update.timer
|
||||
|
||||
# View auto-update logs
|
||||
tail -f logs/auto-update.log
|
||||
|
||||
# Disable auto-updates
|
||||
sudo systemctl stop mev-bot-auto-update.timer
|
||||
|
||||
# Enable auto-updates
|
||||
sudo systemctl start mev-bot-auto-update.timer
|
||||
```
|
||||
|
||||
For complete auto-update documentation, see [AUTO_UPDATE_GUIDE.md](AUTO_UPDATE_GUIDE.md)
|
||||
|
||||
## Security Best Practices
|
||||
|
||||
1. **Never commit `.env` file** - It's in `.gitignore`
|
||||
2. **Use strong RPC credentials** - Keep API keys secure
|
||||
3. **Restrict network access** - Use firewall rules
|
||||
4. **Monitor logs regularly** - Check for suspicious activity
|
||||
5. **Keep system updated** - Update Docker and dependencies
|
||||
|
||||
## Support
|
||||
|
||||
For detailed deployment options, monitoring, and advanced configuration, see:
|
||||
- [DEPLOYMENT_GUIDE.md](docs/DEPLOYMENT_GUIDE.md) - Comprehensive deployment guide
|
||||
- [README.md](README.md) - Project overview
|
||||
|
||||
## Quick Command Reference
|
||||
|
||||
```bash
|
||||
# Deploy
|
||||
sudo ./scripts/deploy-production.sh
|
||||
sudo ./scripts/setup-auto-update.sh # Add auto-updates
|
||||
|
||||
# Status
|
||||
docker compose ps
|
||||
sudo systemctl status mev-bot
|
||||
sudo systemctl status mev-bot-auto-update.timer # Auto-update status
|
||||
|
||||
# Logs
|
||||
docker compose logs -f mev-bot
|
||||
journalctl -u mev-bot -f
|
||||
tail -f logs/auto-update.log # Auto-update logs
|
||||
|
||||
# Restart
|
||||
docker compose restart mev-bot
|
||||
sudo systemctl restart mev-bot
|
||||
|
||||
# Stop
|
||||
docker compose down
|
||||
sudo systemctl stop mev-bot
|
||||
|
||||
# Update (Manual)
|
||||
git pull && docker compose up -d --build
|
||||
|
||||
# Update (Auto - happens automatically)
|
||||
./scripts/auto-update.sh # Trigger manual update check
|
||||
```
|
||||
Reference in New Issue
Block a user