169 lines
5.4 KiB
Bash
Executable File
169 lines
5.4 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Production Deployment Script for MEV Bot
|
|
# This script deploys the MEV bot to a production environment for live trading
|
|
|
|
set -e # Exit on any error
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
PURPLE='\033[0;35m'
|
|
CYAN='\033[0;36m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Script information
|
|
echo -e "${PURPLE}🚀 MEV Bot Production Deployment Script${NC}"
|
|
echo -e "${PURPLE}=====================================${NC}"
|
|
echo ""
|
|
|
|
# Check if running from project root
|
|
if [ ! -f "go.mod" ]; then
|
|
echo -e "${RED}❌ Error: This script must be run from the project root directory${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
# Check if .env.production exists
|
|
if [ ! -f ".env.production" ]; then
|
|
echo -e "${RED}❌ Error: .env.production file not found${NC}"
|
|
echo -e "${YELLOW}Please create .env.production file with production configuration${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
# Load production environment variables
|
|
echo -e "${BLUE}🔧 Loading production environment variables...${NC}"
|
|
source .env.production
|
|
|
|
# Check required environment variables
|
|
echo -e "${BLUE}🔍 Checking required environment variables...${NC}"
|
|
|
|
REQUIRED_VARS=(
|
|
"ARBITRUM_RPC_ENDPOINT"
|
|
"ETHEREUM_PRIVATE_KEY"
|
|
"ETHEREUM_ACCOUNT_ADDRESS"
|
|
"CONTRACT_ARBITRAGE_EXECUTOR"
|
|
"CONTRACT_FLASH_SWAPPER"
|
|
"POSTGRES_PASSWORD"
|
|
"MEV_BOT_ENCRYPTION_KEY"
|
|
)
|
|
|
|
MISSING_VARS=()
|
|
for var in "${REQUIRED_VARS[@]}"; do
|
|
if [ -z "${!var}" ]; then
|
|
MISSING_VARS+=("$var")
|
|
fi
|
|
done
|
|
|
|
if [ ${#MISSING_VARS[@]} -ne 0 ]; then
|
|
echo -e "${RED}❌ Error: Missing required environment variables:${NC}"
|
|
for var in "${MISSING_VARS[@]}"; do
|
|
echo -e "${RED} - $var${NC}"
|
|
done
|
|
echo -e "${YELLOW}Please set these variables in .env.production${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
echo -e "${GREEN}✅ All required environment variables are set${NC}"
|
|
|
|
# Create required directories
|
|
echo -e "${BLUE}📁 Creating required directories...${NC}"
|
|
mkdir -p data/production logs/production config keys
|
|
|
|
# Build the application
|
|
echo -e "${BLUE}🔨 Building MEV bot application...${NC}"
|
|
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o bin/mev-bot-production cmd/mev-bot/main.go
|
|
|
|
if [ $? -eq 0 ]; then
|
|
echo -e "${GREEN}✅ Application built successfully${NC}"
|
|
else
|
|
echo -e "${RED}❌ Error: Failed to build application${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
# Run tests to ensure application is working
|
|
echo -e "${BLUE}🧪 Running tests...${NC}"
|
|
go test -v ./pkg/... -short
|
|
|
|
if [ $? -eq 0 ]; then
|
|
echo -e "${GREEN}✅ Tests passed${NC}"
|
|
else
|
|
echo -e "${RED}❌ Error: Tests failed${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
# Check if Docker is available
|
|
if ! command -v docker &> /dev/null; then
|
|
echo -e "${RED}❌ Error: Docker is not installed or not in PATH${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
if ! command -v docker-compose &> /dev/null; then
|
|
echo -e "${RED}❌ Error: docker-compose is not installed or not in PATH${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
echo -e "${GREEN}✅ Docker and docker-compose are available${NC}"
|
|
|
|
# Stop any existing containers
|
|
echo -e "${BLUE}⏹️ Stopping any existing production containers...${NC}"
|
|
docker-compose -f docker-compose.production.yaml down --remove-orphans 2>/dev/null || true
|
|
|
|
# Pull latest images
|
|
echo -e "${BLUE}⬇️ Pulling latest images...${NC}"
|
|
docker-compose -f docker-compose.production.yaml pull
|
|
|
|
# Build images
|
|
echo -e "${BLUE}🔨 Building production images...${NC}"
|
|
docker-compose -f docker-compose.production.yaml build
|
|
|
|
# Start services
|
|
echo -e "${BLUE}🚀 Starting production services...${NC}"
|
|
docker-compose -f docker-compose.production.yaml up -d
|
|
|
|
# Wait for services to start
|
|
echo -e "${BLUE}⏳ Waiting for services to start...${NC}"
|
|
sleep 30
|
|
|
|
# Check service status
|
|
echo -e "${BLUE}🔍 Checking service status...${NC}"
|
|
SERVICES_RUNNING=true
|
|
|
|
SERVICES=("mev-bot-arbitrum" "mev-bot-redis" "mev-bot-postgres" "mev-bot-prometheus" "mev-bot-grafana" "mev-bot-fluentd")
|
|
|
|
for service in "${SERVICES[@]}"; do
|
|
if docker ps | grep -q "$service"; then
|
|
echo -e "${GREEN}✅ $service is running${NC}"
|
|
else
|
|
echo -e "${RED}❌ $service is not running${NC}"
|
|
SERVICES_RUNNING=false
|
|
fi
|
|
done
|
|
|
|
if [ "$SERVICES_RUNNING" = true ]; then
|
|
echo -e "${GREEN}🎉 All production services started successfully!${NC}"
|
|
echo ""
|
|
echo -e "${BLUE}📊 Monitoring endpoints:${NC}"
|
|
echo -e " - MEV Bot Metrics: http://localhost:${METRICS_PORT:-9090}/metrics"
|
|
echo -e " - MEV Bot Health: http://localhost:${HEALTH_PORT:-8080}/health"
|
|
echo -e " - Prometheus: http://localhost:${PROMETHEUS_PORT:-9091}"
|
|
echo -e " - Grafana: http://localhost:${GRAFANA_PORT:-3000}"
|
|
echo ""
|
|
echo -e "${BLUE}📝 Logs:${NC}"
|
|
echo -e " - MEV Bot: docker logs mev-bot-arbitrum"
|
|
echo -e " - Redis: docker logs mev-bot-redis"
|
|
echo -e " - PostgreSQL: docker logs mev-bot-postgres"
|
|
echo ""
|
|
echo -e "${YELLOW}⚠️ Remember to monitor the production environment closely during initial deployment${NC}"
|
|
echo -e "${YELLOW}⚠️ Start with small position sizes to validate everything works correctly${NC}"
|
|
else
|
|
echo -e "${RED}❌ Some production services failed to start${NC}"
|
|
echo -e "${YELLOW}Check logs with: docker-compose -f docker-compose.production.yaml logs${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
echo ""
|
|
echo -e "${GREEN}✅ Production deployment completed successfully!${NC}"
|
|
echo -e "${CYAN}🚀 MEV Bot is now running in production mode${NC}"
|
|
echo -e "${CYAN} Monitoring Arbitrum for profitable opportunities...${NC}" |