File size: 3,229 Bytes
2e222e5 |
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 86 87 88 89 |
#!/usr/bin/env python3
"""
Docker build validation script
Validates that the system is properly set up during container build
"""
import sys
import os
# Add app directory to Python path
sys.path.append('/app')
def main():
"""Main validation function"""
print("π Starting Docker build validation...")
try:
# Test path manager import
from path_config import path_manager
print(f"β
Path manager imported successfully")
# Display environment information
print(f"π Container environment: {path_manager.environment}")
print(f"π Base directory: {path_manager.base_paths['base']}")
print(f"π Data directory: {path_manager.base_paths['data']}")
print(f"π€ Model directory: {path_manager.base_paths['model']}")
print(f"π Logs directory: {path_manager.base_paths['logs']}")
# Check critical files
print("\nπ Checking critical files...")
critical_files = [
(path_manager.get_combined_dataset_path(), "Combined Dataset"),
(path_manager.get_model_file_path(), "Model File"),
(path_manager.get_vectorizer_path(), "Vectorizer File"),
(path_manager.get_metadata_path(), "Metadata File")
]
files_found = 0
for file_path, description in critical_files:
if file_path.exists():
print(f"β
{description}: {file_path}")
files_found += 1
else:
print(f"β {description}: {file_path}")
# Test critical imports
print("\nπ Testing Python imports...")
imports_to_test = [
('pandas', 'Data processing'),
('sklearn', 'Machine learning'),
('streamlit', 'Web interface'),
('fastapi', 'API framework'),
('numpy', 'Numerical computing'),
('requests', 'HTTP client')
]
import_success = 0
for module_name, description in imports_to_test:
try:
__import__(module_name)
print(f"β
{description} ({module_name})")
import_success += 1
except ImportError as e:
print(f"β {description} ({module_name}): {e}")
# Summary
print(f"\nπ Validation Summary:")
print(f" Files found: {files_found}/{len(critical_files)}")
print(f" Imports successful: {import_success}/{len(imports_to_test)}")
# Determine overall status
if files_found >= 3 and import_success == len(imports_to_test):
print("π Docker build validation PASSED")
return 0
elif files_found >= 2 and import_success >= len(imports_to_test) - 1:
print("β οΈ Docker build validation PASSED with warnings")
return 0
else:
print("β Docker build validation FAILED")
return 1
except Exception as e:
print(f"β Docker build validation ERROR: {e}")
import traceback
print(f"Traceback: {traceback.format_exc()}")
return 1
if __name__ == "__main__":
sys.exit(main()) |