Files
foxhunt/scripts/validate-docker-config.sh
jgrusewski 8d89fe80ff chore: Second cleanup wave - organize root directory
- Archive: 85 agent .txt files → docs/archive/agents/legacy_txt/
- Scripts: Move 110 shell scripts → scripts/ (keep deploy.sh in root)
- Models: Move 18 .safetensors → ml/models/checkpoints/training_artifacts/
- Delete: 34 directories (~33GB freed) - target/, coverage_*, test artifacts
- Build: Clean 14 build artifacts (.rlib, .o, .pid, binaries)
- Tests: Move 14 .rs files → tests/standalone/
- SQL: Move 5 files → sql/ (keep init-db*.sql for Docker)
- Wave 153: Archive to docs/archive/historical/wave153/
- Docs: Archive 9 markdown files to wave_d/reports/ and historical/

Total impact: ~34GB freed (both waves), root directory cleaned from 583 to ~40 essential files
Directory count reduced from 65 to 31 (52% reduction)
All historical data preserved in organized archive structure
2025-10-30 01:26:02 +01:00

224 lines
7.4 KiB
Bash
Executable File

#!/bin/bash
# Docker Configuration Validation Script for Foxhunt HFT System
# This script validates all Docker configurations and fixes common issues
set -e
echo "🔍 Validating Docker Configuration for Foxhunt HFT System..."
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Configuration validation results
VALIDATION_PASSED=true
# Function to print validation results
print_result() {
local status=$1
local message=$2
if [ "$status" = "PASS" ]; then
echo -e "${GREEN}$message${NC}"
elif [ "$status" = "WARN" ]; then
echo -e "${YELLOW}⚠️ $message${NC}"
else
echo -e "${RED}$message${NC}"
VALIDATION_PASSED=false
fi
}
echo -e "${BLUE}📋 Configuration Validation Report${NC}"
echo "=================================================="
# 1. Check Docker Compose Files
echo -e "\n${BLUE}1. Docker Compose Files${NC}"
if [ -f "docker-compose.yml" ]; then
print_result "PASS" "docker-compose.yml exists"
else
print_result "FAIL" "docker-compose.yml missing"
fi
if [ -f "docker-compose.dev.yml" ]; then
print_result "PASS" "docker-compose.dev.yml exists"
else
print_result "WARN" "docker-compose.dev.yml missing (optional)"
fi
# 2. Check Dockerfiles
echo -e "\n${BLUE}2. Dockerfiles${NC}"
if [ -f "Dockerfile" ]; then
print_result "PASS" "Root Dockerfile exists"
else
print_result "WARN" "Root Dockerfile missing (using service-specific Dockerfiles)"
fi
# Check service Dockerfiles
services=("trading_service" "backtesting_service" "ml_training_service")
for service in "${services[@]}"; do
if [ -f "services/$service/Dockerfile" ]; then
print_result "PASS" "services/$service/Dockerfile exists"
else
print_result "FAIL" "services/$service/Dockerfile missing"
fi
done
if [ -f "tli/Dockerfile" ]; then
print_result "PASS" "tli/Dockerfile exists"
else
print_result "FAIL" "tli/Dockerfile missing"
fi
# 3. Environment Configuration
echo -e "\n${BLUE}3. Environment Configuration${NC}"
if [ -f ".env" ]; then
print_result "PASS" ".env file exists"
# Check DATABASE_URL in .env
DB_URL=$(grep "^DATABASE_URL=" .env | cut -d'=' -f2-)
if [[ $DB_URL == *"foxhunt_dev_password"* && $DB_URL == *"foxhunt"* ]]; then
print_result "PASS" "DATABASE_URL credentials match docker-compose.yml"
else
print_result "FAIL" "DATABASE_URL credentials mismatch with docker-compose.yml"
fi
else
print_result "FAIL" ".env file missing"
fi
# 4. PostgreSQL Configuration Consistency
echo -e "\n${BLUE}4. PostgreSQL Configuration${NC}"
# Extract postgres config from docker-compose.yml
if [ -f "docker-compose.yml" ]; then
POSTGRES_DB=$(grep "POSTGRES_DB:" docker-compose.yml | head -1 | awk '{print $2}')
POSTGRES_USER=$(grep "POSTGRES_USER:" docker-compose.yml | head -1 | awk '{print $2}')
POSTGRES_PASSWORD=$(grep "POSTGRES_PASSWORD:" docker-compose.yml | head -1 | awk '{print $2}')
echo "Docker Compose PostgreSQL Config:"
echo " Database: $POSTGRES_DB"
echo " User: $POSTGRES_USER"
echo " Password: $POSTGRES_PASSWORD"
# Check if .env DATABASE_URL matches
if [ -f ".env" ]; then
ENV_DB_URL=$(grep "^DATABASE_URL=" .env | cut -d'=' -f2-)
if [[ $ENV_DB_URL == *"$POSTGRES_USER:$POSTGRES_PASSWORD@"*"/$POSTGRES_DB"* ]]; then
print_result "PASS" "PostgreSQL credentials consistent between docker-compose.yml and .env"
else
print_result "FAIL" "PostgreSQL credentials inconsistent between docker-compose.yml and .env"
echo "Expected: postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:5432/$POSTGRES_DB"
echo "Found in .env: $ENV_DB_URL"
fi
fi
fi
# 5. Check Database Init Scripts
echo -e "\n${BLUE}5. Database Initialization Scripts${NC}"
if [ -f "init-db-dev.sql" ]; then
# Check if init script creates correct database name
INIT_DB_NAME=$(grep "CREATE DATABASE" init-db-dev.sql | awk '{print $3}' | tr -d ';')
if [ "$INIT_DB_NAME" = "$POSTGRES_DB" ]; then
print_result "PASS" "init-db-dev.sql creates correct database ($INIT_DB_NAME)"
else
print_result "FAIL" "Database name mismatch: init-db-dev.sql creates '$INIT_DB_NAME', expected '$POSTGRES_DB'"
fi
else
print_result "WARN" "init-db-dev.sql missing"
fi
# 6. Network Configuration
echo -e "\n${BLUE}6. Network Configuration${NC}"
if grep -q "networks:" docker-compose.yml 2>/dev/null; then
print_result "PASS" "Docker networks defined"
else
print_result "WARN" "No custom Docker networks defined"
fi
# 7. Health Checks
echo -e "\n${BLUE}7. Health Checks${NC}"
health_check_count=$(grep -c "healthcheck:" docker-compose.yml 2>/dev/null || echo "0")
if [ "$health_check_count" -gt "0" ]; then
print_result "PASS" "Health checks configured ($health_check_count services)"
else
print_result "WARN" "No health checks configured"
fi
# 8. Volume Mounts
echo -e "\n${BLUE}8. Volume Configuration${NC}"
if grep -q "volumes:" docker-compose.yml 2>/dev/null; then
print_result "PASS" "Docker volumes configured"
else
print_result "WARN" "No Docker volumes configured"
fi
# 9. Port Configuration
echo -e "\n${BLUE}9. Port Configuration${NC}"
port_conflicts=()
if command -v netstat >/dev/null 2>&1; then
# Check for port conflicts
ports=("5432" "6379" "8086" "8200" "9090" "3000" "50051" "50052" "50053")
for port in "${ports[@]}"; do
if netstat -tuln 2>/dev/null | grep -q ":$port "; then
port_conflicts+=("$port")
fi
done
if [ ${#port_conflicts[@]} -eq 0 ]; then
print_result "PASS" "No port conflicts detected"
else
print_result "WARN" "Potential port conflicts: ${port_conflicts[*]}"
fi
fi
# 10. Check if Docker services can be parsed
echo -e "\n${BLUE}10. Docker Compose Syntax${NC}"
if docker-compose -f docker-compose.yml config >/dev/null 2>&1; then
print_result "PASS" "docker-compose.yml syntax is valid"
else
print_result "FAIL" "docker-compose.yml has syntax errors"
fi
if [ -f "docker-compose.dev.yml" ]; then
if docker-compose -f docker-compose.dev.yml config >/dev/null 2>&1; then
print_result "PASS" "docker-compose.dev.yml syntax is valid"
else
print_result "FAIL" "docker-compose.dev.yml has syntax errors"
fi
fi
# Summary
echo -e "\n${BLUE}=================================================="
echo "📊 Validation Summary"
echo "==================================================${NC}"
if [ "$VALIDATION_PASSED" = true ]; then
echo -e "${GREEN}🎉 All critical validations passed!${NC}"
echo ""
echo "✅ Your Docker configuration is ready for deployment"
echo ""
echo "Next steps:"
echo "1. Start services: docker-compose up -d"
echo "2. Check service health: docker-compose ps"
echo "3. View logs: docker-compose logs -f [service_name]"
else
echo -e "${RED}❌ Some validations failed${NC}"
echo ""
echo "Please fix the issues above before proceeding."
echo ""
echo "Common fixes:"
echo "1. Update DATABASE_URL in .env to match docker-compose.yml"
echo "2. Ensure all required Dockerfiles exist"
echo "3. Fix any Docker Compose syntax errors"
fi
echo ""
echo "📝 Configuration Details:"
echo " Database: $POSTGRES_DB"
echo " User: $POSTGRES_USER"
echo " Password: [configured]"
echo " Environment file: .env"
echo ""
exit $([ "$VALIDATION_PASSED" = true ] && echo 0 || echo 1)