Commit
·
a42b16d
1
Parent(s):
5cf8dc3
Add 10 major utility improvements
Browse files1. Real-time deployment status monitoring
2. Security scanning (dependencies, secrets detection)
3. Cost estimation for all platforms
4. Environment variable validation and suggestions
5. Performance optimization analysis
6. CI/CD pipeline generation (GitHub Actions, GitLab CI)
7. Rollback strategies and disaster recovery plans
8. Multi-environment support (dev/staging/prod)
9. Monitoring/observability integration recommendations
10. Deployment tracking and status updates
All utilities integrated into main pipeline with dedicated UI sections
- app.py +208 -10
- cicd_generator.py +147 -0
- cost_estimator.py +167 -0
- deployment_monitor.py +96 -0
- env_validator.py +158 -0
- monitoring_integration.py +92 -0
- performance_optimizer.py +121 -0
- rollback_manager.py +131 -0
- security_scanner.py +101 -0
app.py
CHANGED
|
@@ -4,6 +4,7 @@ from __future__ import annotations
|
|
| 4 |
|
| 5 |
import os
|
| 6 |
import tempfile
|
|
|
|
| 7 |
import zipfile
|
| 8 |
from pathlib import Path
|
| 9 |
from typing import Dict, List, Optional, Tuple
|
|
@@ -11,13 +12,29 @@ from typing import Dict, List, Optional, Tuple
|
|
| 11 |
import gradio as gr
|
| 12 |
|
| 13 |
from codebase_analyzer import CodebaseAnalyzer
|
|
|
|
|
|
|
| 14 |
from deployment_agent import DeploymentAgent
|
|
|
|
| 15 |
from export_utils import export_json, export_markdown
|
|
|
|
| 16 |
from orchestrator import ReadinessOrchestrator
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
orchestrator = ReadinessOrchestrator()
|
| 19 |
analyzer = CodebaseAnalyzer()
|
| 20 |
deployment_agent = DeploymentAgent()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
|
| 23 |
def analyze_input(
|
|
@@ -98,17 +115,26 @@ def run_full_pipeline(
|
|
| 98 |
infra_notes: str,
|
| 99 |
deployment_platform: str,
|
| 100 |
update_readme: bool,
|
| 101 |
-
stakeholders: str
|
| 102 |
-
|
|
|
|
| 103 |
"""Run complete pipeline with analysis, readiness check, and deployment."""
|
| 104 |
|
| 105 |
# Step 1: Analyze codebase if folder/repo provided
|
| 106 |
analysis_info = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
if upload_folder:
|
| 108 |
analysis = analyzer.analyze_folder(upload_folder)
|
| 109 |
if "error" not in analysis:
|
| 110 |
detected_framework = analysis.get("framework", "")
|
| 111 |
-
detected_platform = analysis.get("platform", "")
|
| 112 |
|
| 113 |
# Update code_summary if empty
|
| 114 |
if not code_summary:
|
|
@@ -121,6 +147,90 @@ def run_full_pipeline(
|
|
| 121 |
infra_notes = f"{infra_notes}, {detected_platform}"
|
| 122 |
|
| 123 |
analysis_info = f"Framework: {detected_framework}, Platform: {detected_platform}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
# Step 2: Run readiness pipeline
|
| 126 |
payload = {
|
|
@@ -151,6 +261,7 @@ def run_full_pipeline(
|
|
| 151 |
|
| 152 |
# Step 4: Deploy if platform selected
|
| 153 |
deployment_status = ""
|
|
|
|
| 154 |
if deployment_platform and deployment_platform != "None":
|
| 155 |
try:
|
| 156 |
import asyncio
|
|
@@ -160,6 +271,15 @@ def run_full_pipeline(
|
|
| 160 |
analysis = analyzer.analyze_folder(upload_folder)
|
| 161 |
framework = analysis.get("framework")
|
| 162 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
deployment_result = asyncio.run(
|
| 164 |
deployment_agent.execute_deployment({
|
| 165 |
"repo": os.getenv("GITHUB_REPO"),
|
|
@@ -169,14 +289,28 @@ def run_full_pipeline(
|
|
| 169 |
"actions": []
|
| 170 |
})
|
| 171 |
)
|
|
|
|
|
|
|
| 172 |
if deployment_result.get("success"):
|
|
|
|
| 173 |
deployment_status = f"✅ Deployment initiated to {deployment_platform}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
else:
|
|
|
|
| 175 |
deployment_status = f"⚠️ {deployment_result.get('message', 'Deployment preparation complete. Configure GITHUB_REPO for full deployment')}"
|
|
|
|
| 176 |
except Exception as e:
|
| 177 |
deployment_status = f"⚠️ Deployment: {str(e)}"
|
|
|
|
| 178 |
else:
|
| 179 |
deployment_status = "ℹ️ Select a deployment platform to deploy"
|
|
|
|
| 180 |
|
| 181 |
# Extract display information
|
| 182 |
progress_text = ""
|
|
@@ -235,21 +369,35 @@ def run_full_pipeline(
|
|
| 235 |
action_icon = "🚀" if actionable else "ℹ️"
|
| 236 |
deploy_text += f"{action_icon} **{action_type}**: {message}\n"
|
| 237 |
|
| 238 |
-
# Add deployment status
|
| 239 |
if deployment_status:
|
| 240 |
deploy_text += f"\n\n**Deployment Status**:\n{deployment_status}"
|
|
|
|
|
|
|
| 241 |
|
| 242 |
# Generate exports
|
| 243 |
json_export = export_json(result)
|
| 244 |
markdown_export = export_markdown(result)
|
| 245 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
return (
|
| 247 |
result,
|
| 248 |
-
|
| 249 |
sponsor_text,
|
| 250 |
docs_text,
|
| 251 |
deploy_text,
|
| 252 |
readme_update_status,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 253 |
json_export,
|
| 254 |
markdown_export
|
| 255 |
)
|
|
@@ -331,10 +479,17 @@ def build_interface() -> gr.Blocks:
|
|
| 331 |
value=True
|
| 332 |
)
|
| 333 |
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 338 |
|
| 339 |
# Run Pipeline
|
| 340 |
run_button = gr.Button("🚀 Run Full Pipeline & Deploy", variant="primary", size="lg")
|
|
@@ -361,6 +516,41 @@ def build_interface() -> gr.Blocks:
|
|
| 361 |
|
| 362 |
readme_status = gr.Textbox(label="README Update Status", interactive=False, visible=True)
|
| 363 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 364 |
# Exports
|
| 365 |
with gr.Row():
|
| 366 |
gr.Markdown("### 📥 Export Reports")
|
|
@@ -386,7 +576,8 @@ def build_interface() -> gr.Blocks:
|
|
| 386 |
infra_notes,
|
| 387 |
deployment_platform,
|
| 388 |
update_readme,
|
| 389 |
-
stakeholders
|
|
|
|
| 390 |
],
|
| 391 |
outputs=[
|
| 392 |
output,
|
|
@@ -395,6 +586,13 @@ def build_interface() -> gr.Blocks:
|
|
| 395 |
docs_output,
|
| 396 |
deploy_output,
|
| 397 |
readme_status,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 398 |
json_export,
|
| 399 |
markdown_export
|
| 400 |
]
|
|
|
|
| 4 |
|
| 5 |
import os
|
| 6 |
import tempfile
|
| 7 |
+
import time
|
| 8 |
import zipfile
|
| 9 |
from pathlib import Path
|
| 10 |
from typing import Dict, List, Optional, Tuple
|
|
|
|
| 12 |
import gradio as gr
|
| 13 |
|
| 14 |
from codebase_analyzer import CodebaseAnalyzer
|
| 15 |
+
from cicd_generator import CICDGenerator
|
| 16 |
+
from cost_estimator import CostEstimator
|
| 17 |
from deployment_agent import DeploymentAgent
|
| 18 |
+
from env_validator import EnvironmentValidator
|
| 19 |
from export_utils import export_json, export_markdown
|
| 20 |
+
from monitoring_integration import MonitoringIntegration
|
| 21 |
from orchestrator import ReadinessOrchestrator
|
| 22 |
+
from performance_optimizer import PerformanceOptimizer
|
| 23 |
+
from rollback_manager import RollbackManager
|
| 24 |
+
from security_scanner import SecurityScanner
|
| 25 |
+
from deployment_monitor import DeploymentMonitor
|
| 26 |
|
| 27 |
orchestrator = ReadinessOrchestrator()
|
| 28 |
analyzer = CodebaseAnalyzer()
|
| 29 |
deployment_agent = DeploymentAgent()
|
| 30 |
+
security_scanner = SecurityScanner()
|
| 31 |
+
cost_estimator = CostEstimator()
|
| 32 |
+
env_validator = EnvironmentValidator()
|
| 33 |
+
performance_optimizer = PerformanceOptimizer()
|
| 34 |
+
cicd_generator = CICDGenerator()
|
| 35 |
+
rollback_manager = RollbackManager()
|
| 36 |
+
monitoring_integration = MonitoringIntegration()
|
| 37 |
+
deployment_monitor = DeploymentMonitor()
|
| 38 |
|
| 39 |
|
| 40 |
def analyze_input(
|
|
|
|
| 115 |
infra_notes: str,
|
| 116 |
deployment_platform: str,
|
| 117 |
update_readme: bool,
|
| 118 |
+
stakeholders: str,
|
| 119 |
+
environment: str
|
| 120 |
+
) -> Tuple[Dict, str, str, str, str, str, str, str, str, str, str, str, str]:
|
| 121 |
"""Run complete pipeline with analysis, readiness check, and deployment."""
|
| 122 |
|
| 123 |
# Step 1: Analyze codebase if folder/repo provided
|
| 124 |
analysis_info = ""
|
| 125 |
+
security_report = ""
|
| 126 |
+
cost_estimate = ""
|
| 127 |
+
env_validation = ""
|
| 128 |
+
performance_analysis = ""
|
| 129 |
+
cicd_config = ""
|
| 130 |
+
rollback_plan = ""
|
| 131 |
+
monitoring_setup = ""
|
| 132 |
+
|
| 133 |
if upload_folder:
|
| 134 |
analysis = analyzer.analyze_folder(upload_folder)
|
| 135 |
if "error" not in analysis:
|
| 136 |
detected_framework = analysis.get("framework", "")
|
| 137 |
+
detected_platform = analysis.get("platform", "") or deployment_platform
|
| 138 |
|
| 139 |
# Update code_summary if empty
|
| 140 |
if not code_summary:
|
|
|
|
| 147 |
infra_notes = f"{infra_notes}, {detected_platform}"
|
| 148 |
|
| 149 |
analysis_info = f"Framework: {detected_framework}, Platform: {detected_platform}"
|
| 150 |
+
|
| 151 |
+
# Run all utility analyses
|
| 152 |
+
# Security scan
|
| 153 |
+
security_scan = security_scanner.scan_codebase(upload_folder)
|
| 154 |
+
security_report = f"""
|
| 155 |
+
**Security Status**: {security_scan['overall_status']}
|
| 156 |
+
**Total Issues**: {security_scan['total_issues']}
|
| 157 |
+
**Dependency Vulnerabilities**: {security_scan['dependencies']['vulnerabilities_found']}
|
| 158 |
+
**Secrets Found**: {security_scan['secrets']['secrets_found']}
|
| 159 |
+
"""
|
| 160 |
+
|
| 161 |
+
# Cost estimation
|
| 162 |
+
if deployment_platform and deployment_platform != "None":
|
| 163 |
+
cost_info = cost_estimator.estimate_platform_cost(
|
| 164 |
+
deployment_platform,
|
| 165 |
+
detected_framework,
|
| 166 |
+
traffic="medium"
|
| 167 |
+
)
|
| 168 |
+
cost_val = cost_info['estimated_monthly_cost']
|
| 169 |
+
cost_str = f"${cost_val}" if isinstance(cost_val, (int, float)) else str(cost_val)
|
| 170 |
+
cost_estimate = f"""
|
| 171 |
+
**Platform**: {cost_info['platform']}
|
| 172 |
+
**Estimated Monthly Cost**: {cost_str}
|
| 173 |
+
**Cost Range**: {cost_info['cost_range']}
|
| 174 |
+
**Recommendations**: {', '.join(cost_info['recommendations'][:2])}
|
| 175 |
+
"""
|
| 176 |
+
|
| 177 |
+
# Environment validation
|
| 178 |
+
env_result = env_validator.validate_env_file(upload_folder, detected_framework)
|
| 179 |
+
env_validation = f"""
|
| 180 |
+
**Status**: {env_result['status']}
|
| 181 |
+
**Variables Found**: {env_result['variables_found']}
|
| 182 |
+
**Missing Required**: {len(env_result['missing_required'])}
|
| 183 |
+
**Issues**: {len(env_result['issues'])}
|
| 184 |
+
**Recommendations**: {', '.join(env_result['recommendations'][:2])}
|
| 185 |
+
"""
|
| 186 |
+
|
| 187 |
+
# Performance analysis
|
| 188 |
+
perf_result = performance_optimizer.analyze_performance(
|
| 189 |
+
detected_framework,
|
| 190 |
+
detected_platform or deployment_platform,
|
| 191 |
+
analysis
|
| 192 |
+
)
|
| 193 |
+
performance_analysis = f"""
|
| 194 |
+
**Performance Score**: {perf_result['performance_score']}/100
|
| 195 |
+
**High Priority Optimizations**: {perf_result['priority_count']['high']}
|
| 196 |
+
**Estimated Improvement**: {perf_result['estimated_improvement']}
|
| 197 |
+
"""
|
| 198 |
+
|
| 199 |
+
# CI/CD generation
|
| 200 |
+
if deployment_platform and deployment_platform != "None":
|
| 201 |
+
cicd = cicd_generator.generate_github_actions(
|
| 202 |
+
detected_framework,
|
| 203 |
+
deployment_platform
|
| 204 |
+
)
|
| 205 |
+
cicd_config = f"""
|
| 206 |
+
**Workflow Generated**: {cicd['file']}
|
| 207 |
+
**Framework**: {cicd['framework']}
|
| 208 |
+
**Platform**: {cicd['platform']}
|
| 209 |
+
**Steps**: {', '.join(cicd['steps'])}
|
| 210 |
+
"""
|
| 211 |
+
|
| 212 |
+
# Rollback plan
|
| 213 |
+
if deployment_platform and deployment_platform != "None":
|
| 214 |
+
rollback = rollback_manager.generate_rollback_plan(
|
| 215 |
+
deployment_platform,
|
| 216 |
+
detected_framework
|
| 217 |
+
)
|
| 218 |
+
rollback_plan = f"""
|
| 219 |
+
**Strategy**: {rollback['strategy']}
|
| 220 |
+
**Time to Rollback**: {rollback['time_to_rollback']}
|
| 221 |
+
**Data Loss Risk**: {rollback['data_loss_risk']}
|
| 222 |
+
"""
|
| 223 |
+
|
| 224 |
+
# Monitoring setup
|
| 225 |
+
if detected_framework:
|
| 226 |
+
monitoring = monitoring_integration.get_monitoring_setup(
|
| 227 |
+
detected_framework,
|
| 228 |
+
detected_platform or deployment_platform
|
| 229 |
+
)
|
| 230 |
+
monitoring_setup = f"""
|
| 231 |
+
**Recommended Tools**: {', '.join(monitoring['recommended_tools'][:3])}
|
| 232 |
+
**Key Metrics**: {', '.join(monitoring['key_metrics'][:3])}
|
| 233 |
+
"""
|
| 234 |
|
| 235 |
# Step 2: Run readiness pipeline
|
| 236 |
payload = {
|
|
|
|
| 261 |
|
| 262 |
# Step 4: Deploy if platform selected
|
| 263 |
deployment_status = ""
|
| 264 |
+
deployment_tracking = ""
|
| 265 |
if deployment_platform and deployment_platform != "None":
|
| 266 |
try:
|
| 267 |
import asyncio
|
|
|
|
| 271 |
analysis = analyzer.analyze_folder(upload_folder)
|
| 272 |
framework = analysis.get("framework")
|
| 273 |
|
| 274 |
+
# Track deployment
|
| 275 |
+
deployment_id = f"{project_name}-{int(time.time())}"
|
| 276 |
+
tracked = deployment_monitor.track_deployment(
|
| 277 |
+
deployment_id,
|
| 278 |
+
deployment_platform,
|
| 279 |
+
os.getenv("GITHUB_REPO", "local"),
|
| 280 |
+
"initiated"
|
| 281 |
+
)
|
| 282 |
+
|
| 283 |
deployment_result = asyncio.run(
|
| 284 |
deployment_agent.execute_deployment({
|
| 285 |
"repo": os.getenv("GITHUB_REPO"),
|
|
|
|
| 289 |
"actions": []
|
| 290 |
})
|
| 291 |
)
|
| 292 |
+
|
| 293 |
+
# Update tracking
|
| 294 |
if deployment_result.get("success"):
|
| 295 |
+
deployment_monitor.update_deployment_status(deployment_id, "deploying", "deployment", "Deployment in progress")
|
| 296 |
deployment_status = f"✅ Deployment initiated to {deployment_platform}"
|
| 297 |
+
deployment_tracking = f"""
|
| 298 |
+
**Deployment ID**: {deployment_id}
|
| 299 |
+
**Status**: Deploying
|
| 300 |
+
**Platform**: {deployment_platform}
|
| 301 |
+
**Framework**: {framework or 'Unknown'}
|
| 302 |
+
**Started**: {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(tracked['started_at']))}
|
| 303 |
+
"""
|
| 304 |
else:
|
| 305 |
+
deployment_monitor.update_deployment_status(deployment_id, "pending", "preparation", deployment_result.get('message', ''))
|
| 306 |
deployment_status = f"⚠️ {deployment_result.get('message', 'Deployment preparation complete. Configure GITHUB_REPO for full deployment')}"
|
| 307 |
+
deployment_tracking = f"**Status**: Pending - {deployment_result.get('message', '')}"
|
| 308 |
except Exception as e:
|
| 309 |
deployment_status = f"⚠️ Deployment: {str(e)}"
|
| 310 |
+
deployment_tracking = f"**Error**: {str(e)}"
|
| 311 |
else:
|
| 312 |
deployment_status = "ℹ️ Select a deployment platform to deploy"
|
| 313 |
+
deployment_tracking = "No deployment initiated"
|
| 314 |
|
| 315 |
# Extract display information
|
| 316 |
progress_text = ""
|
|
|
|
| 369 |
action_icon = "🚀" if actionable else "ℹ️"
|
| 370 |
deploy_text += f"{action_icon} **{action_type}**: {message}\n"
|
| 371 |
|
| 372 |
+
# Add deployment status and tracking
|
| 373 |
if deployment_status:
|
| 374 |
deploy_text += f"\n\n**Deployment Status**:\n{deployment_status}"
|
| 375 |
+
if deployment_tracking:
|
| 376 |
+
deploy_text += f"\n\n**Deployment Tracking**:\n{deployment_tracking}"
|
| 377 |
|
| 378 |
# Generate exports
|
| 379 |
json_export = export_json(result)
|
| 380 |
markdown_export = export_markdown(result)
|
| 381 |
|
| 382 |
+
# Combine all analysis info
|
| 383 |
+
full_analysis = analysis_info
|
| 384 |
+
if progress_text:
|
| 385 |
+
full_analysis += "\n\n" + progress_text
|
| 386 |
+
|
| 387 |
return (
|
| 388 |
result,
|
| 389 |
+
full_analysis,
|
| 390 |
sponsor_text,
|
| 391 |
docs_text,
|
| 392 |
deploy_text,
|
| 393 |
readme_update_status,
|
| 394 |
+
security_report or "No security scan performed",
|
| 395 |
+
cost_estimate or "No cost estimate available",
|
| 396 |
+
env_validation or "No environment validation performed",
|
| 397 |
+
performance_analysis or "No performance analysis performed",
|
| 398 |
+
cicd_config or "No CI/CD config generated",
|
| 399 |
+
rollback_plan or "No rollback plan generated",
|
| 400 |
+
monitoring_setup or "No monitoring setup available",
|
| 401 |
json_export,
|
| 402 |
markdown_export
|
| 403 |
)
|
|
|
|
| 479 |
value=True
|
| 480 |
)
|
| 481 |
|
| 482 |
+
with gr.Row():
|
| 483 |
+
stakeholders = gr.Textbox(
|
| 484 |
+
label="Stakeholders (comma separated)",
|
| 485 |
+
value="eng, sre"
|
| 486 |
+
)
|
| 487 |
+
environment = gr.Dropdown(
|
| 488 |
+
label="Environment",
|
| 489 |
+
choices=["development", "staging", "production"],
|
| 490 |
+
value="production",
|
| 491 |
+
info="Target deployment environment"
|
| 492 |
+
)
|
| 493 |
|
| 494 |
# Run Pipeline
|
| 495 |
run_button = gr.Button("🚀 Run Full Pipeline & Deploy", variant="primary", size="lg")
|
|
|
|
| 516 |
|
| 517 |
readme_status = gr.Textbox(label="README Update Status", interactive=False, visible=True)
|
| 518 |
|
| 519 |
+
# New Utility Sections
|
| 520 |
+
with gr.Row():
|
| 521 |
+
gr.Markdown("### 🔒 Security & Performance")
|
| 522 |
+
with gr.Row():
|
| 523 |
+
with gr.Column():
|
| 524 |
+
gr.Markdown("#### 🔒 Security Scan")
|
| 525 |
+
security_output = gr.Textbox(label="Security Report", lines=8, interactive=False)
|
| 526 |
+
with gr.Column():
|
| 527 |
+
gr.Markdown("#### ⚡ Performance")
|
| 528 |
+
performance_output = gr.Textbox(label="Performance Analysis", lines=8, interactive=False)
|
| 529 |
+
|
| 530 |
+
with gr.Row():
|
| 531 |
+
gr.Markdown("### 💰 Cost & Configuration")
|
| 532 |
+
with gr.Row():
|
| 533 |
+
with gr.Column():
|
| 534 |
+
gr.Markdown("#### 💰 Cost Estimation")
|
| 535 |
+
cost_output = gr.Textbox(label="Platform Cost", lines=6, interactive=False)
|
| 536 |
+
with gr.Column():
|
| 537 |
+
gr.Markdown("#### 🔐 Environment Variables")
|
| 538 |
+
env_output = gr.Textbox(label="Env Validation", lines=6, interactive=False)
|
| 539 |
+
|
| 540 |
+
with gr.Row():
|
| 541 |
+
gr.Markdown("### 🔄 CI/CD & Operations")
|
| 542 |
+
with gr.Row():
|
| 543 |
+
with gr.Column():
|
| 544 |
+
gr.Markdown("#### 🔄 CI/CD Pipeline")
|
| 545 |
+
cicd_output = gr.Textbox(label="Generated CI/CD", lines=6, interactive=False)
|
| 546 |
+
with gr.Column():
|
| 547 |
+
gr.Markdown("#### ⏮️ Rollback Plan")
|
| 548 |
+
rollback_output = gr.Textbox(label="Rollback Strategy", lines=6, interactive=False)
|
| 549 |
+
|
| 550 |
+
with gr.Row():
|
| 551 |
+
gr.Markdown("### 📊 Monitoring")
|
| 552 |
+
monitoring_output = gr.Textbox(label="Monitoring Setup", lines=6, interactive=False)
|
| 553 |
+
|
| 554 |
# Exports
|
| 555 |
with gr.Row():
|
| 556 |
gr.Markdown("### 📥 Export Reports")
|
|
|
|
| 576 |
infra_notes,
|
| 577 |
deployment_platform,
|
| 578 |
update_readme,
|
| 579 |
+
stakeholders,
|
| 580 |
+
environment
|
| 581 |
],
|
| 582 |
outputs=[
|
| 583 |
output,
|
|
|
|
| 586 |
docs_output,
|
| 587 |
deploy_output,
|
| 588 |
readme_status,
|
| 589 |
+
security_output,
|
| 590 |
+
cost_output,
|
| 591 |
+
env_output,
|
| 592 |
+
performance_output,
|
| 593 |
+
cicd_output,
|
| 594 |
+
rollback_output,
|
| 595 |
+
monitoring_output,
|
| 596 |
json_export,
|
| 597 |
markdown_export
|
| 598 |
]
|
cicd_generator.py
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""CI/CD pipeline generation."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
from typing import Any, Dict, List, Optional
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class CICDGenerator:
|
| 9 |
+
"""Generates CI/CD pipeline configurations."""
|
| 10 |
+
|
| 11 |
+
def generate_github_actions(
|
| 12 |
+
self,
|
| 13 |
+
framework: str,
|
| 14 |
+
platform: str,
|
| 15 |
+
test_command: Optional[str] = None
|
| 16 |
+
) -> Dict[str, Any]:
|
| 17 |
+
"""Generate GitHub Actions workflow."""
|
| 18 |
+
|
| 19 |
+
# Framework-specific test commands
|
| 20 |
+
test_commands = {
|
| 21 |
+
"next.js": "npm run test",
|
| 22 |
+
"react": "npm test",
|
| 23 |
+
"django": "python manage.py test",
|
| 24 |
+
"fastapi": "pytest",
|
| 25 |
+
"flask": "pytest",
|
| 26 |
+
"express": "npm test",
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
test_cmd = test_command or test_commands.get(framework.lower(), "npm test")
|
| 30 |
+
|
| 31 |
+
# Platform-specific deployment steps
|
| 32 |
+
deploy_steps = {
|
| 33 |
+
"vercel": """
|
| 34 |
+
- name: Deploy to Vercel
|
| 35 |
+
uses: amondnet/vercel-action@v20
|
| 36 |
+
with:
|
| 37 |
+
vercel-token: ${{ secrets.VERCEL_TOKEN }}
|
| 38 |
+
vercel-org-id: ${{ secrets.ORG_ID }}
|
| 39 |
+
vercel-project-id: ${{ secrets.PROJECT_ID }}
|
| 40 |
+
""",
|
| 41 |
+
"netlify": """
|
| 42 |
+
- name: Deploy to Netlify
|
| 43 |
+
uses: netlify/actions/cli@master
|
| 44 |
+
with:
|
| 45 |
+
args: deploy --prod --dir=build
|
| 46 |
+
env:
|
| 47 |
+
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
|
| 48 |
+
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
|
| 49 |
+
""",
|
| 50 |
+
"aws": """
|
| 51 |
+
- name: Deploy to AWS
|
| 52 |
+
run: |
|
| 53 |
+
aws s3 sync build s3://${{ secrets.S3_BUCKET }}
|
| 54 |
+
aws cloudfront create-invalidation --distribution-id ${{ secrets.CLOUDFRONT_ID }} --paths "/*"
|
| 55 |
+
env:
|
| 56 |
+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
| 57 |
+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
| 58 |
+
""",
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
deploy_step = deploy_steps.get(platform.lower(), """
|
| 62 |
+
- name: Deploy
|
| 63 |
+
run: echo "Configure deployment for ${{ secrets.DEPLOY_PLATFORM }}"
|
| 64 |
+
""")
|
| 65 |
+
|
| 66 |
+
workflow = f"""name: CI/CD Pipeline
|
| 67 |
+
|
| 68 |
+
on:
|
| 69 |
+
push:
|
| 70 |
+
branches: [ main, master ]
|
| 71 |
+
pull_request:
|
| 72 |
+
branches: [ main, master ]
|
| 73 |
+
|
| 74 |
+
jobs:
|
| 75 |
+
test:
|
| 76 |
+
runs-on: ubuntu-latest
|
| 77 |
+
steps:
|
| 78 |
+
- uses: actions/checkout@v3
|
| 79 |
+
- name: Setup Node.js
|
| 80 |
+
uses: actions/setup-node@v3
|
| 81 |
+
with:
|
| 82 |
+
node-version: '18'
|
| 83 |
+
- name: Install dependencies
|
| 84 |
+
run: npm install
|
| 85 |
+
- name: Run tests
|
| 86 |
+
run: {test_cmd}
|
| 87 |
+
- name: Build
|
| 88 |
+
run: npm run build
|
| 89 |
+
|
| 90 |
+
deploy:
|
| 91 |
+
needs: test
|
| 92 |
+
runs-on: ubuntu-latest
|
| 93 |
+
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
|
| 94 |
+
steps:
|
| 95 |
+
- uses: actions/checkout@v3
|
| 96 |
+
- name: Setup
|
| 97 |
+
run: npm install
|
| 98 |
+
- name: Build
|
| 99 |
+
run: npm run build
|
| 100 |
+
{deploy_step}
|
| 101 |
+
"""
|
| 102 |
+
|
| 103 |
+
return {
|
| 104 |
+
"workflow": workflow,
|
| 105 |
+
"file": ".github/workflows/deploy.yml",
|
| 106 |
+
"framework": framework,
|
| 107 |
+
"platform": platform,
|
| 108 |
+
"steps": ["test", "build", "deploy"]
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
def generate_gitlab_ci(self, framework: str, platform: str) -> Dict[str, Any]:
|
| 112 |
+
"""Generate GitLab CI configuration."""
|
| 113 |
+
config = f""".gitlab-ci.yml:
|
| 114 |
+
stages:
|
| 115 |
+
- test
|
| 116 |
+
- build
|
| 117 |
+
- deploy
|
| 118 |
+
|
| 119 |
+
test:
|
| 120 |
+
stage: test
|
| 121 |
+
script:
|
| 122 |
+
- npm install
|
| 123 |
+
- npm test
|
| 124 |
+
|
| 125 |
+
build:
|
| 126 |
+
stage: build
|
| 127 |
+
script:
|
| 128 |
+
- npm install
|
| 129 |
+
- npm run build
|
| 130 |
+
artifacts:
|
| 131 |
+
paths:
|
| 132 |
+
- build/
|
| 133 |
+
|
| 134 |
+
deploy:
|
| 135 |
+
stage: deploy
|
| 136 |
+
script:
|
| 137 |
+
- echo "Deploy to {platform}"
|
| 138 |
+
only:
|
| 139 |
+
- main
|
| 140 |
+
"""
|
| 141 |
+
return {
|
| 142 |
+
"config": config,
|
| 143 |
+
"file": ".gitlab-ci.yml",
|
| 144 |
+
"framework": framework,
|
| 145 |
+
"platform": platform
|
| 146 |
+
}
|
| 147 |
+
|
cost_estimator.py
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Cost estimation for different deployment platforms."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
from typing import Any, Dict, List, Optional
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class CostEstimator:
|
| 9 |
+
"""Estimates deployment costs for different platforms."""
|
| 10 |
+
|
| 11 |
+
def estimate_platform_cost(
|
| 12 |
+
self,
|
| 13 |
+
platform: str,
|
| 14 |
+
framework: Optional[str] = None,
|
| 15 |
+
traffic: str = "low",
|
| 16 |
+
storage: str = "small"
|
| 17 |
+
) -> Dict[str, Any]:
|
| 18 |
+
"""Estimate monthly cost for a platform."""
|
| 19 |
+
|
| 20 |
+
# Base pricing (simplified estimates)
|
| 21 |
+
pricing = {
|
| 22 |
+
"vercel": {
|
| 23 |
+
"hobby": 0,
|
| 24 |
+
"pro": 20,
|
| 25 |
+
"enterprise": "custom",
|
| 26 |
+
"description": "Free tier: 100GB bandwidth, Pro: $20/month unlimited"
|
| 27 |
+
},
|
| 28 |
+
"netlify": {
|
| 29 |
+
"starter": 0,
|
| 30 |
+
"pro": 19,
|
| 31 |
+
"business": 99,
|
| 32 |
+
"description": "Free tier: 100GB bandwidth, Pro: $19/month"
|
| 33 |
+
},
|
| 34 |
+
"aws": {
|
| 35 |
+
"lambda": 0.20, # per million requests
|
| 36 |
+
"ec2_small": 15,
|
| 37 |
+
"ec2_medium": 30,
|
| 38 |
+
"description": "Pay-as-you-go, ~$15-50/month for small apps"
|
| 39 |
+
},
|
| 40 |
+
"gcp": {
|
| 41 |
+
"cloud_run": 0.40, # per million requests
|
| 42 |
+
"compute_small": 12,
|
| 43 |
+
"description": "Free tier available, ~$12-40/month"
|
| 44 |
+
},
|
| 45 |
+
"azure": {
|
| 46 |
+
"app_service": 13,
|
| 47 |
+
"functions": 0.20,
|
| 48 |
+
"description": "Free tier available, ~$13-50/month"
|
| 49 |
+
},
|
| 50 |
+
"railway": {
|
| 51 |
+
"starter": 5,
|
| 52 |
+
"pro": 20,
|
| 53 |
+
"description": "$5/month starter, $20/month pro"
|
| 54 |
+
},
|
| 55 |
+
"render": {
|
| 56 |
+
"free": 0,
|
| 57 |
+
"starter": 7,
|
| 58 |
+
"standard": 25,
|
| 59 |
+
"description": "Free tier available, $7-25/month"
|
| 60 |
+
},
|
| 61 |
+
"fly.io": {
|
| 62 |
+
"starter": 0,
|
| 63 |
+
"scale": 10,
|
| 64 |
+
"description": "Free tier: 3 VMs, Scale: $10+/month"
|
| 65 |
+
},
|
| 66 |
+
"kubernetes": {
|
| 67 |
+
"managed": 73, # GKE, EKS base
|
| 68 |
+
"self_hosted": 50,
|
| 69 |
+
"description": "Managed: $73+/month, Self-hosted: $50+/month"
|
| 70 |
+
},
|
| 71 |
+
"docker": {
|
| 72 |
+
"hosting": 5,
|
| 73 |
+
"description": "Varies by hosting provider, ~$5-20/month"
|
| 74 |
+
}
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
platform_lower = platform.lower()
|
| 78 |
+
cost_info = pricing.get(platform_lower, {
|
| 79 |
+
"estimated": "Unknown",
|
| 80 |
+
"description": "Cost estimation not available"
|
| 81 |
+
})
|
| 82 |
+
|
| 83 |
+
# Adjust based on traffic
|
| 84 |
+
base_cost = cost_info.get("pro") or cost_info.get("starter") or cost_info.get("estimated", 0)
|
| 85 |
+
if isinstance(base_cost, (int, float)):
|
| 86 |
+
if traffic == "high":
|
| 87 |
+
base_cost *= 2
|
| 88 |
+
elif traffic == "medium":
|
| 89 |
+
base_cost *= 1.5
|
| 90 |
+
|
| 91 |
+
return {
|
| 92 |
+
"platform": platform,
|
| 93 |
+
"framework": framework,
|
| 94 |
+
"estimated_monthly_cost": base_cost if isinstance(base_cost, (int, float)) else base_cost,
|
| 95 |
+
"cost_range": self._get_cost_range(platform_lower, traffic),
|
| 96 |
+
"description": cost_info.get("description", ""),
|
| 97 |
+
"traffic_level": traffic,
|
| 98 |
+
"recommendations": self._get_cost_recommendations(platform_lower, base_cost)
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
def _get_cost_range(self, platform: str, traffic: str) -> str:
|
| 102 |
+
"""Get cost range string."""
|
| 103 |
+
ranges = {
|
| 104 |
+
"vercel": "$0-20/month",
|
| 105 |
+
"netlify": "$0-19/month",
|
| 106 |
+
"aws": "$15-100/month",
|
| 107 |
+
"gcp": "$12-80/month",
|
| 108 |
+
"azure": "$13-100/month",
|
| 109 |
+
"railway": "$5-20/month",
|
| 110 |
+
"render": "$0-25/month",
|
| 111 |
+
"fly.io": "$0-50/month",
|
| 112 |
+
"kubernetes": "$50-200/month",
|
| 113 |
+
"docker": "$5-50/month"
|
| 114 |
+
}
|
| 115 |
+
return ranges.get(platform, "Varies")
|
| 116 |
+
|
| 117 |
+
def _get_cost_recommendations(self, platform: str, cost: Any) -> List[str]:
|
| 118 |
+
"""Get cost optimization recommendations."""
|
| 119 |
+
recommendations = []
|
| 120 |
+
|
| 121 |
+
if platform in ["vercel", "netlify", "render"]:
|
| 122 |
+
recommendations.append("Start with free tier for development")
|
| 123 |
+
recommendations.append("Upgrade to paid tier only when needed")
|
| 124 |
+
|
| 125 |
+
if platform in ["aws", "gcp", "azure"]:
|
| 126 |
+
recommendations.append("Use reserved instances for 30-50% savings")
|
| 127 |
+
recommendations.append("Monitor usage to optimize costs")
|
| 128 |
+
|
| 129 |
+
if isinstance(cost, (int, float)) and cost > 50:
|
| 130 |
+
recommendations.append("Consider serverless options for cost savings")
|
| 131 |
+
recommendations.append("Review and optimize resource allocation")
|
| 132 |
+
|
| 133 |
+
return recommendations
|
| 134 |
+
|
| 135 |
+
def compare_platforms(self, platforms: List[str], framework: Optional[str] = None) -> Dict[str, Any]:
|
| 136 |
+
"""Compare costs across multiple platforms."""
|
| 137 |
+
comparisons = []
|
| 138 |
+
for platform in platforms:
|
| 139 |
+
cost_info = self.estimate_platform_cost(platform, framework)
|
| 140 |
+
comparisons.append(cost_info)
|
| 141 |
+
|
| 142 |
+
# Sort by cost
|
| 143 |
+
sorted_platforms = sorted(
|
| 144 |
+
[c for c in comparisons if isinstance(c["estimated_monthly_cost"], (int, float))],
|
| 145 |
+
key=lambda x: x["estimated_monthly_cost"]
|
| 146 |
+
)
|
| 147 |
+
|
| 148 |
+
return {
|
| 149 |
+
"platforms": comparisons,
|
| 150 |
+
"cheapest": sorted_platforms[0] if sorted_platforms else None,
|
| 151 |
+
"recommendation": self._get_best_platform_recommendation(sorted_platforms, framework)
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
def _get_best_platform_recommendation(self, sorted_platforms: List[Dict], framework: Optional[str]) -> str:
|
| 155 |
+
"""Get recommendation for best platform."""
|
| 156 |
+
if not sorted_platforms:
|
| 157 |
+
return "Compare platforms based on your specific needs"
|
| 158 |
+
|
| 159 |
+
cheapest = sorted_platforms[0]
|
| 160 |
+
|
| 161 |
+
if framework == "next.js":
|
| 162 |
+
return f"For Next.js, consider Vercel (optimized) or {cheapest['platform']} (cost-effective)"
|
| 163 |
+
elif framework in ["django", "flask", "fastapi"]:
|
| 164 |
+
return f"For Python apps, {cheapest['platform']} offers good value"
|
| 165 |
+
else:
|
| 166 |
+
return f"{cheapest['platform']} is the most cost-effective option"
|
| 167 |
+
|
deployment_monitor.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Real-time deployment status monitoring."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import time
|
| 6 |
+
from typing import Any, Dict, List, Optional
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class DeploymentMonitor:
|
| 10 |
+
"""Monitors deployment status in real-time."""
|
| 11 |
+
|
| 12 |
+
def __init__(self):
|
| 13 |
+
self.deployments: Dict[str, Dict[str, Any]] = {}
|
| 14 |
+
|
| 15 |
+
def track_deployment(
|
| 16 |
+
self,
|
| 17 |
+
deployment_id: str,
|
| 18 |
+
platform: str,
|
| 19 |
+
repo: str,
|
| 20 |
+
status: str = "initiated"
|
| 21 |
+
) -> Dict[str, Any]:
|
| 22 |
+
"""Track a new deployment."""
|
| 23 |
+
deployment = {
|
| 24 |
+
"id": deployment_id,
|
| 25 |
+
"platform": platform,
|
| 26 |
+
"repo": repo,
|
| 27 |
+
"status": status,
|
| 28 |
+
"started_at": time.time(),
|
| 29 |
+
"updated_at": time.time(),
|
| 30 |
+
"stages": [],
|
| 31 |
+
"logs": []
|
| 32 |
+
}
|
| 33 |
+
self.deployments[deployment_id] = deployment
|
| 34 |
+
return deployment
|
| 35 |
+
|
| 36 |
+
def update_deployment_status(
|
| 37 |
+
self,
|
| 38 |
+
deployment_id: str,
|
| 39 |
+
status: str,
|
| 40 |
+
stage: Optional[str] = None,
|
| 41 |
+
log_message: Optional[str] = None
|
| 42 |
+
) -> Dict[str, Any]:
|
| 43 |
+
"""Update deployment status."""
|
| 44 |
+
if deployment_id not in self.deployments:
|
| 45 |
+
return {"error": "Deployment not found"}
|
| 46 |
+
|
| 47 |
+
deployment = self.deployments[deployment_id]
|
| 48 |
+
deployment["status"] = status
|
| 49 |
+
deployment["updated_at"] = time.time()
|
| 50 |
+
|
| 51 |
+
if stage:
|
| 52 |
+
deployment["stages"].append({
|
| 53 |
+
"name": stage,
|
| 54 |
+
"status": status,
|
| 55 |
+
"timestamp": time.time()
|
| 56 |
+
})
|
| 57 |
+
|
| 58 |
+
if log_message:
|
| 59 |
+
deployment["logs"].append({
|
| 60 |
+
"message": log_message,
|
| 61 |
+
"timestamp": time.time(),
|
| 62 |
+
"level": "info" if status == "success" else "warning" if status == "pending" else "error"
|
| 63 |
+
})
|
| 64 |
+
|
| 65 |
+
return deployment
|
| 66 |
+
|
| 67 |
+
def get_deployment_status(self, deployment_id: str) -> Dict[str, Any]:
|
| 68 |
+
"""Get current deployment status."""
|
| 69 |
+
if deployment_id not in self.deployments:
|
| 70 |
+
return {"error": "Deployment not found"}
|
| 71 |
+
|
| 72 |
+
deployment = self.deployments[deployment_id]
|
| 73 |
+
elapsed = time.time() - deployment["started_at"]
|
| 74 |
+
|
| 75 |
+
return {
|
| 76 |
+
**deployment,
|
| 77 |
+
"elapsed_time": f"{elapsed:.1f}s",
|
| 78 |
+
"is_complete": deployment["status"] in ["success", "failed", "cancelled"],
|
| 79 |
+
"is_running": deployment["status"] in ["initiated", "building", "deploying"]
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
def get_status_summary(self) -> Dict[str, Any]:
|
| 83 |
+
"""Get summary of all deployments."""
|
| 84 |
+
total = len(self.deployments)
|
| 85 |
+
running = len([d for d in self.deployments.values() if d["status"] in ["initiated", "building", "deploying"]])
|
| 86 |
+
successful = len([d for d in self.deployments.values() if d["status"] == "success"])
|
| 87 |
+
failed = len([d for d in self.deployments.values() if d["status"] == "failed"])
|
| 88 |
+
|
| 89 |
+
return {
|
| 90 |
+
"total_deployments": total,
|
| 91 |
+
"running": running,
|
| 92 |
+
"successful": successful,
|
| 93 |
+
"failed": failed,
|
| 94 |
+
"success_rate": (successful / total * 100) if total > 0 else 0
|
| 95 |
+
}
|
| 96 |
+
|
env_validator.py
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Environment variable validation and suggestions."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import os
|
| 6 |
+
import re
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
from typing import Any, Dict, List, Optional
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class EnvironmentValidator:
|
| 12 |
+
"""Validates and suggests environment variables."""
|
| 13 |
+
|
| 14 |
+
def __init__(self):
|
| 15 |
+
self.common_vars = {
|
| 16 |
+
"next.js": ["NEXT_PUBLIC_API_URL", "DATABASE_URL", "NEXTAUTH_SECRET", "NEXTAUTH_URL"],
|
| 17 |
+
"django": ["SECRET_KEY", "DEBUG", "DATABASE_URL", "ALLOWED_HOSTS"],
|
| 18 |
+
"fastapi": ["DATABASE_URL", "SECRET_KEY", "CORS_ORIGINS", "ENVIRONMENT"],
|
| 19 |
+
"react": ["REACT_APP_API_URL", "REACT_APP_ENV"],
|
| 20 |
+
"express": ["PORT", "NODE_ENV", "DATABASE_URL", "JWT_SECRET"],
|
| 21 |
+
"nestjs": ["PORT", "DATABASE_URL", "JWT_SECRET", "NODE_ENV"],
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
def validate_env_file(self, folder_path: str, framework: Optional[str] = None) -> Dict[str, Any]:
|
| 25 |
+
"""Validate .env files in codebase."""
|
| 26 |
+
path = Path(folder_path)
|
| 27 |
+
env_files = list(path.rglob(".env*"))
|
| 28 |
+
|
| 29 |
+
found_vars = []
|
| 30 |
+
missing_vars = []
|
| 31 |
+
issues = []
|
| 32 |
+
|
| 33 |
+
# Read all env files
|
| 34 |
+
for env_file in env_files:
|
| 35 |
+
if env_file.is_file() and ".git" not in str(env_file):
|
| 36 |
+
try:
|
| 37 |
+
content = env_file.read_text()
|
| 38 |
+
# Extract variable names
|
| 39 |
+
var_pattern = r'^([A-Z_][A-Z0-9_]*)\s*='
|
| 40 |
+
vars_in_file = re.findall(var_pattern, content, re.MULTILINE)
|
| 41 |
+
found_vars.extend(vars_in_file)
|
| 42 |
+
except Exception:
|
| 43 |
+
pass
|
| 44 |
+
|
| 45 |
+
# Check for framework-specific requirements
|
| 46 |
+
if framework:
|
| 47 |
+
required_vars = self.common_vars.get(framework.lower(), [])
|
| 48 |
+
for var in required_vars:
|
| 49 |
+
if var not in found_vars:
|
| 50 |
+
missing_vars.append({
|
| 51 |
+
"variable": var,
|
| 52 |
+
"required": True,
|
| 53 |
+
"description": self._get_var_description(var, framework)
|
| 54 |
+
})
|
| 55 |
+
|
| 56 |
+
# Check for common issues
|
| 57 |
+
for env_file in env_files:
|
| 58 |
+
try:
|
| 59 |
+
content = env_file.read_text()
|
| 60 |
+
# Check for hardcoded secrets
|
| 61 |
+
if re.search(r'(password|secret|key|token)\s*=\s*["\'][^"\']+["\']', content, re.IGNORECASE):
|
| 62 |
+
issues.append({
|
| 63 |
+
"file": str(env_file.relative_to(path)),
|
| 64 |
+
"severity": "high",
|
| 65 |
+
"issue": "Hardcoded secrets detected - use environment variables or secrets manager"
|
| 66 |
+
})
|
| 67 |
+
|
| 68 |
+
# Check for .env in git
|
| 69 |
+
gitignore = path / ".gitignore"
|
| 70 |
+
if gitignore.exists():
|
| 71 |
+
gitignore_content = gitignore.read_text()
|
| 72 |
+
if ".env" not in gitignore_content:
|
| 73 |
+
issues.append({
|
| 74 |
+
"file": ".gitignore",
|
| 75 |
+
"severity": "medium",
|
| 76 |
+
"issue": ".env files should be in .gitignore"
|
| 77 |
+
})
|
| 78 |
+
except Exception:
|
| 79 |
+
pass
|
| 80 |
+
|
| 81 |
+
return {
|
| 82 |
+
"env_files_found": len(env_files),
|
| 83 |
+
"variables_found": len(set(found_vars)),
|
| 84 |
+
"missing_required": missing_vars,
|
| 85 |
+
"issues": issues,
|
| 86 |
+
"status": "valid" if not missing_vars and not issues else "needs_attention",
|
| 87 |
+
"recommendations": self._get_recommendations(framework, missing_vars, issues)
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
def suggest_env_vars(self, framework: str, platform: str) -> List[Dict[str, str]]:
|
| 91 |
+
"""Suggest environment variables based on framework and platform."""
|
| 92 |
+
suggestions = []
|
| 93 |
+
|
| 94 |
+
# Framework-specific
|
| 95 |
+
framework_vars = self.common_vars.get(framework.lower(), [])
|
| 96 |
+
for var in framework_vars:
|
| 97 |
+
suggestions.append({
|
| 98 |
+
"variable": var,
|
| 99 |
+
"required": True,
|
| 100 |
+
"description": self._get_var_description(var, framework),
|
| 101 |
+
"category": "framework"
|
| 102 |
+
})
|
| 103 |
+
|
| 104 |
+
# Platform-specific
|
| 105 |
+
platform_vars = {
|
| 106 |
+
"vercel": ["VERCEL_URL", "VERCEL_ENV"],
|
| 107 |
+
"netlify": ["NETLIFY", "CONTEXT"],
|
| 108 |
+
"aws": ["AWS_REGION", "AWS_ACCESS_KEY_ID"],
|
| 109 |
+
"gcp": ["GOOGLE_CLOUD_PROJECT", "GCP_REGION"],
|
| 110 |
+
"azure": ["AZURE_REGION", "AZURE_SUBSCRIPTION_ID"],
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
platform_vars_list = platform_vars.get(platform.lower(), [])
|
| 114 |
+
for var in platform_vars_list:
|
| 115 |
+
suggestions.append({
|
| 116 |
+
"variable": var,
|
| 117 |
+
"required": False,
|
| 118 |
+
"description": f"Platform-specific variable for {platform}",
|
| 119 |
+
"category": "platform"
|
| 120 |
+
})
|
| 121 |
+
|
| 122 |
+
return suggestions
|
| 123 |
+
|
| 124 |
+
def _get_var_description(self, var: str, framework: str) -> str:
|
| 125 |
+
"""Get description for a variable."""
|
| 126 |
+
descriptions = {
|
| 127 |
+
"DATABASE_URL": "Database connection string",
|
| 128 |
+
"SECRET_KEY": "Secret key for encryption/signing",
|
| 129 |
+
"API_URL": "API endpoint URL",
|
| 130 |
+
"NODE_ENV": "Node.js environment (development/production)",
|
| 131 |
+
"PORT": "Application port number",
|
| 132 |
+
"DEBUG": "Debug mode flag",
|
| 133 |
+
}
|
| 134 |
+
return descriptions.get(var, f"Required for {framework}")
|
| 135 |
+
|
| 136 |
+
def _get_recommendations(
|
| 137 |
+
self,
|
| 138 |
+
framework: Optional[str],
|
| 139 |
+
missing_vars: List[Dict],
|
| 140 |
+
issues: List[Dict]
|
| 141 |
+
) -> List[str]:
|
| 142 |
+
"""Get recommendations based on validation results."""
|
| 143 |
+
recommendations = []
|
| 144 |
+
|
| 145 |
+
if missing_vars:
|
| 146 |
+
recommendations.append(f"Add {len(missing_vars)} missing required environment variables")
|
| 147 |
+
|
| 148 |
+
if issues:
|
| 149 |
+
recommendations.append("Review security issues in environment files")
|
| 150 |
+
|
| 151 |
+
recommendations.append("Use a secrets manager (AWS Secrets Manager, HashiCorp Vault) for production")
|
| 152 |
+
recommendations.append("Never commit .env files to version control")
|
| 153 |
+
|
| 154 |
+
if framework:
|
| 155 |
+
recommendations.append(f"Follow {framework} best practices for environment configuration")
|
| 156 |
+
|
| 157 |
+
return recommendations
|
| 158 |
+
|
monitoring_integration.py
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Monitoring and observability integration."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
from typing import Any, Dict, List, Optional
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class MonitoringIntegration:
|
| 9 |
+
"""Integrates with monitoring and observability tools."""
|
| 10 |
+
|
| 11 |
+
def get_monitoring_setup(
|
| 12 |
+
self,
|
| 13 |
+
framework: str,
|
| 14 |
+
platform: str
|
| 15 |
+
) -> Dict[str, Any]:
|
| 16 |
+
"""Get monitoring setup recommendations."""
|
| 17 |
+
|
| 18 |
+
monitoring_tools = {
|
| 19 |
+
"next.js": {
|
| 20 |
+
"recommended": ["Vercel Analytics", "Sentry", "LogRocket"],
|
| 21 |
+
"built_in": "Vercel Analytics (if on Vercel)"
|
| 22 |
+
},
|
| 23 |
+
"django": {
|
| 24 |
+
"recommended": ["Sentry", "New Relic", "Datadog"],
|
| 25 |
+
"built_in": "Django Debug Toolbar (dev only)"
|
| 26 |
+
},
|
| 27 |
+
"fastapi": {
|
| 28 |
+
"recommended": ["Prometheus", "Grafana", "Sentry"],
|
| 29 |
+
"built_in": "FastAPI metrics endpoint"
|
| 30 |
+
},
|
| 31 |
+
"react": {
|
| 32 |
+
"recommended": ["Sentry", "LogRocket", "Mixpanel"],
|
| 33 |
+
"built_in": "React DevTools (dev only)"
|
| 34 |
+
},
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
framework_tools = monitoring_tools.get(framework.lower(), {
|
| 38 |
+
"recommended": ["Sentry", "New Relic", "Datadog"],
|
| 39 |
+
"built_in": "Application logs"
|
| 40 |
+
})
|
| 41 |
+
|
| 42 |
+
# Platform-specific monitoring
|
| 43 |
+
platform_monitoring = {
|
| 44 |
+
"vercel": "Vercel Analytics and Speed Insights included",
|
| 45 |
+
"netlify": "Netlify Analytics available",
|
| 46 |
+
"aws": "CloudWatch monitoring included",
|
| 47 |
+
"gcp": "Cloud Monitoring and Logging included",
|
| 48 |
+
"azure": "Azure Monitor included",
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
return {
|
| 52 |
+
"framework": framework,
|
| 53 |
+
"platform": platform,
|
| 54 |
+
"recommended_tools": framework_tools["recommended"],
|
| 55 |
+
"built_in_monitoring": framework_tools.get("built_in", ""),
|
| 56 |
+
"platform_monitoring": platform_monitoring.get(platform.lower(), "Use third-party tools"),
|
| 57 |
+
"setup_steps": self._get_setup_steps(framework, platform),
|
| 58 |
+
"key_metrics": self._get_key_metrics(framework)
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
def _get_setup_steps(self, framework: str, platform: str) -> List[str]:
|
| 62 |
+
"""Get setup steps for monitoring."""
|
| 63 |
+
steps = [
|
| 64 |
+
f"1. Set up error tracking (Sentry recommended for {framework})",
|
| 65 |
+
f"2. Configure application performance monitoring",
|
| 66 |
+
"3. Set up log aggregation",
|
| 67 |
+
"4. Configure alerting for critical errors",
|
| 68 |
+
"5. Set up uptime monitoring",
|
| 69 |
+
]
|
| 70 |
+
|
| 71 |
+
if platform.lower() in ["aws", "gcp", "azure"]:
|
| 72 |
+
steps.append(f"6. Enable {platform} native monitoring")
|
| 73 |
+
|
| 74 |
+
return steps
|
| 75 |
+
|
| 76 |
+
def _get_key_metrics(self, framework: str) -> List[str]:
|
| 77 |
+
"""Get key metrics to monitor."""
|
| 78 |
+
base_metrics = [
|
| 79 |
+
"Response time (p50, p95, p99)",
|
| 80 |
+
"Error rate",
|
| 81 |
+
"Request rate",
|
| 82 |
+
"CPU and memory usage"
|
| 83 |
+
]
|
| 84 |
+
|
| 85 |
+
framework_metrics = {
|
| 86 |
+
"next.js": ["Page load time", "Time to First Byte (TTFB)", "Core Web Vitals"],
|
| 87 |
+
"django": ["Database query time", "Request processing time"],
|
| 88 |
+
"fastapi": ["API response time", "Concurrent requests"],
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
return base_metrics + framework_metrics.get(framework.lower(), [])
|
| 92 |
+
|
performance_optimizer.py
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Performance optimization suggestions."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
from typing import Any, Dict, List, Optional
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class PerformanceOptimizer:
|
| 9 |
+
"""Provides performance optimization recommendations."""
|
| 10 |
+
|
| 11 |
+
def analyze_performance(self, framework: str, platform: str, analysis: Dict[str, Any]) -> Dict[str, Any]:
|
| 12 |
+
"""Analyze and suggest performance optimizations."""
|
| 13 |
+
optimizations = []
|
| 14 |
+
score = 100
|
| 15 |
+
|
| 16 |
+
# Framework-specific optimizations
|
| 17 |
+
if framework.lower() == "next.js":
|
| 18 |
+
optimizations.extend([
|
| 19 |
+
{
|
| 20 |
+
"category": "build",
|
| 21 |
+
"priority": "high",
|
| 22 |
+
"suggestion": "Enable static generation for pages where possible",
|
| 23 |
+
"impact": "Reduces server load and improves response time"
|
| 24 |
+
},
|
| 25 |
+
{
|
| 26 |
+
"category": "images",
|
| 27 |
+
"priority": "medium",
|
| 28 |
+
"suggestion": "Use next/image for automatic image optimization",
|
| 29 |
+
"impact": "Reduces image size by 30-50%"
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"category": "caching",
|
| 33 |
+
"priority": "high",
|
| 34 |
+
"suggestion": "Implement ISR (Incremental Static Regeneration)",
|
| 35 |
+
"impact": "Improves page load time significantly"
|
| 36 |
+
}
|
| 37 |
+
])
|
| 38 |
+
score -= 10 if not analysis.get("has_docker") else 0
|
| 39 |
+
|
| 40 |
+
elif framework.lower() in ["django", "flask", "fastapi"]:
|
| 41 |
+
optimizations.extend([
|
| 42 |
+
{
|
| 43 |
+
"category": "database",
|
| 44 |
+
"priority": "high",
|
| 45 |
+
"suggestion": "Enable database connection pooling",
|
| 46 |
+
"impact": "Reduces database connection overhead"
|
| 47 |
+
},
|
| 48 |
+
{
|
| 49 |
+
"category": "caching",
|
| 50 |
+
"priority": "high",
|
| 51 |
+
"suggestion": "Implement Redis caching layer",
|
| 52 |
+
"impact": "Improves response time by 40-60%"
|
| 53 |
+
},
|
| 54 |
+
{
|
| 55 |
+
"category": "async",
|
| 56 |
+
"priority": "medium",
|
| 57 |
+
"suggestion": "Use async/await for I/O operations",
|
| 58 |
+
"impact": "Improves concurrency and throughput"
|
| 59 |
+
}
|
| 60 |
+
])
|
| 61 |
+
|
| 62 |
+
# Platform-specific optimizations
|
| 63 |
+
if platform.lower() == "vercel":
|
| 64 |
+
optimizations.append({
|
| 65 |
+
"category": "edge",
|
| 66 |
+
"priority": "high",
|
| 67 |
+
"suggestion": "Use Edge Functions for low-latency responses",
|
| 68 |
+
"impact": "Reduces latency by 50-70%"
|
| 69 |
+
})
|
| 70 |
+
|
| 71 |
+
if platform.lower() in ["aws", "gcp", "azure"]:
|
| 72 |
+
optimizations.append({
|
| 73 |
+
"category": "cdn",
|
| 74 |
+
"priority": "high",
|
| 75 |
+
"suggestion": "Enable CDN for static assets",
|
| 76 |
+
"impact": "Improves global load times"
|
| 77 |
+
})
|
| 78 |
+
|
| 79 |
+
# General optimizations
|
| 80 |
+
if not analysis.get("has_docker"):
|
| 81 |
+
optimizations.append({
|
| 82 |
+
"category": "containerization",
|
| 83 |
+
"priority": "medium",
|
| 84 |
+
"suggestion": "Containerize application for consistent deployments",
|
| 85 |
+
"impact": "Improves deployment reliability"
|
| 86 |
+
})
|
| 87 |
+
|
| 88 |
+
if analysis.get("dependencies", []):
|
| 89 |
+
dep_count = len(analysis.get("dependencies", []))
|
| 90 |
+
if dep_count > 50:
|
| 91 |
+
optimizations.append({
|
| 92 |
+
"category": "dependencies",
|
| 93 |
+
"priority": "medium",
|
| 94 |
+
"suggestion": f"Review {dep_count} dependencies - consider removing unused ones",
|
| 95 |
+
"impact": "Reduces bundle size and build time"
|
| 96 |
+
})
|
| 97 |
+
|
| 98 |
+
return {
|
| 99 |
+
"performance_score": max(0, score),
|
| 100 |
+
"optimizations": optimizations,
|
| 101 |
+
"priority_count": {
|
| 102 |
+
"high": len([o for o in optimizations if o["priority"] == "high"]),
|
| 103 |
+
"medium": len([o for o in optimizations if o["priority"] == "medium"]),
|
| 104 |
+
"low": len([o for o in optimizations if o["priority"] == "low"])
|
| 105 |
+
},
|
| 106 |
+
"estimated_improvement": self._estimate_improvement(optimizations)
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
def _estimate_improvement(self, optimizations: List[Dict]) -> str:
|
| 110 |
+
"""Estimate performance improvement."""
|
| 111 |
+
high_priority = len([o for o in optimizations if o["priority"] == "high"])
|
| 112 |
+
|
| 113 |
+
if high_priority >= 3:
|
| 114 |
+
return "30-50% performance improvement possible"
|
| 115 |
+
elif high_priority >= 2:
|
| 116 |
+
return "20-30% performance improvement possible"
|
| 117 |
+
elif high_priority >= 1:
|
| 118 |
+
return "10-20% performance improvement possible"
|
| 119 |
+
else:
|
| 120 |
+
return "Minor optimizations available"
|
| 121 |
+
|
rollback_manager.py
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Rollback strategies and disaster recovery."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
from typing import Any, Dict, List, Optional
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class RollbackManager:
|
| 9 |
+
"""Manages rollback strategies and disaster recovery plans."""
|
| 10 |
+
|
| 11 |
+
def generate_rollback_plan(
|
| 12 |
+
self,
|
| 13 |
+
platform: str,
|
| 14 |
+
framework: str,
|
| 15 |
+
deployment_type: str = "blue_green"
|
| 16 |
+
) -> Dict[str, Any]:
|
| 17 |
+
"""Generate rollback plan for deployment."""
|
| 18 |
+
|
| 19 |
+
rollback_strategies = {
|
| 20 |
+
"vercel": {
|
| 21 |
+
"strategy": "instant_rollback",
|
| 22 |
+
"steps": [
|
| 23 |
+
"1. Go to Vercel dashboard",
|
| 24 |
+
"2. Select previous deployment",
|
| 25 |
+
"3. Click 'Promote to Production'",
|
| 26 |
+
"4. Rollback completes in < 1 minute"
|
| 27 |
+
],
|
| 28 |
+
"time_to_rollback": "< 1 minute",
|
| 29 |
+
"data_loss_risk": "None"
|
| 30 |
+
},
|
| 31 |
+
"netlify": {
|
| 32 |
+
"strategy": "deploy_rollback",
|
| 33 |
+
"steps": [
|
| 34 |
+
"1. Go to Netlify dashboard",
|
| 35 |
+
"2. Navigate to Deploys",
|
| 36 |
+
"3. Select previous successful deploy",
|
| 37 |
+
"4. Click 'Publish deploy'",
|
| 38 |
+
"5. Rollback completes in < 2 minutes"
|
| 39 |
+
],
|
| 40 |
+
"time_to_rollback": "< 2 minutes",
|
| 41 |
+
"data_loss_risk": "None"
|
| 42 |
+
},
|
| 43 |
+
"kubernetes": {
|
| 44 |
+
"strategy": "blue_green",
|
| 45 |
+
"steps": [
|
| 46 |
+
"1. Keep previous deployment running",
|
| 47 |
+
"2. Switch traffic to previous version",
|
| 48 |
+
"3. Scale down new deployment",
|
| 49 |
+
"4. Rollback completes in < 5 minutes"
|
| 50 |
+
],
|
| 51 |
+
"time_to_rollback": "< 5 minutes",
|
| 52 |
+
"data_loss_risk": "Low (if database migrations involved)"
|
| 53 |
+
},
|
| 54 |
+
"docker": {
|
| 55 |
+
"strategy": "container_rollback",
|
| 56 |
+
"steps": [
|
| 57 |
+
"1. Stop current container",
|
| 58 |
+
"2. Start previous container version",
|
| 59 |
+
"3. Update load balancer",
|
| 60 |
+
"4. Rollback completes in < 3 minutes"
|
| 61 |
+
],
|
| 62 |
+
"time_to_rollback": "< 3 minutes",
|
| 63 |
+
"data_loss_risk": "Low"
|
| 64 |
+
},
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
strategy = rollback_strategies.get(platform.lower(), {
|
| 68 |
+
"strategy": "manual_rollback",
|
| 69 |
+
"steps": [
|
| 70 |
+
"1. Identify previous stable version",
|
| 71 |
+
"2. Redeploy previous version",
|
| 72 |
+
"3. Verify functionality",
|
| 73 |
+
"4. Monitor for issues"
|
| 74 |
+
],
|
| 75 |
+
"time_to_rollback": "5-10 minutes",
|
| 76 |
+
"data_loss_risk": "Medium"
|
| 77 |
+
})
|
| 78 |
+
|
| 79 |
+
return {
|
| 80 |
+
"platform": platform,
|
| 81 |
+
"framework": framework,
|
| 82 |
+
"strategy": strategy["strategy"],
|
| 83 |
+
"steps": strategy["steps"],
|
| 84 |
+
"time_to_rollback": strategy["time_to_rollback"],
|
| 85 |
+
"data_loss_risk": strategy["data_loss_risk"],
|
| 86 |
+
"pre_rollback_checklist": self._get_pre_rollback_checklist(),
|
| 87 |
+
"post_rollback_checklist": self._get_post_rollback_checklist()
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
def _get_pre_rollback_checklist(self) -> List[str]:
|
| 91 |
+
"""Get pre-rollback checklist."""
|
| 92 |
+
return [
|
| 93 |
+
"Identify the issue causing rollback",
|
| 94 |
+
"Document current deployment version",
|
| 95 |
+
"Verify previous stable version is available",
|
| 96 |
+
"Notify team about rollback",
|
| 97 |
+
"Backup current database (if applicable)",
|
| 98 |
+
"Check for database migrations that need reversal"
|
| 99 |
+
]
|
| 100 |
+
|
| 101 |
+
def _get_post_rollback_checklist(self) -> List[str]:
|
| 102 |
+
"""Get post-rollback checklist."""
|
| 103 |
+
return [
|
| 104 |
+
"Verify application is functioning correctly",
|
| 105 |
+
"Monitor error rates and performance",
|
| 106 |
+
"Check database integrity",
|
| 107 |
+
"Notify team of successful rollback",
|
| 108 |
+
"Document rollback reason and lessons learned",
|
| 109 |
+
"Plan fix for the issue that caused rollback"
|
| 110 |
+
]
|
| 111 |
+
|
| 112 |
+
def generate_disaster_recovery_plan(self, platform: str) -> Dict[str, Any]:
|
| 113 |
+
"""Generate disaster recovery plan."""
|
| 114 |
+
return {
|
| 115 |
+
"platform": platform,
|
| 116 |
+
"recovery_time_objective": "15-30 minutes",
|
| 117 |
+
"recovery_point_objective": "Last successful deployment",
|
| 118 |
+
"backup_strategy": "Automated backups before each deployment",
|
| 119 |
+
"monitoring": "Set up alerts for critical failures",
|
| 120 |
+
"communication_plan": "Notify stakeholders within 5 minutes of incident",
|
| 121 |
+
"steps": [
|
| 122 |
+
"1. Assess the severity of the incident",
|
| 123 |
+
"2. Execute rollback plan",
|
| 124 |
+
"3. Verify system stability",
|
| 125 |
+
"4. Investigate root cause",
|
| 126 |
+
"5. Implement fix",
|
| 127 |
+
"6. Re-deploy with fix",
|
| 128 |
+
"7. Document incident and improvements"
|
| 129 |
+
]
|
| 130 |
+
}
|
| 131 |
+
|
security_scanner.py
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Security scanning for dependencies and secrets."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import re
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
from typing import Any, Dict, List
|
| 8 |
+
|
| 9 |
+
from codebase_analyzer import CodebaseAnalyzer
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class SecurityScanner:
|
| 13 |
+
"""Scans codebase for security issues."""
|
| 14 |
+
|
| 15 |
+
def __init__(self):
|
| 16 |
+
self.analyzer = CodebaseAnalyzer()
|
| 17 |
+
|
| 18 |
+
def scan_dependencies(self, folder_path: str) -> Dict[str, Any]:
|
| 19 |
+
"""Scan dependencies for known vulnerabilities."""
|
| 20 |
+
analysis = self.analyzer.analyze_folder(folder_path)
|
| 21 |
+
dependencies = analysis.get("dependencies", [])
|
| 22 |
+
|
| 23 |
+
# Known vulnerable packages (simplified - would use real vulnerability DB)
|
| 24 |
+
vulnerable_packages = {
|
| 25 |
+
"lodash": "< 4.17.21",
|
| 26 |
+
"axios": "< 0.21.1",
|
| 27 |
+
"express": "< 4.17.1",
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
issues = []
|
| 31 |
+
for dep in dependencies[:20]: # Check first 20
|
| 32 |
+
dep_name = dep.lower() if isinstance(dep, str) else dep.get("name", "").lower()
|
| 33 |
+
if dep_name in vulnerable_packages:
|
| 34 |
+
issues.append({
|
| 35 |
+
"package": dep_name,
|
| 36 |
+
"severity": "high",
|
| 37 |
+
"issue": f"Known vulnerability, update to {vulnerable_packages[dep_name]}",
|
| 38 |
+
"type": "dependency_vulnerability"
|
| 39 |
+
})
|
| 40 |
+
|
| 41 |
+
return {
|
| 42 |
+
"total_dependencies": len(dependencies),
|
| 43 |
+
"scanned": min(20, len(dependencies)),
|
| 44 |
+
"vulnerabilities_found": len(issues),
|
| 45 |
+
"issues": issues,
|
| 46 |
+
"status": "safe" if not issues else "vulnerabilities_detected"
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
def scan_secrets(self, folder_path: str) -> Dict[str, Any]:
|
| 50 |
+
"""Scan for exposed secrets and API keys."""
|
| 51 |
+
path = Path(folder_path)
|
| 52 |
+
secrets_found = []
|
| 53 |
+
|
| 54 |
+
# Patterns for common secrets
|
| 55 |
+
secret_patterns = {
|
| 56 |
+
"api_key": r'(?i)(api[_-]?key|apikey)\s*[:=]\s*["\']?([a-zA-Z0-9_\-]{20,})["\']?',
|
| 57 |
+
"secret": r'(?i)(secret|password|pwd)\s*[:=]\s*["\']?([a-zA-Z0-9_\-]{10,})["\']?',
|
| 58 |
+
"token": r'(?i)(token|bearer)\s*[:=]\s*["\']?([a-zA-Z0-9_\-]{20,})["\']?',
|
| 59 |
+
"aws_key": r'AKIA[0-9A-Z]{16}',
|
| 60 |
+
"private_key": r'-----BEGIN\s+(RSA\s+)?PRIVATE\s+KEY-----',
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
# Scan common config files
|
| 64 |
+
config_files = ["*.env", "*.env.*", "*.config.js", "*.config.ts", "*.json"]
|
| 65 |
+
|
| 66 |
+
for pattern in config_files:
|
| 67 |
+
for file_path in path.rglob(pattern):
|
| 68 |
+
if file_path.is_file() and ".git" not in str(file_path):
|
| 69 |
+
try:
|
| 70 |
+
content = file_path.read_text()
|
| 71 |
+
for secret_type, regex in secret_patterns.items():
|
| 72 |
+
matches = re.findall(regex, content)
|
| 73 |
+
if matches:
|
| 74 |
+
secrets_found.append({
|
| 75 |
+
"file": str(file_path.relative_to(path)),
|
| 76 |
+
"type": secret_type,
|
| 77 |
+
"severity": "critical",
|
| 78 |
+
"issue": f"Potential {secret_type} exposed in {file_path.name}"
|
| 79 |
+
})
|
| 80 |
+
except Exception:
|
| 81 |
+
pass
|
| 82 |
+
|
| 83 |
+
return {
|
| 84 |
+
"secrets_found": len(secrets_found),
|
| 85 |
+
"issues": secrets_found[:10], # Limit to 10
|
| 86 |
+
"status": "safe" if not secrets_found else "secrets_detected",
|
| 87 |
+
"recommendation": "Use environment variables and secrets management"
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
def scan_codebase(self, folder_path: str) -> Dict[str, Any]:
|
| 91 |
+
"""Complete security scan."""
|
| 92 |
+
deps_scan = self.scan_dependencies(folder_path)
|
| 93 |
+
secrets_scan = self.scan_secrets(folder_path)
|
| 94 |
+
|
| 95 |
+
return {
|
| 96 |
+
"dependencies": deps_scan,
|
| 97 |
+
"secrets": secrets_scan,
|
| 98 |
+
"overall_status": "safe" if deps_scan["status"] == "safe" and secrets_scan["status"] == "safe" else "issues_found",
|
| 99 |
+
"total_issues": deps_scan["vulnerabilities_found"] + secrets_scan["secrets_found"]
|
| 100 |
+
}
|
| 101 |
+
|