deploy.ps1 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. # PCB AFM Simulation System - Windows Deployment Script
  2. # Usage: .\deploy.ps1
  3. # Prerequisites: Python 3.10+, Node.js 18+, Git
  4. param(
  5. [switch]$SkipFrontendBuild,
  6. [switch]$SkipBackendDeps,
  7. [string]$BackendPort = "8000",
  8. [string]$FrontendPort = "5173"
  9. )
  10. $ErrorActionPreference = "Stop"
  11. $ProjectRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
  12. $BackendDir = Join-Path $ProjectRoot "web\backend"
  13. $FrontendDir = Join-Path $ProjectRoot "web\frontend"
  14. Write-Host "========================================" -ForegroundColor Cyan
  15. Write-Host "PCB AFM Simulation System - Deployment" -ForegroundColor Cyan
  16. Write-Host "========================================" -ForegroundColor Cyan
  17. Write-Host ""
  18. # Step 1: Check prerequisites
  19. Write-Host "[1/6] Checking prerequisites..." -ForegroundColor Yellow
  20. try {
  21. $pythonVersion = python --version 2>&1
  22. Write-Host " Python: $pythonVersion" -ForegroundColor Green
  23. } catch {
  24. Write-Host " ERROR: Python not found. Install Python 3.10+" -ForegroundColor Red
  25. exit 1
  26. }
  27. try {
  28. $nodeVersion = node --version 2>&1
  29. Write-Host " Node.js: $nodeVersion" -ForegroundColor Green
  30. } catch {
  31. Write-Host " ERROR: Node.js not found. Install Node.js 18+" -ForegroundColor Red
  32. exit 1
  33. }
  34. # Step 2: Backend dependencies
  35. if (-not $SkipBackendDeps) {
  36. Write-Host ""
  37. Write-Host "[2/6] Installing backend dependencies..." -ForegroundColor Yellow
  38. Push-Location $BackendDir
  39. try {
  40. pip install -r requirements.txt
  41. Write-Host " Backend dependencies installed." -ForegroundColor Green
  42. } finally {
  43. Pop-Location
  44. }
  45. } else {
  46. Write-Host ""
  47. Write-Host "[2/6] Skipping backend dependencies (--SkipBackendDeps)." -ForegroundColor Yellow
  48. }
  49. # Step 3: Initialize database
  50. Write-Host ""
  51. Write-Host "[3/6] Initializing database..." -ForegroundColor Yellow
  52. Push-Location $BackendDir
  53. try {
  54. python -c "from app.database import init_db; init_db(); print('Database initialized.')"
  55. Write-Host " Database initialized." -ForegroundColor Green
  56. } catch {
  57. Write-Host " WARNING: Database init failed: $_" -ForegroundColor Yellow
  58. } finally {
  59. Pop-Location
  60. }
  61. # Step 4: Frontend build
  62. if (-not $SkipFrontendBuild) {
  63. Write-Host ""
  64. Write-Host "[4/6] Building frontend..." -ForegroundColor Yellow
  65. Push-Location $FrontendDir
  66. try {
  67. if (-not (Test-Path "node_modules")) {
  68. Write-Host " Installing npm packages..." -ForegroundColor Gray
  69. npm install
  70. }
  71. Write-Host " Running build..." -ForegroundColor Gray
  72. npm run build
  73. Write-Host " Frontend built successfully." -ForegroundColor Green
  74. } finally {
  75. Pop-Location
  76. }
  77. } else {
  78. Write-Host ""
  79. Write-Host "[4/6] Skipping frontend build (--SkipFrontendBuild)." -ForegroundColor Yellow
  80. }
  81. # Step 5: Environment configuration
  82. Write-Host ""
  83. Write-Host "[5/6] Checking environment configuration..." -ForegroundColor Yellow
  84. $envFile = Join-Path $BackendDir ".env"
  85. if (-not (Test-Path $envFile)) {
  86. Write-Host " Creating .env file from template..." -ForegroundColor Gray
  87. @"
  88. DATABASE_URL=sqlite:///./afm_sim.db
  89. KIMI_API_KEY=your_kimi_api_key_here
  90. KIMI_MODEL=k3
  91. KIMI_BASE_URL=https://api.kimi.com/coding/v1
  92. MAX_PARALLEL_TASKS=2
  93. "@ | Set-Content -Path $envFile -Encoding UTF8
  94. Write-Host " .env created. Please edit with your Kimi API key." -ForegroundColor Yellow
  95. } else {
  96. Write-Host " .env file exists." -ForegroundColor Green
  97. }
  98. # Step 6: Start services
  99. Write-Host ""
  100. Write-Host "[6/6] Starting services..." -ForegroundColor Yellow
  101. Write-Host ""
  102. Write-Host " Backend: http://localhost:$BackendPort" -ForegroundColor Cyan
  103. Write-Host " Frontend: http://localhost:$FrontendPort" -ForegroundColor Cyan
  104. Write-Host ""
  105. Write-Host " To start backend (in backend dir):" -ForegroundColor Gray
  106. Write-Host " python -m uvicorn app.main:app --host 0.0.0.0 --port $BackendPort" -ForegroundColor Gray
  107. Write-Host ""
  108. Write-Host " To start frontend dev server (in frontend dir):" -ForegroundColor Gray
  109. Write-Host " npm run dev" -ForegroundColor Gray
  110. Write-Host ""
  111. Write-Host " Or use Docker:" -ForegroundColor Gray
  112. Write-Host " docker-compose up -d" -ForegroundColor Gray
  113. Write-Host ""
  114. Write-Host "========================================" -ForegroundColor Cyan
  115. Write-Host "Deployment complete!" -ForegroundColor Green
  116. Write-Host "========================================" -ForegroundColor Cyan