-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathverify_docker_usage.py
More file actions
85 lines (69 loc) · 3.34 KB
/
verify_docker_usage.py
File metadata and controls
85 lines (69 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import sys
import os
import logging
# Add backend to path so we can import services
sys.path.append(os.path.join(os.getcwd(), 'backend'))
try:
from services.docker_sandbox import DockerSandboxService, DOCKER_AVAILABLE
import docker
except ImportError as e:
# If docker is not installed, it will raise ImportError (or ModuleNotFoundError)
# But DOCKER_AVAILABLE might be False even if import succeeds if inside DockerSandboxService logic changes
print(f"❌ Could not import DockerSandboxService or docker: {e}")
print("Make sure you are running this from the project root.")
sys.exit(1)
# Configure logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("DockerVerification")
def verify_docker():
print("🔍 Verifying Docker Configuration...\n")
# 1. Check if docker python package is installed (checked by import)
if not DOCKER_AVAILABLE:
print("❌ Docker Python SDK is NOT installed.")
print(" Run: pip install docker")
return
print("✅ Docker Python SDK is installed.")
# 2. Check if DockerSandboxService can connect to Docker Daemon
try:
# Debug: Print env vars
print(f" DOCKER_HOST: {os.environ.get('DOCKER_HOST', 'Not Set')}")
print(f" DOCKER_CERT_PATH: {os.environ.get('DOCKER_CERT_PATH', 'Not Set')}")
print(f" DOCKER_TLS_VERIFY: {os.environ.get('DOCKER_TLS_VERIFY', 'Not Set')}")
try:
client = docker.from_env()
client.ping()
print("✅ Docker Daemon is running and accessible (via docker.from_env).")
sandbox = DockerSandboxService()
except Exception as e:
print(f"❌ docker.from_env() failed: {e}")
print(f" Attempting explicit socket connection...")
try:
client = docker.DockerClient(base_url='unix://var/run/docker.sock')
client.ping()
print("✅ Docker Daemon is accessible via unix://var/run/docker.sock")
except Exception as e2:
print(f"❌ Explicit socket connection failed: {e2}")
sandbox = None
if sandbox or (client and client.ping()):
# Get some info
version = client.version()
print(f" Docker Version: {version.get('Version', 'Unknown')}")
print(f" Platform: {version.get('Platform', {}).get('Name', 'Unknown')}")
else:
print("❌ Docker Daemon is NOT accessible.")
except Exception as e:
print(f"❌ Error initializing DockerSandboxService: {e}")
# 3. Check Environment Variables impacting CodeExecutionService
print("\n🔍 Checking Environment Configuration for Code Execution:")
use_aws = os.environ.get('USE_AWS_SANDBOX', 'false').lower() == 'true'
dev_mode = os.environ.get('DEV_MODE', 'false').lower() == 'true'
print(f" USE_AWS_SANDBOX: {use_aws}")
print(f" DEV_MODE: {dev_mode}")
if dev_mode:
print("\nℹ️ DEV_MODE is enabled. CodeExecutionService will prioritize Local Docker.")
elif use_aws:
print("\nℹ️ USE_AWS_SANDBOX is enabled. CodeExecutionService will try AWS Fargate first.")
else:
print("\nℹ️ Default mode. CodeExecutionService will try Local Docker first, then fallback to local execution.")
if __name__ == "__main__":
verify_docker()