immortal-bnb/scripts/healthcheck.ts
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

41 lines
1.0 KiB
TypeScript

#!/usr/bin/env bun
/**
* Health Check Script for Docker Container
* Verifies the bot is running and responding correctly
*/
const PORT = process.env.PORT || 3001;
const HEALTH_ENDPOINT = `http://localhost:${PORT}/health`;
async function healthCheck(): Promise<void> {
try {
// Make request to health endpoint
const response = await fetch(HEALTH_ENDPOINT, {
method: 'GET',
headers: { 'Content-Type': 'application/json' },
});
if (!response.ok) {
console.error(`❌ Health check failed: HTTP ${response.status}`);
process.exit(1);
}
const data = await response.json();
// Verify response structure
if (!data.status || data.status !== 'ok') {
console.error('❌ Health check failed: Invalid response', data);
process.exit(1);
}
// Success
console.log('✅ Health check passed');
process.exit(0);
} catch (error) {
console.error('❌ Health check failed:', (error as Error).message);
process.exit(1);
}
}
healthCheck();