Claude b4671d5735
feat: Add comprehensive CI/CD, Docker, and DevOps infrastructure
GitHub Actions CI/CD Pipeline (.github/workflows/ci.yml):
- Automated testing for backend, frontend, and smart contracts
- Security scanning with Trivy
- Docker image building on main branch
- Deployment validation checks
- Multi-job workflow with dependency management

Docker Infrastructure:
- Production-optimized Dockerfile with multi-stage build
  - Base image: oven/bun:1 for fast runtime
  - Non-root user for security (botuser)
  - Health check integration
  - Optimized layer caching

- docker-compose.yml for easy deployment
  - Single-command deployment
  - Volume management for logs and data
  - Network isolation
  - Health checks and restart policies
  - Ready for PostgreSQL and Redis integration

- .dockerignore for optimized builds
  - Excludes node_modules, tests, docs
  - Reduces image size significantly

DevOps Scripts:
- scripts/healthcheck.ts - Container health verification
  - HTTP health endpoint check
  - Exit codes for Docker health status
  - Used by Docker HEALTHCHECK directive

- scripts/monitor.ts - Bot monitoring and statistics
  - Real-time bot status display
  - Trading performance metrics (win rate, P/L)
  - System information
  - Watch mode for continuous monitoring
  - Performance indicators and alerts

- scripts/backup.sh - Automated backup system
  - Backs up logs, data, configs
  - Excludes secrets for security
  - Compression and retention (keeps last 7)
  - Backup metadata and restore instructions

- scripts/setup.sh - Developer onboarding
  - Interactive setup wizard
  - Dependency installation (Bun, Node.js)
  - Environment file creation
  - Directory structure setup
  - Optional Hardhat installation
  - Next steps guidance

Environment Templates:
- .env.development - Safe defaults for local dev
  - Testnet configuration
  - Conservative trading limits
  - Debug logging enabled

- .env.production (template only, not committed)
  - Mainnet configuration
  - Production security settings
  - Monitoring integrations
  - Strong API key requirements

Package.json Scripts:
- monitor: Check bot status and performance
- monitor⌚ Continuous monitoring
- backup: Create system backups
- setup: Run setup wizard
- docker:build: Build Docker image
- docker:run: Start with Docker Compose
- docker:stop: Stop containers
- docker:logs: View container logs
- validate: Pre-deployment validation

Documentation:
- DOCKER.md - Complete Docker deployment guide
  - Quick start instructions
  - Configuration management
  - Multi-architecture builds
  - Docker Compose usage
  - Monitoring and logging
  - Backup and restore procedures
  - Production best practices
  - Troubleshooting guide
  - CI/CD integration examples

This infrastructure enables:
✅ One-command deployment (docker-compose up)
✅ Automated testing and security scanning
✅ Production-grade monitoring and health checks
✅ Easy developer onboarding (setup.sh)
✅ Comprehensive backup and disaster recovery
✅ CI/CD pipeline for automated deployments
✅ Multi-environment support (dev/prod)
2025-11-08 20:09:35 +00:00

