-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeploy_mvp.py
More file actions
209 lines (175 loc) · 6.8 KB
/
Copy pathdeploy_mvp.py
File metadata and controls
209 lines (175 loc) · 6.8 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/usr/bin/env python
"""
CryptoWildfire MVP Deployment Script
This script validates core functionality and deploys the application.
"""
import os
import sys
import json
import logging
import datetime
import subprocess
from pathlib import Path
# Configure logging
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
logger = logging.getLogger("mvp_deployment")
# Define project paths
PROJECT_ROOT = Path(__file__).parent
API_DIR = PROJECT_ROOT / "src" / "api"
FRONTEND_DIR = PROJECT_ROOT / "frontend"
CONFIG_FILE = PROJECT_ROOT / "src" / "config.py"
def print_banner(text):
"""Print a formatted banner"""
width = 80
padding = (width - len(text) - 4) // 2
stars = "*" * width
print("\n" + stars)
print(f"{'*' * padding} {text} {'*' * padding}")
print(stars + "\n")
def run_validation():
"""Run the core functionality validation script"""
print_banner("VALIDATING CORE FUNCTIONALITY")
try:
# Run validation script
result = subprocess.run(
["python", "validate_core_functionality.py"],
cwd=PROJECT_ROOT,
capture_output=True,
text=True,
check=True
)
# Extract success rate from output
output = result.stdout
print(output)
if "Failed: 0" in output:
logger.info("Validation passed with 100% success rate")
return True, output
elif "Passed:" in output:
# Extract pass percentage
lines = output.split("\n")
for line in lines:
if "Passed:" in line and "%" in line:
rate = line.split("(")[1].split("%")[0]
pass_rate = float(rate)
if pass_rate >= 80:
logger.info(f"Validation passed with {pass_rate}% success rate - sufficient for MVP")
return True, output
else:
logger.error(f"Validation failed with only {pass_rate}% success rate")
return False, output
logger.error("Validation failed: Could not determine success rate")
return False, output
except subprocess.CalledProcessError as e:
logger.error(f"Validation script failed: {e}")
print(e.stdout)
print(e.stderr)
return False, e.stdout + "\n" + e.stderr
def create_deployment_record(validation_result, validation_output):
"""Create a deployment record with validation results"""
print_banner("CREATING DEPLOYMENT RECORD")
timestamp = datetime.datetime.now().isoformat()
record = {
"version": "0.5.0", # MVP version
"timestamp": timestamp,
"deployment_id": f"mvp-{timestamp}",
"validation": {
"success": validation_result,
"summary": validation_output.split("TEST SUMMARY")[1].split("RECOMMENDATIONS")[0].strip()
if "TEST SUMMARY" in validation_output else "Validation output not parseable"
},
"features": {
"correlation_analysis": True,
"technical_indicators": True,
"quantile_predictions": True,
"dynamic_stop_loss": True,
"trailing_stops": False,
"position_sizing": False,
"sentiment_analysis": False
},
"environment": os.environ.get("CRYPTOWILDFIRE_ENV", "development")
}
# Save deployment record
deploy_dir = PROJECT_ROOT / "deployments"
deploy_dir.mkdir(exist_ok=True)
record_file = deploy_dir / f"mvp_deployment_{timestamp.replace(':', '-')}.json"
with open(record_file, "w") as f:
json.dump(record, f, indent=2)
logger.info(f"Deployment record created: {record_file}")
return record
def deploy_api():
"""Deploy the API component"""
print_banner("DEPLOYING API")
try:
# Check if the service is already running
check_result = subprocess.run(
["ps", "-ef"],
capture_output=True,
text=True
)
if "uvicorn src.api.main:app" in check_result.stdout:
logger.warning("API already running - restart required")
# In production, you'd want to restart the service here
# For development: start the API
logger.info("Starting API service...")
subprocess.Popen(
["uvicorn", "src.api.main:app", "--reload", "--host", "0.0.0.0", "--port", "8000"],
cwd=PROJECT_ROOT
)
logger.info("API service started on http://localhost:8000")
return True
except Exception as e:
logger.error(f"API deployment failed: {e}")
return False
def deploy_frontend():
"""Deploy the frontend component"""
print_banner("DEPLOYING FRONTEND")
try:
# Build frontend in production mode
logger.info("Building frontend...")
subprocess.run(
["npm", "run", "build"],
cwd=FRONTEND_DIR,
check=True
)
# Start frontend server (development only, in production use nginx/etc)
logger.info("Starting frontend service...")
subprocess.Popen(
["npm", "run", "preview", "--", "--port", "3000"],
cwd=FRONTEND_DIR
)
logger.info("Frontend service started on http://localhost:3000")
return True
except Exception as e:
logger.error(f"Frontend deployment failed: {e}")
return False
def main():
"""Main deployment function"""
print_banner("CRYPTOWILDFIRE MVP DEPLOYMENT")
logger.info("Starting MVP deployment process")
# Run validation
validation_result, validation_output = run_validation()
if not validation_result:
logger.error("Deployment aborted: Validation failed")
proceed = input("Validation failed. Do you want to proceed anyway? (y/N): ")
if proceed.lower() != 'y':
sys.exit(1)
# Create deployment record
deploy_record = create_deployment_record(validation_result, validation_output)
# Deploy components
api_result = deploy_api()
frontend_result = deploy_frontend()
# Final status
print_banner("DEPLOYMENT COMPLETE")
print(f"API: {'✅ Success' if api_result else '❌ Failed'}")
print(f"Frontend: {'✅ Success' if frontend_result else '❌ Failed'}")
print(f"\nCryptoWildfire MVP v{deploy_record['version']} deployed at {deploy_record['timestamp']}")
print(f"Access the application at http://localhost:3000")
print("\nActive Features:")
for feature, enabled in deploy_record['features'].items():
status = "✅ Enabled" if enabled else "⏳ Coming Soon"
print(f"- {feature.replace('_', ' ').title()}: {status}")
if __name__ == "__main__":
main()