Completed clean root directory structure: - Root now contains only: .git, .env, docs/, orig/ - Moved all remaining files and directories to orig/: - Config files (.claude, .dockerignore, .drone.yml, etc.) - All .env variants (except active .env) - Git config (.gitconfig, .github, .gitignore, etc.) - Tool configs (.golangci.yml, .revive.toml, etc.) - Documentation (*.md files, @prompts) - Build files (Dockerfiles, Makefile, go.mod, go.sum) - Docker compose files - All source directories (scripts, tests, tools, etc.) - Runtime directories (logs, monitoring, reports) - Dependency files (node_modules, lib, cache) - Special files (--delete) - Removed empty runtime directories (bin/, data/) V2 structure is now clean: - docs/planning/ - V2 planning documents - orig/ - Complete V1 codebase preserved - .env - Active environment config (not in git) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
173 lines
5.6 KiB
Bash
Executable File
173 lines
5.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# Production Deployment Script for MEV Bot
|
|
# This script deploys the MEV bot to a production environment for live trading
|
|
# Supports: Podman (preferred) and Docker
|
|
|
|
set -euo pipefail # Exit on any error, undefined vars, pipe failures
|
|
|
|
# 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
|
|
|
|
# Load container runtime detection
|
|
source "$(dirname "$0")/container-runtime.sh" init
|
|
|
|
if [[ -z "$CONTAINER_RUNTIME" ]]; then
|
|
echo -e "${RED}❌ Error: No container runtime found (podman or docker required)${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
if [[ -z "$COMPOSE_CMD" ]]; then
|
|
echo -e "${RED}❌ Error: No compose command available${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
echo -e "${GREEN}✅ Container runtime available: $CONTAINER_RUNTIME${NC}"
|
|
echo -e "${GREEN}✅ Compose command: $COMPOSE_CMD${NC}"
|
|
|
|
# Stop any existing containers
|
|
echo -e "${BLUE}⏹️ Stopping any existing production containers...${NC}"
|
|
$COMPOSE_CMD -f docker-compose.production.yaml down --remove-orphans 2>/dev/null || true
|
|
|
|
# Pull latest images
|
|
echo -e "${BLUE}⬇️ Pulling latest images...${NC}"
|
|
$COMPOSE_CMD -f docker-compose.production.yaml pull
|
|
|
|
# Build images
|
|
echo -e "${BLUE}🔨 Building production images...${NC}"
|
|
$COMPOSE_CMD -f docker-compose.production.yaml build
|
|
|
|
# Start services
|
|
echo -e "${BLUE}🚀 Starting production services...${NC}"
|
|
$COMPOSE_CMD -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 $CONTAINER_RUNTIME 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: $CONTAINER_RUNTIME logs mev-bot-arbitrum"
|
|
echo -e " - Redis: $CONTAINER_RUNTIME logs mev-bot-redis"
|
|
echo -e " - PostgreSQL: $CONTAINER_RUNTIME 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: $COMPOSE_CMD -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}" |