-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathvalidate-deployment.py
More file actions
158 lines (134 loc) · 4.67 KB
/
Copy pathvalidate-deployment.py
File metadata and controls
158 lines (134 loc) · 4.67 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/env python3
"""
VishwaGuru Deployment Validation Script
Validates the deployment configuration and environment setup.
"""
import os
import sys
import subprocess
from pathlib import Path
def check_python_version():
"""Check Python version compatibility"""
version = sys.version_info
if version.major == 3 and version.minor >= 9:
print("Python version compatible")
return True
else:
print(f"Python {version.major}.{version.minor} not compatible. Need Python 3.9+")
return False
def check_dependencies():
"""Check if required packages can be installed"""
try:
result = subprocess.run([
sys.executable, "-c",
"import fastapi, uvicorn, sqlalchemy, pydantic; print('Core dependencies available')"
], capture_output=True, text=True, timeout=30)
if result.returncode == 0:
print("Core dependencies available")
return True
else:
print("Core dependencies missing")
print(result.stderr)
return False
except Exception as e:
print(f"Error checking dependencies: {e}")
return False
def check_environment_variables():
"""Check environment variable configuration"""
required_vars = ["GEMINI_API_KEY", "TELEGRAM_BOT_TOKEN", "FRONTEND_URL"]
optional_vars = ["DATABASE_URL", "ENVIRONMENT", "DEBUG"]
missing_required = []
for var in required_vars:
if not os.getenv(var):
missing_required.append(var)
if missing_required:
print("Missing required environment variables:")
for var in missing_required:
print(f" - {var}")
return False
print("Required environment variables present")
# Check optional variables
for var in optional_vars:
if os.getenv(var):
print(f"{var} configured")
else:
print(f"{var} not set (will use defaults)")
return True
def check_file_structure():
"""Check project file structure"""
required_files = [
"backend/main.py",
"backend/requirements.txt",
"render.yaml",
"start-backend.py"
]
missing_files = []
for file_path in required_files:
if not Path(file_path).exists():
missing_files.append(file_path)
if missing_files:
print("Missing required files:")
for file_path in missing_files:
print(f" - {file_path}")
return False
print("Project structure correct")
return True
def check_database_connectivity():
"""Test database connection"""
try:
from sqlalchemy import text
from backend.database import engine
with engine.connect() as conn:
conn.execute(text("SELECT 1"))
print("Database connection successful")
return True
except Exception as e:
print(f"Database connection failed: {e}")
return False
def check_api_import():
"""Test backend API import"""
try:
# Set minimal environment for testing
os.environ.setdefault("FRONTEND_URL", "http://localhost:5173")
os.environ.setdefault("GEMINI_API_KEY", "test")
os.environ.setdefault("TELEGRAM_BOT_TOKEN", "test")
sys.path.insert(0, str(Path("backend").absolute()))
import backend.main
app = backend.main.app
print("Backend API imports successfully")
return True
except Exception as e:
print(f"Backend API import failed: {e}")
return False
def main():
"""Run all validation checks"""
print("🔍 VishwaGuru Deployment Validation")
print("=" * 40)
checks = [
("Python Version", check_python_version),
("File Structure", check_file_structure),
("Dependencies", check_dependencies),
("Environment Variables", check_environment_variables),
("API Import", check_api_import),
("Database Connectivity", check_database_connectivity),
]
passed = 0
total = len(checks)
for name, check_func in checks:
print(f"\n📋 Checking {name}...")
if check_func():
passed += 1
print(f"\n📊 Validation Results: {passed}/{total} checks passed")
if passed == total:
print("🎉 All validation checks passed! Ready for deployment.")
print("\n🚀 Next steps:")
print("1. Set environment variables in Render dashboard")
print("2. Deploy to Render using render.yaml")
print("3. Test API endpoints")
print("4. Update frontend with backend URL")
return 0
else:
print("⚠️ Some validation checks failed. Please fix issues before deployment.")
return 1
if __name__ == "__main__":
sys.exit(main())