-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.ps1
More file actions
156 lines (128 loc) · 5 KB
/
Copy pathstart.ps1
File metadata and controls
156 lines (128 loc) · 5 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
param(
[switch]$SkipBuild,
[switch]$FrontendOnly
)
$ErrorActionPreference = "Stop"
Write-Host ""
Write-Host "+-----------------------------------------------------------+" -ForegroundColor Cyan
Write-Host "| KalmanGuard Local Launcher |" -ForegroundColor Cyan
Write-Host "+-----------------------------------------------------------+" -ForegroundColor Cyan
Write-Host ""
$RootDir = $PSScriptRoot
# Check prerequisites
function Test-Prerequisites {
$missing = @()
if (-not (Get-Command docker -ErrorAction SilentlyContinue)) {
$missing += "Docker (https://docs.docker.com/get-docker/)"
}
if (-not (Get-Command node -ErrorAction SilentlyContinue)) {
$missing += "Node.js (https://nodejs.org/)"
}
if (-not (Get-Command npm -ErrorAction SilentlyContinue)) {
$missing += "npm (comes with Node.js)"
}
if ($missing.Count -gt 0) {
Write-Host "Missing prerequisites:" -ForegroundColor Red
foreach ($m in $missing) {
Write-Host " - $m" -ForegroundColor Yellow
}
exit 1
}
Write-Host "[OK] All prerequisites installed" -ForegroundColor Green
}
# Load environment
function Import-DotEnv {
$envFile = Join-Path $RootDir ".env"
if (Test-Path $envFile) {
Write-Host "[*] Loading .env file..." -ForegroundColor Gray
Get-Content $envFile | ForEach-Object {
$line = $_.Trim()
if (-not $line -or $line.StartsWith('#')) { return }
$idx = $line.IndexOf('=')
if ($idx -lt 1) { return }
$key = $line.Substring(0, $idx).Trim()
$val = $line.Substring($idx + 1).Trim()
if (-not (Get-Item -Path "Env:$key" -ErrorAction SilentlyContinue)) {
Set-Item -Path "Env:$key" -Value $val
}
}
}
}
# Start Docker backend
function Start-Backend {
Write-Host ""
Write-Host "[1/3] Starting Docker backend..." -ForegroundColor Cyan
$composeFile = Join-Path $RootDir "docker\docker-compose.yml"
$composeArgs = "--env-file `"$RootDir\.env`" -f `"$composeFile`""
$services = "redis kalman-engine agents"
if (-not $SkipBuild) {
Write-Host " Building containers (this may take a few minutes on first run)..." -ForegroundColor Gray
$buildCmd = "docker compose $composeArgs build $services"
Invoke-Expression $buildCmd
}
Write-Host " Starting services..." -ForegroundColor Gray
$upCmd = "docker compose $composeArgs up -d $services"
Invoke-Expression $upCmd
Write-Host "[OK] Backend started" -ForegroundColor Green
}
# Wait for backend health
function Wait-ForBackend {
Write-Host ""
Write-Host "[2/3] Waiting for backend to be healthy..." -ForegroundColor Cyan
$maxAttempts = 30
$attempt = 0
while ($attempt -lt $maxAttempts) {
try {
$response = Invoke-WebRequest -Uri "http://localhost:3001/health" -UseBasicParsing -TimeoutSec 2 -ErrorAction SilentlyContinue
if ($response.StatusCode -eq 200) {
Write-Host "[OK] Backend healthy at http://localhost:3001" -ForegroundColor Green
return
}
} catch {
# ignore
}
$attempt++
Write-Host " Waiting... ($attempt/$maxAttempts)" -ForegroundColor Gray
Start-Sleep -Seconds 2
}
Write-Host "[WARN] Backend may not be fully ready yet" -ForegroundColor Yellow
}
# Start frontend dev server
function Start-Frontend {
Write-Host ""
Write-Host "[3/3] Starting frontend dev server..." -ForegroundColor Cyan
$frontendDir = Join-Path $RootDir "frontend"
Push-Location $frontendDir
# Install deps if needed
if (-not (Test-Path (Join-Path $frontendDir "node_modules"))) {
Write-Host " Installing frontend dependencies..." -ForegroundColor Gray
npm install
}
Write-Host ""
Write-Host "===========================================================" -ForegroundColor Green
Write-Host ""
Write-Host " KalmanGuard is starting!" -ForegroundColor Green
Write-Host ""
Write-Host " Backend API: http://localhost:3001" -ForegroundColor White
Write-Host " Kalman Engine: http://localhost:8000" -ForegroundColor White
Write-Host " Frontend: http://localhost:5173 (opening soon...)" -ForegroundColor White
Write-Host ""
Write-Host " Network: Sepolia (single mode)" -ForegroundColor Cyan
Write-Host ""
Write-Host " Press Ctrl+C to stop the frontend dev server." -ForegroundColor Gray
Write-Host " Run 'docker compose -f docker/docker-compose.yml down' to stop backend." -ForegroundColor Gray
Write-Host ""
Write-Host "===========================================================" -ForegroundColor Green
Write-Host ""
# Start Vite (this will block)
npm run dev
Pop-Location
}
# Main
Test-Prerequisites
Import-DotEnv
if (-not $FrontendOnly) {
Start-Backend
Wait-ForBackend
}
Start-Frontend