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

119 lines
3.3 KiB
Bash
Executable File

#!/bin/bash
# Backup Script for Immortal AI Trading Bot
# Backs up logs, configuration, and trade data
set -e
# Configuration
BACKUP_DIR="${BACKUP_DIR:-./backups}"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_NAME="immortal-bot-backup-${TIMESTAMP}"
BACKUP_PATH="${BACKUP_DIR}/${BACKUP_NAME}"
# Colors
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
echo -e "${BLUE}🔄 Starting backup...${NC}\n"
# Create backup directory
mkdir -p "${BACKUP_PATH}"
echo -e "${GREEN}✅${NC} Created backup directory: ${BACKUP_PATH}"
# Backup logs
if [ -d "logs" ]; then
echo -e "${BLUE}📝${NC} Backing up logs..."
cp -r logs "${BACKUP_PATH}/"
echo -e "${GREEN}✅${NC} Logs backed up"
else
echo -e "${YELLOW}⚠️${NC} No logs directory found"
fi
# Backup data directory (if exists)
if [ -d "data" ]; then
echo -e "${BLUE}💾${NC} Backing up data..."
cp -r data "${BACKUP_PATH}/"
echo -e "${GREEN}✅${NC} Data backed up"
fi
# Backup configuration (without secrets)
echo -e "${BLUE}⚙️${NC} Backing up configuration..."
if [ -f ".env.example" ]; then
cp .env.example "${BACKUP_PATH}/"
fi
if [ -f "package.json" ]; then
cp package.json "${BACKUP_PATH}/"
fi
echo -e "${GREEN}✅${NC} Configuration backed up"
# Backup contract ABIs (if compiled)
if [ -d "artifacts" ]; then
echo -e "${BLUE}📜${NC} Backing up contract ABIs..."
mkdir -p "${BACKUP_PATH}/artifacts"
cp -r artifacts/contracts "${BACKUP_PATH}/artifacts/" 2>/dev/null || true
echo -e "${GREEN}✅${NC} Contract ABIs backed up"
fi
# Create backup info file
cat > "${BACKUP_PATH}/backup-info.txt" << EOF
Immortal AI Trading Bot - Backup
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Backup Date: $(date)
Backup Name: ${BACKUP_NAME}
Hostname: $(hostname)
User: $(whoami)
Contents:
- Logs
- Data files
- Configuration (without secrets)
- Contract ABIs
⚠️ NOT INCLUDED (security):
- .env file with secrets
- Private keys
- API keys
To restore:
1. Extract backup to project directory
2. Manually restore .env file with your secrets
3. Restart bot
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
EOF
# Compress backup
echo -e "${BLUE}📦${NC} Compressing backup..."
cd "${BACKUP_DIR}"
tar -czf "${BACKUP_NAME}.tar.gz" "${BACKUP_NAME}"
rm -rf "${BACKUP_NAME}"
cd - > /dev/null
# Calculate size
BACKUP_SIZE=$(du -h "${BACKUP_DIR}/${BACKUP_NAME}.tar.gz" | cut -f1)
echo ""
echo -e "${GREEN}✅ Backup complete!${NC}"
echo -e " Location: ${BACKUP_DIR}/${BACKUP_NAME}.tar.gz"
echo -e " Size: ${BACKUP_SIZE}"
echo ""
# Cleanup old backups (keep last 7)
echo -e "${BLUE}🧹${NC} Cleaning up old backups (keeping last 7)..."
cd "${BACKUP_DIR}"
ls -t immortal-bot-backup-*.tar.gz 2>/dev/null | tail -n +8 | xargs -r rm -f
BACKUP_COUNT=$(ls -1 immortal-bot-backup-*.tar.gz 2>/dev/null | wc -l)
echo -e "${GREEN}✅${NC} ${BACKUP_COUNT} backups retained"
cd - > /dev/null
echo ""
echo -e "${BLUE}💡 Tips:${NC}"
echo " - Store backups in a secure location"
echo " - Keep .env file separately (encrypted)"
echo " - Test restore procedure periodically"
echo " - Consider offsite backup for critical data"
echo ""