forked from rahat15/AI-Interview-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_dev.py
More file actions
164 lines (138 loc) Β· 5.48 KB
/
start_dev.py
File metadata and controls
164 lines (138 loc) Β· 5.48 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
159
160
161
162
163
164
#!/usr/bin/env python3
"""
Development startup script for Interview Coach API.
This script helps you get started with the development environment.
"""
import os
import sys
import subprocess
import time
def run_command(command, description):
"""Run a command and handle errors"""
print(f"\nπ {description}...")
print(f"Running: {command}")
try:
result = subprocess.run(command, shell=True, check=True, capture_output=True, text=True)
print(f"β
{description} completed successfully")
if result.stdout:
print(result.stdout)
return True
except subprocess.CalledProcessError as e:
print(f"β {description} failed:")
print(f"Error code: {e.returncode}")
if e.stdout:
print(f"stdout: {e.stdout}")
if e.stderr:
print(f"stderr: {e.stderr}")
return False
def check_docker():
"""Check if Docker is running"""
print("π Checking Docker status...")
try:
result = subprocess.run("docker --version", shell=True, capture_output=True, text=True)
if result.returncode == 0:
print(f"β
Docker is available: {result.stdout.strip()}")
# Check if Docker daemon is running
result = subprocess.run("docker info", shell=True, capture_output=True, text=True)
if result.returncode == 0:
print("β
Docker daemon is running")
return True
else:
print("β Docker daemon is not running")
print("Please start Docker Desktop or the Docker service")
return False
else:
print("β Docker is not available")
return False
except Exception as e:
print(f"β Error checking Docker: {e}")
return False
def check_environment():
"""Check environment setup"""
print("\nπ Checking environment setup...")
# Check if .env file exists
if not os.path.exists(".env"):
if os.path.exists("env.example"):
print("β οΈ .env file not found, but env.example exists")
print("Please copy env.example to .env and configure your environment variables")
return False
else:
print("β Neither .env nor env.example found")
return False
print("β
.env file found")
# Check required environment variables
required_vars = ["SECRET_KEY", "DATABASE_URL", "REDIS_URL"]
missing_vars = []
for var in required_vars:
if not os.getenv(var):
missing_vars.append(var)
if missing_vars:
print(f"β Missing environment variables: {', '.join(missing_vars)}")
print("Please check your .env file")
return False
print("β
Required environment variables are set")
return True
def main():
"""Main startup function"""
print("π Interview Coach API - Development Startup")
print("=" * 50)
# Check Docker
if not check_docker():
print("\nβ Docker is required but not available.")
print("Please install Docker Desktop or Docker Engine and try again.")
return 1
# Check environment
if not check_environment():
print("\nβ Environment is not properly configured.")
print("Please fix the issues above and try again.")
return 1
print("\nβ
Environment is ready!")
# Ask user what they want to do
print("\nWhat would you like to do?")
print("1. Start the full development stack (recommended)")
print("2. Start only the database and Redis")
print("3. Run tests")
print("4. Exit")
while True:
choice = input("\nEnter your choice (1-4): ").strip()
if choice == "1":
print("\nπ Starting full development stack...")
if run_command("make dev-setup", "Starting development environment"):
print("\nπ Development environment is ready!")
print("\nServices available at:")
print("- API: http://localhost:8080")
print("- API Docs: http://localhost:8080/docs")
print("- Health Check: http://localhost:8080/healthz")
print("- Database: localhost:5432")
print("- Redis: localhost:6379")
print("\nTo stop the environment, run: make down")
print("To view logs, run: make logs")
else:
print("\nβ Failed to start development environment")
return 1
break
elif choice == "2":
print("\nπ Starting database and Redis only...")
if run_command("make up", "Starting database and Redis"):
print("\nβ
Database and Redis are running")
print("To start the API, run: make up")
else:
print("\nβ Failed to start database and Redis")
return 1
break
elif choice == "3":
print("\nπ§ͺ Running tests...")
if run_command("make test", "Running tests"):
print("\nβ
Tests completed")
else:
print("\nβ Tests failed")
return 1
break
elif choice == "4":
print("\nπ Goodbye!")
return 0
else:
print("β Invalid choice. Please enter 1, 2, 3, or 4.")
return 0
if __name__ == "__main__":
sys.exit(main())