Commit
Β·
2e222e5
1
Parent(s):
b4620ce
Update docker_validation.py
Browse files- docker_validation.py +89 -12
docker_validation.py
CHANGED
|
@@ -1,12 +1,89 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Docker build validation script
|
| 4 |
+
Validates that the system is properly set up during container build
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import sys
|
| 8 |
+
import os
|
| 9 |
+
|
| 10 |
+
# Add app directory to Python path
|
| 11 |
+
sys.path.append('/app')
|
| 12 |
+
|
| 13 |
+
def main():
|
| 14 |
+
"""Main validation function"""
|
| 15 |
+
print("π Starting Docker build validation...")
|
| 16 |
+
|
| 17 |
+
try:
|
| 18 |
+
# Test path manager import
|
| 19 |
+
from path_config import path_manager
|
| 20 |
+
print(f"β
Path manager imported successfully")
|
| 21 |
+
|
| 22 |
+
# Display environment information
|
| 23 |
+
print(f"π Container environment: {path_manager.environment}")
|
| 24 |
+
print(f"π Base directory: {path_manager.base_paths['base']}")
|
| 25 |
+
print(f"π Data directory: {path_manager.base_paths['data']}")
|
| 26 |
+
print(f"π€ Model directory: {path_manager.base_paths['model']}")
|
| 27 |
+
print(f"π Logs directory: {path_manager.base_paths['logs']}")
|
| 28 |
+
|
| 29 |
+
# Check critical files
|
| 30 |
+
print("\nπ Checking critical files...")
|
| 31 |
+
critical_files = [
|
| 32 |
+
(path_manager.get_combined_dataset_path(), "Combined Dataset"),
|
| 33 |
+
(path_manager.get_model_file_path(), "Model File"),
|
| 34 |
+
(path_manager.get_vectorizer_path(), "Vectorizer File"),
|
| 35 |
+
(path_manager.get_metadata_path(), "Metadata File")
|
| 36 |
+
]
|
| 37 |
+
|
| 38 |
+
files_found = 0
|
| 39 |
+
for file_path, description in critical_files:
|
| 40 |
+
if file_path.exists():
|
| 41 |
+
print(f"β
{description}: {file_path}")
|
| 42 |
+
files_found += 1
|
| 43 |
+
else:
|
| 44 |
+
print(f"β {description}: {file_path}")
|
| 45 |
+
|
| 46 |
+
# Test critical imports
|
| 47 |
+
print("\nπ Testing Python imports...")
|
| 48 |
+
imports_to_test = [
|
| 49 |
+
('pandas', 'Data processing'),
|
| 50 |
+
('sklearn', 'Machine learning'),
|
| 51 |
+
('streamlit', 'Web interface'),
|
| 52 |
+
('fastapi', 'API framework'),
|
| 53 |
+
('numpy', 'Numerical computing'),
|
| 54 |
+
('requests', 'HTTP client')
|
| 55 |
+
]
|
| 56 |
+
|
| 57 |
+
import_success = 0
|
| 58 |
+
for module_name, description in imports_to_test:
|
| 59 |
+
try:
|
| 60 |
+
__import__(module_name)
|
| 61 |
+
print(f"β
{description} ({module_name})")
|
| 62 |
+
import_success += 1
|
| 63 |
+
except ImportError as e:
|
| 64 |
+
print(f"β {description} ({module_name}): {e}")
|
| 65 |
+
|
| 66 |
+
# Summary
|
| 67 |
+
print(f"\nπ Validation Summary:")
|
| 68 |
+
print(f" Files found: {files_found}/{len(critical_files)}")
|
| 69 |
+
print(f" Imports successful: {import_success}/{len(imports_to_test)}")
|
| 70 |
+
|
| 71 |
+
# Determine overall status
|
| 72 |
+
if files_found >= 3 and import_success == len(imports_to_test):
|
| 73 |
+
print("π Docker build validation PASSED")
|
| 74 |
+
return 0
|
| 75 |
+
elif files_found >= 2 and import_success >= len(imports_to_test) - 1:
|
| 76 |
+
print("β οΈ Docker build validation PASSED with warnings")
|
| 77 |
+
return 0
|
| 78 |
+
else:
|
| 79 |
+
print("β Docker build validation FAILED")
|
| 80 |
+
return 1
|
| 81 |
+
|
| 82 |
+
except Exception as e:
|
| 83 |
+
print(f"β Docker build validation ERROR: {e}")
|
| 84 |
+
import traceback
|
| 85 |
+
print(f"Traceback: {traceback.format_exc()}")
|
| 86 |
+
return 1
|
| 87 |
+
|
| 88 |
+
if __name__ == "__main__":
|
| 89 |
+
sys.exit(main())
|