164 lines
5.1 KiB
Bash
Executable File
164 lines
5.1 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Staging Deployment Script for MEV Bot
|
|
# This script deploys the MEV bot to a staging environment for testing
|
|
|
|
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'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Script information
|
|
echo -e "${BLUE}🚀 MEV Bot Staging Deployment Script${NC}"
|
|
echo -e "${BLUE}====================================${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.staging exists
|
|
if [ ! -f ".env.staging" ]; then
|
|
echo -e "${RED}❌ Error: .env.staging file not found${NC}"
|
|
echo -e "${YELLOW}Please create .env.staging file with staging configuration${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
# Load staging environment variables
|
|
echo -e "${BLUE}🔧 Loading staging environment variables...${NC}"
|
|
source .env.staging
|
|
|
|
# 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"
|
|
)
|
|
|
|
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.staging${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/staging logs/staging config keys
|
|
|
|
# Build the application
|
|
echo -e "${BLUE}🔨 Building MEV bot application...${NC}"
|
|
go build -o bin/mev-bot-staging 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 staging containers...${NC}"
|
|
docker-compose -f docker-compose.staging.yaml down --remove-orphans 2>/dev/null || true
|
|
|
|
# Pull latest images
|
|
echo -e "${BLUE}⬇️ Pulling latest images...${NC}"
|
|
docker-compose -f docker-compose.staging.yaml pull
|
|
|
|
# Build images
|
|
echo -e "${BLUE}🔨 Building staging images...${NC}"
|
|
docker-compose -f docker-compose.staging.yaml build
|
|
|
|
# Start services
|
|
echo -e "${BLUE}🚀 Starting staging services...${NC}"
|
|
docker-compose -f docker-compose.staging.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-staging" "mev-bot-redis-staging" "mev-bot-postgres-staging" "mev-bot-prometheus-staging" "mev-bot-grafana-staging" "mev-bot-fluentd-staging")
|
|
|
|
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 staging services started successfully!${NC}"
|
|
echo ""
|
|
echo -e "${BLUE}📊 Monitoring endpoints:${NC}"
|
|
echo -e " - MEV Bot Metrics: http://localhost:${METRICS_PORT:-9091}/metrics"
|
|
echo -e " - MEV Bot Health: http://localhost:${HEALTH_PORT:-8081}/health"
|
|
echo -e " - Prometheus: http://localhost:${PROMETHEUS_PORT:-9092}"
|
|
echo -e " - Grafana: http://localhost:${GRAFANA_PORT:-3001}"
|
|
echo ""
|
|
echo -e "${BLUE}📝 Logs:${NC}"
|
|
echo -e " - MEV Bot: docker logs mev-bot-arbitrum-staging"
|
|
echo -e " - Redis: docker logs mev-bot-redis-staging"
|
|
echo -e " - PostgreSQL: docker logs mev-bot-postgres-staging"
|
|
echo ""
|
|
echo -e "${YELLOW}⚠️ Remember to monitor the staging environment closely during testing${NC}"
|
|
echo -e "${YELLOW}⚠️ Staging uses real funds but with reduced position sizes for safety${NC}"
|
|
else
|
|
echo -e "${RED}❌ Some staging services failed to start${NC}"
|
|
echo -e "${YELLOW}Check logs with: docker-compose -f docker-compose.staging.yaml logs${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
echo ""
|
|
echo -e "${GREEN}✅ Staging deployment completed successfully!${NC}" |