You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
91 lines
3.2 KiB
Python
91 lines
3.2 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test Docker setup for Know Foolery project
|
|
Validates Docker Compose configuration and tests basic functionality
|
|
"""
|
|
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
def run_command(cmd, description=""):
|
|
"""Run a command and return success status"""
|
|
try:
|
|
result = subprocess.run(cmd, shell=True, capture_output=True, text=True, timeout=30)
|
|
if result.returncode == 0:
|
|
print(f"✅ {description or cmd}")
|
|
return True, result.stdout
|
|
else:
|
|
print(f"❌ {description or cmd}")
|
|
print(f" Error: {result.stderr.strip()}")
|
|
return False, result.stderr
|
|
except subprocess.TimeoutExpired:
|
|
print(f"⏰ {description or cmd} - TIMEOUT")
|
|
return False, "Timeout"
|
|
except Exception as e:
|
|
print(f"💥 {description or cmd} - EXCEPTION: {e}")
|
|
return False, str(e)
|
|
|
|
def test_docker_setup():
|
|
"""Test the complete Docker setup"""
|
|
print("🐳 Testing Know Foolery Docker Setup...")
|
|
print("=" * 50)
|
|
|
|
issues = []
|
|
|
|
# Test Docker availability
|
|
print("\n🔧 Docker Environment:")
|
|
success, output = run_command("docker --version", "Docker is installed")
|
|
if not success:
|
|
issues.append("Docker not available")
|
|
return False
|
|
|
|
success, output = run_command("docker compose version", "Docker Compose is available")
|
|
if not success:
|
|
issues.append("Docker Compose not available")
|
|
return False
|
|
|
|
# Test Docker Compose configuration
|
|
print("\n📋 Docker Compose Configuration:")
|
|
success, output = run_command("docker compose config --quiet", "Docker Compose configuration is valid")
|
|
if not success:
|
|
issues.append("Invalid Docker Compose configuration")
|
|
|
|
# Test building (dry run - just validate Dockerfiles)
|
|
print("\n🏗️ Docker Build Validation:")
|
|
success, output = run_command("docker compose config --services", "Services are properly defined")
|
|
if success:
|
|
services = output.strip().split('\n')
|
|
print(f" Found {len(services)} services: {', '.join(services)}")
|
|
else:
|
|
issues.append("Cannot list services")
|
|
|
|
# Test specific service configurations
|
|
print("\n🔍 Service Configuration Details:")
|
|
test_commands = [
|
|
("docker compose config --service-ports api-gateway", "API Gateway ports configured"),
|
|
("docker compose config --service-ports frontend", "Frontend ports configured"),
|
|
("docker compose config --service-ports game-service", "Game Service ports configured"),
|
|
]
|
|
|
|
for cmd, desc in test_commands:
|
|
run_command(cmd, desc)
|
|
|
|
# Summary
|
|
print("\n" + "=" * 50)
|
|
if issues:
|
|
print(f"❌ Docker setup has {len(issues)} issues:")
|
|
for issue in issues:
|
|
print(f" • {issue}")
|
|
return False
|
|
else:
|
|
print("✅ Docker setup is READY!")
|
|
print("\n🚀 Ready to run:")
|
|
print(" make build # Build all containers")
|
|
print(" make up # Start all services")
|
|
print(" make status # Check service status")
|
|
return True
|
|
|
|
if __name__ == "__main__":
|
|
success = test_docker_setup()
|
|
exit(0 if success else 1) |