-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart-prod.ps1
More file actions
189 lines (164 loc) · 6.87 KB
/
start-prod.ps1
File metadata and controls
189 lines (164 loc) · 6.87 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
#!/usr/bin/env pwsh
<#
.SYNOPSIS
SteerDock Production Mode Startup Script (Windows)
.DESCRIPTION
Compiles and starts backend and frontend in production mode
.EXAMPLE
.\start-prod.ps1
#>
$ErrorActionPreference = "Stop"
Write-Host "╔════════════════════════════════════════════════════════════╗" -ForegroundColor Cyan
Write-Host "║ SteerDock Production Mode (Windows) ║" -ForegroundColor Cyan
Write-Host "╚════════════════════════════════════════════════════════════╝" -ForegroundColor Cyan
Write-Host ""
# Check requirements
Write-Host "Checking requirements..." -ForegroundColor Yellow
# Check Go
try {
$goVersion = go version
Write-Host "[OK] Go found: $goVersion" -ForegroundColor Green
} catch {
Write-Host "[X] Go is not installed. Please install Go 1.24+" -ForegroundColor Red
exit 1
}
# Check Node.js
try {
$nodeVersion = node --version
Write-Host "[OK] Node.js found: $nodeVersion" -ForegroundColor Green
} catch {
Write-Host "[X] Node.js is not installed. Please install Node.js 18+" -ForegroundColor Red
exit 1
}
Write-Host ""
# Save current directory
$rootDir = Get-Location
# Stop existing processes
Write-Host "Stopping existing processes..." -ForegroundColor Yellow
if (Test-Path "$rootDir\stop-prod.ps1") {
& "$rootDir\stop-prod.ps1" -Silent
}
Start-Sleep -Seconds 2
# Create necessary directories
$dirs = @("$rootDir\logs", "$rootDir\backend\backups")
foreach ($dir in $dirs) {
if (-not (Test-Path $dir)) {
New-Item -ItemType Directory -Path $dir | Out-Null
Write-Host "Created directory: $dir" -ForegroundColor Gray
}
}
# Build backend
Write-Host "Building backend..." -ForegroundColor Yellow
Push-Location "$rootDir\backend"
$env:CGO_ENABLED = "0"
$env:GOOS = "windows"
$env:GOARCH = "amd64"
go build -ldflags="-s -w" -o steerdock.exe .
if ($LASTEXITCODE -ne 0) {
Write-Host "[X] Backend build failed" -ForegroundColor Red
Pop-Location
exit 1
}
Write-Host "[OK] Backend built successfully" -ForegroundColor Green
Pop-Location
# Build frontend
Write-Host "Building frontend..." -ForegroundColor Yellow
Push-Location "$rootDir\frontend"
if (-not (Test-Path "node_modules")) {
Write-Host "Installing frontend dependencies..." -ForegroundColor Yellow
npm install
if ($LASTEXITCODE -ne 0) {
Write-Host "[X] Frontend dependencies installation failed" -ForegroundColor Red
Pop-Location
exit 1
}
}
npm run build
if ($LASTEXITCODE -ne 0) {
Write-Host "[X] Frontend build failed" -ForegroundColor Red
Pop-Location
exit 1
}
Write-Host "[OK] Frontend built successfully" -ForegroundColor Green
Pop-Location
# Set production environment
$env:GIN_MODE = "release"
$env:NODE_ENV = "production"
# Start backend
Write-Host ""
Write-Host "Starting backend..." -ForegroundColor Yellow
Push-Location "$rootDir\backend"
$backendProcess = Start-Process -FilePath ".\steerdock.exe" -RedirectStandardOutput "..\logs\backend-prod.log" -RedirectStandardError "..\logs\backend-prod-error.log" -PassThru -NoNewWindow
Write-Host "[OK] Backend started (PID: $($backendProcess.Id))" -ForegroundColor Green
Pop-Location
# Wait for backend to start
Write-Host "Waiting for backend to initialize..." -ForegroundColor Yellow
$maxRetries = 30
$retryCount = 0
$backendReady = $false
while ($retryCount -lt $maxRetries) {
Start-Sleep -Seconds 1
try {
$response = Invoke-WebRequest -Uri "http://localhost:8383/health/live" -UseBasicParsing -TimeoutSec 2 -ErrorAction SilentlyContinue
if ($response.StatusCode -eq 200) {
$backendReady = $true
break
}
} catch {
# Continue waiting
}
$retryCount++
Write-Host "." -NoNewline -ForegroundColor Gray
}
Write-Host ""
if ($backendReady) {
Write-Host "[OK] Backend is healthy" -ForegroundColor Green
} else {
Write-Host "[X] Backend health check timeout" -ForegroundColor Red
Write-Host "Check logs\backend-prod-error.log for details" -ForegroundColor Yellow
exit 1
}
# Start frontend (serve built files)
Write-Host "Starting frontend..." -ForegroundColor Yellow
Push-Location "$rootDir\frontend"
# Find npx executable
$npxCmd = Get-Command npx.cmd -ErrorAction SilentlyContinue
if (-not $npxCmd) {
$npxCmd = Get-Command npx -ErrorAction SilentlyContinue
}
if ($npxCmd) {
$frontendProcess = Start-Process -FilePath $npxCmd.Source -ArgumentList "vite", "preview", "--host", "0.0.0.0", "--port", "5151" -RedirectStandardOutput "..\logs\frontend-prod.log" -RedirectStandardError "..\logs\frontend-prod-error.log" -PassThru -NoNewWindow
} else {
# Fallback: use cmd to run npx
$frontendProcess = Start-Process -FilePath "cmd.exe" -ArgumentList "/c", "npx vite preview --host 0.0.0.0 --port 5151" -RedirectStandardOutput "..\logs\frontend-prod.log" -RedirectStandardError "..\logs\frontend-prod-error.log" -PassThru -NoNewWindow
}
Write-Host "[OK] Frontend started (PID: $($frontendProcess.Id))" -ForegroundColor Green
Pop-Location
# Wait for frontend to start
Write-Host "Waiting for frontend to initialize..." -ForegroundColor Yellow
Start-Sleep -Seconds 3
Write-Host ""
Write-Host "╔════════════════════════════════════════════════════════════╗" -ForegroundColor Green
Write-Host "║ SteerDock Production Mode Started ║" -ForegroundColor Green
Write-Host "╚════════════════════════════════════════════════════════════╝" -ForegroundColor Green
Write-Host ""
Write-Host "Access Points:" -ForegroundColor Cyan
Write-Host " Frontend: http://localhost:5151" -ForegroundColor Green
Write-Host " Backend API: http://localhost:8383" -ForegroundColor Green
Write-Host " Health Check: http://localhost:8383/health/live" -ForegroundColor Green
Write-Host ""
Write-Host "Default Login:" -ForegroundColor Cyan
Write-Host " Username: admin" -ForegroundColor Yellow
Write-Host " Password: admin123" -ForegroundColor Yellow
Write-Host ""
Write-Host "Process IDs:" -ForegroundColor Cyan
Write-Host " Backend: $($backendProcess.Id)" -ForegroundColor Gray
Write-Host " Frontend: $($frontendProcess.Id)" -ForegroundColor Gray
Write-Host ""
Write-Host "Logs:" -ForegroundColor Cyan
Write-Host " Backend: Get-Content logs\backend-prod.log -Wait" -ForegroundColor Yellow
Write-Host " Frontend: Get-Content logs\frontend-prod.log -Wait" -ForegroundColor Yellow
Write-Host ""
Write-Host "To stop all services:" -ForegroundColor Cyan
Write-Host " .\stop-prod.ps1" -ForegroundColor Yellow
Write-Host ""