240 lines
8.1 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# Comprehensive Setup Script for Immortal AI Trading Bot
# Sets up development environment with all dependencies
set -e # Exit on error
echo "🤖 Immortal AI Trading Bot - Development Setup"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Print colored message
print_success() {
echo -e "${GREEN}✅ $1${NC}"
}
print_error() {
echo -e "${RED}❌ $1${NC}"
}
print_warning() {
echo -e "${YELLOW}⚠️ $1${NC}"
}
print_info() {
echo -e "${BLUE}ℹ️ $1${NC}"
}
# Step 1: Check system requirements
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "1️⃣ Checking System Requirements"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
# Check for Bun
if command_exists bun; then
BUN_VERSION=$(bun --version)
print_success "Bun installed (version $BUN_VERSION)"
else
print_warning "Bun not found - Installing Bun..."
curl -fsSL https://bun.sh/install | bash
export PATH="$HOME/.bun/bin:$PATH"
if command_exists bun; then
print_success "Bun installed successfully"
else
print_error "Failed to install Bun. Please install manually: https://bun.sh"
exit 1
fi
fi
# Check for Node.js (fallback)
if command_exists node; then
NODE_VERSION=$(node --version)
print_success "Node.js installed ($NODE_VERSION)"
else
print_warning "Node.js not found (optional - Bun can be used instead)"
fi
# Check for Git
if command_exists git; then
GIT_VERSION=$(git --version)
print_success "Git installed"
else
print_error "Git not found. Please install Git first."
exit 1
fi
echo ""
# Step 2: Install backend dependencies
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "2️⃣ Installing Backend Dependencies"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
print_info "Installing backend packages..."
bun install
if [ $? -eq 0 ]; then
print_success "Backend dependencies installed"
else
print_error "Failed to install backend dependencies"
exit 1
fi
echo ""
# Step 3: Install frontend dependencies
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "3️⃣ Installing Frontend Dependencies"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
if [ -d "apps/frontend" ]; then
print_info "Installing frontend packages..."
cd apps/frontend
bun install
cd ../..
print_success "Frontend dependencies installed"
else
print_warning "Frontend directory not found, skipping"
fi
echo ""
# Step 4: Setup environment file
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "4️⃣ Setting Up Environment"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
if [ ! -f ".env" ]; then
print_info "Creating .env file from template..."
cp .env.example .env
print_success ".env file created"
print_warning "⚠️ IMPORTANT: Edit .env and add your API keys:"
echo " - WALLET_PRIVATE_KEY (your BNB wallet private key)"
echo " - OPENROUTER_API_KEY (from https://openrouter.ai)"
echo " - Other optional keys (see .env file)"
else
print_info ".env file already exists (not overwriting)"
fi
echo ""
# Step 5: Install Hardhat for smart contracts
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "5️⃣ Installing Smart Contract Tools (Optional)"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
read -p "Install Hardhat for smart contract deployment? (y/N) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
print_info "Installing Hardhat and dependencies..."
npm install --save-dev \
hardhat \
@nomicfoundation/hardhat-toolbox \
@nomicfoundation/hardhat-verify \
@openzeppelin/contracts \
@typechain/ethers-v6 \
@typechain/hardhat \
typechain
print_success "Hardhat installed"
else
print_info "Skipping Hardhat installation"
fi
echo ""
# Step 6: Create necessary directories
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "6️⃣ Creating Project Directories"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
mkdir -p logs
mkdir -p data
print_success "Created logs and data directories"
echo ""
# Step 7: Verify setup
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "7️⃣ Verifying Setup"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
# Check if critical files exist
CRITICAL_FILES=(
"src/index.ts"
"src/config.ts"
"src/api-server.ts"
".env"
"package.json"
)
for file in "${CRITICAL_FILES[@]}"; do
if [ -f "$file" ]; then
print_success "$file exists"
else
print_error "$file not found"
fi
done
echo ""
# Step 8: Display next steps
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "✅ Setup Complete!"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo "📝 Next Steps:"
echo ""
echo "1️⃣ Configure Environment Variables:"
echo " ${BLUE}nano .env${NC}"
echo " Add your WALLET_PRIVATE_KEY and OPENROUTER_API_KEY"
echo ""
echo "2️⃣ Get Testnet BNB:"
echo " ${BLUE}https://testnet.bnbchain.org/faucet-smart${NC}"
echo ""
echo "3️⃣ Start Backend Development Server:"
echo " ${BLUE}bun run dev${NC}"
echo ""
echo "4️⃣ Start Frontend (in another terminal):"
echo " ${BLUE}cd apps/frontend && bun run dev${NC}"
echo ""
echo "5️⃣ Access Dashboard:"
echo " ${BLUE}http://localhost:3000${NC}"
echo ""
echo "📖 Documentation:"
echo " - README.md - Quick start guide"
echo " - QUICKSTART.md - Detailed setup instructions"
echo " - DEPLOYMENT.md - Production deployment guide"
echo " - TESTING.md - Testing procedures"
echo " - contracts/README.md - Smart contract deployment"
echo ""
echo "🐳 Docker Deployment:"
echo " ${BLUE}docker-compose up -d${NC}"
echo ""
echo "💡 Useful Commands:"
echo " bun test - Run tests"
echo " bun run docker:build - Build Docker image"
echo " bun run healthcheck - Check bot health"
echo " npx hardhat compile - Compile smart contracts"
echo ""
echo "🎉 Happy Trading! Remember to start with testnet first."
echo ""