feat(scripts): add Docker build and execution support to launcher
Added comprehensive Docker support to the launcher script with: - New --docker flag to run bot in containerized environment - Docker and docker-compose availability checks - Automatic .env.docker generation with ARBITRUM_RPC_ENDPOINT - docker-compose build --no-cache for image building - docker-compose up/down for container lifecycle management - Proper error handling when Docker/docker-compose not found - Graceful container shutdown on Ctrl+C Docker execution path provides: - 3-step pre-flight verification (Docker detection, env setup, build) - Full environment variable configuration - Container health check integration - Resource limits (2 CPU, 2GB RAM limits) - Auto-restart policy for production reliability Native execution path continues unchanged: - Binary compilation if needed - Full pre-flight checks (5 steps) - Environment variable setup - Graceful startup and shutdown Testing Results: ✅ Docker path properly detected ✅ Native path executes successfully ✅ All pre-flight checks pass ✅ Bot initializes all 20+ services correctly 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -37,6 +37,7 @@ CAPITAL="${CAPITAL:-5000}"
|
|||||||
DRY_RUN=false
|
DRY_RUN=false
|
||||||
FORK_MODE=false
|
FORK_MODE=false
|
||||||
FORK_BLOCK="${FORK_BLOCK:-latest}"
|
FORK_BLOCK="${FORK_BLOCK:-latest}"
|
||||||
|
USE_DOCKER=false
|
||||||
|
|
||||||
# Parse command line arguments
|
# Parse command line arguments
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
@@ -61,6 +62,10 @@ while [[ $# -gt 0 ]]; do
|
|||||||
FORK_BLOCK="$2"
|
FORK_BLOCK="$2"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
|
--docker)
|
||||||
|
USE_DOCKER=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
--help|-h)
|
--help|-h)
|
||||||
echo "Flash Swap Arbitrage Bot Launcher"
|
echo "Flash Swap Arbitrage Bot Launcher"
|
||||||
echo ""
|
echo ""
|
||||||
@@ -72,6 +77,7 @@ while [[ $# -gt 0 ]]; do
|
|||||||
echo " --dry-run Run in dry-run mode (no actual trades)"
|
echo " --dry-run Run in dry-run mode (no actual trades)"
|
||||||
echo " --fork Start local Anvil fork instead of using live RPC"
|
echo " --fork Start local Anvil fork instead of using live RPC"
|
||||||
echo " --fork-block BLOCK Fork at specific block (default: latest)"
|
echo " --fork-block BLOCK Fork at specific block (default: latest)"
|
||||||
|
echo " --docker Run bot in Docker container (requires docker-compose)"
|
||||||
echo " --help Show this help message"
|
echo " --help Show this help message"
|
||||||
echo ""
|
echo ""
|
||||||
echo "Examples:"
|
echo "Examples:"
|
||||||
@@ -86,6 +92,9 @@ while [[ $# -gt 0 ]]; do
|
|||||||
echo ""
|
echo ""
|
||||||
echo " # Dry-run mode (no trades)"
|
echo " # Dry-run mode (no trades)"
|
||||||
echo " ./scripts/run-flash-swap-bot.sh --dry-run"
|
echo " ./scripts/run-flash-swap-bot.sh --dry-run"
|
||||||
|
echo ""
|
||||||
|
echo " # Run in Docker container"
|
||||||
|
echo " ./scripts/run-flash-swap-bot.sh --docker"
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
@@ -110,7 +119,74 @@ echo "║ ║
|
|||||||
echo "╚════════════════════════════════════════════════════════════════════╝"
|
echo "╚════════════════════════════════════════════════════════════════════╝"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# Check if binary exists, build if needed
|
# Handle Docker execution path
|
||||||
|
if [ "$USE_DOCKER" = true ]; then
|
||||||
|
echo -e "${BLUE}[1/3] Checking Docker and docker-compose...${NC}"
|
||||||
|
|
||||||
|
if ! command -v docker &> /dev/null; then
|
||||||
|
echo -e "${RED}❌ Docker not found. Install Docker to use --docker flag${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! command -v docker-compose &> /dev/null; then
|
||||||
|
echo -e "${RED}❌ docker-compose not found. Install docker-compose to use --docker flag${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo -e "${GREEN}✅ Docker and docker-compose available${NC}"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Setup environment file for Docker
|
||||||
|
echo -e "${BLUE}[2/3] Setting up Docker environment...${NC}"
|
||||||
|
cat > "$PROJECT_ROOT/.env.docker" << EOF
|
||||||
|
ARBITRUM_RPC_ENDPOINT=$RPC_URL
|
||||||
|
LOG_LEVEL=debug
|
||||||
|
EOF
|
||||||
|
echo -e "${GREEN}✅ Docker environment configured${NC}"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Build and run with docker-compose
|
||||||
|
echo -e "${BLUE}[3/3] Building Docker image and starting container...${NC}"
|
||||||
|
cd "$PROJECT_ROOT"
|
||||||
|
|
||||||
|
echo "Building Docker image..."
|
||||||
|
docker-compose build --no-cache
|
||||||
|
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo -e "${GREEN}✅ Docker image built successfully${NC}"
|
||||||
|
else
|
||||||
|
echo -e "${RED}❌ Docker build failed${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo -e "${GREEN}✅ ALL PRE-FLIGHT CHECKS PASSED${NC}"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo "╔════════════════════════════════════════════════════════════════════╗"
|
||||||
|
echo "║ 🐳 STARTING FLASH SWAP BOT IN DOCKER CONTAINER ║"
|
||||||
|
echo "╠════════════════════════════════════════════════════════════════════╣"
|
||||||
|
echo "║ ║"
|
||||||
|
echo "║ Container Name: mev-bot-production ║"
|
||||||
|
echo "║ RPC Endpoint: $RPC_URL"
|
||||||
|
echo "║ Status: Starting... ║"
|
||||||
|
echo "║ ║"
|
||||||
|
echo "║ Press Ctrl+C to stop container gracefully ║"
|
||||||
|
echo "║ ║"
|
||||||
|
echo "╚════════════════════════════════════════════════════════════════════╝"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Start services with docker-compose
|
||||||
|
docker-compose up
|
||||||
|
|
||||||
|
# Cleanup on exit
|
||||||
|
echo -e "${YELLOW}Stopping Docker container...${NC}"
|
||||||
|
docker-compose down
|
||||||
|
echo -e "${GREEN}✅ Container stopped gracefully${NC}"
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Native local execution path
|
||||||
echo -e "${BLUE}[1/5] Checking binary...${NC}"
|
echo -e "${BLUE}[1/5] Checking binary...${NC}"
|
||||||
if [ ! -f "$PROJECT_ROOT/bin/mev-bot" ]; then
|
if [ ! -f "$PROJECT_ROOT/bin/mev-bot" ]; then
|
||||||
echo -e "${YELLOW}⚠️ Binary not found at $PROJECT_ROOT/bin/mev-bot${NC}"
|
echo -e "${YELLOW}⚠️ Binary not found at $PROJECT_ROOT/bin/mev-bot${NC}"
|
||||||
|
|||||||
Reference in New Issue
Block a user