-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
421 lines (360 loc) · 15.7 KB
/
install.ps1
File metadata and controls
421 lines (360 loc) · 15.7 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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
#Requires -Version 5.1
<#
.SYNOPSIS
Govrix AI OSS — Windows PowerShell Installer
.DESCRIPTION
Installs Govrix AI OSS on Windows using Docker.
Two modes:
Default (-Dev not set) — Docker-only, no Rust or Node.js needed.
-Dev — Full contributor setup (requires Rust + Node.js 20+).
.PARAMETER Dev
Switch to enable full contributor / developer setup.
.EXAMPLE
# End-user (Docker only):
iwr -useb https://raw.githubusercontent.com/Govrix-AI/govrixaioss/main/install.ps1 | iex
# Contributor setup:
.\install.ps1 -Dev
# Pipe with flag (save first, then run):
iwr -useb https://raw.githubusercontent.com/Govrix-AI/govrixaioss/main/install.ps1 -OutFile install.ps1
.\install.ps1 -Dev
.NOTES
Requires Windows 10 (1903+) or Windows 11 with Docker Desktop installed.
Run from PowerShell 5.1+ or PowerShell 7+.
#>
[CmdletBinding()]
param(
[switch]$Dev,
[string]$GovrixDir = "$env:USERPROFILE\.govrix"
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
# ── Config ────────────────────────────────────────────────────────────────────
$REPO_RAW_BASE = "https://raw.githubusercontent.com/Govrix-AI/govrixaioss/main"
$REPO_URL = "https://github.com/Govrix-AI/govrixaioss"
# ── Colors ────────────────────────────────────────────────────────────────────
function Write-Info { param([string]$Msg) Write-Host "[govrix] $Msg" -ForegroundColor Cyan }
function Write-Success { param([string]$Msg) Write-Host "[govrix] $Msg" -ForegroundColor Green }
function Write-Warn { param([string]$Msg) Write-Host "[govrix] WARN: $Msg" -ForegroundColor Yellow }
function Write-Fail {
param([string]$Msg)
Write-Host "[govrix] ERROR: $Msg" -ForegroundColor Red
throw "Installation failed: $Msg"
}
function Write-Separator { Write-Host ("=" * 63) }
# ── Secure random hex ─────────────────────────────────────────────────────────
function New-SecureHex {
param([int]$ByteCount = 24)
$rng = [System.Security.Cryptography.RandomNumberGenerator]::Create()
$bytes = [byte[]]::new($ByteCount)
$rng.GetBytes($bytes)
$rng.Dispose()
return ([System.BitConverter]::ToString($bytes) -replace '-', '').ToLower()
}
# ── Check Docker ──────────────────────────────────────────────────────────────
function Test-Docker {
Write-Info "Checking Docker..."
if (-not (Get-Command docker -ErrorAction SilentlyContinue)) {
Write-Host ""
Write-Fail @"
Docker is not installed.
Install Docker Desktop from: https://docs.docker.com/get-docker/
Then re-run this installer.
"@
}
$dockerInfo = docker info 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Host ""
Write-Fail @"
Docker daemon is not running.
Start Docker Desktop, wait for it to be ready, then re-run this installer.
"@
}
$composeCheck = docker compose version 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Host ""
Write-Fail @"
Docker Compose v2 is not available.
Upgrade Docker Desktop to include Compose v2.
See: https://docs.docker.com/compose/install/
"@
}
$composeVer = (docker compose version --short 2>$null) -join ''
if (-not $composeVer) { $composeVer = 'v2' }
Write-Success "Docker ready (Compose $composeVer)"
}
# ── Check Rust ────────────────────────────────────────────────────────────────
function Test-OrInstallRust {
if (Get-Command rustc -ErrorAction SilentlyContinue) {
Write-Success "Rust found: $(rustc --version)"
return
}
Write-Info "Rust not found — installing via rustup (this takes ~2 minutes)..."
$rustupInstaller = "$env:TEMP\rustup-init.exe"
Invoke-WebRequest -Uri 'https://win.rustup.rs/x86_64' -OutFile $rustupInstaller -UseBasicParsing
& $rustupInstaller -y --default-toolchain stable
Remove-Item $rustupInstaller -Force -ErrorAction SilentlyContinue
# Refresh PATH for this session
$env:PATH += ";$env:USERPROFILE\.cargo\bin"
if (Get-Command rustc -ErrorAction SilentlyContinue) {
Write-Success "Rust installed: $(rustc --version)"
} else {
Write-Fail "Rust installation failed. Please install manually from https://rustup.rs"
}
}
# ── Check Node.js ─────────────────────────────────────────────────────────────
function Test-Node {
if (-not (Get-Command node -ErrorAction SilentlyContinue)) {
Write-Host ""
Write-Fail @"
Node.js 20+ is required for -Dev mode.
Download from: https://nodejs.org
Or install via winget: winget install OpenJS.NodeJS.LTS
Or install via nvm-windows: https://github.com/coreybutler/nvm-windows
"@
}
$nodeVer = (node --version) -replace '^v', ''
$nodeMajor = [int]($nodeVer -split '\.')[0]
if ($nodeMajor -lt 20) {
Write-Fail "Node.js 20+ required, found v$nodeVer.`n Update: winget upgrade OpenJS.NodeJS.LTS"
}
Write-Success "Node.js v$nodeVer"
}
# ── Check / install pnpm ──────────────────────────────────────────────────────
function Test-OrInstallPnpm {
if (Get-Command pnpm -ErrorAction SilentlyContinue) {
Write-Success "pnpm $(pnpm --version)"
return
}
Write-Info "Installing pnpm..."
npm install -g pnpm
Write-Success "pnpm $(pnpm --version) installed"
}
# ── Health check loop ─────────────────────────────────────────────────────────
function Wait-Healthy {
param(
[string]$Url,
[string]$Label,
[int] $TimeoutSec = 90,
[int] $IntervalSec = 3
)
Write-Host "[govrix] Waiting for $Label" -ForegroundColor Cyan -NoNewline
$elapsed = 0
while ($elapsed -lt $TimeoutSec) {
try {
$resp = Invoke-WebRequest -Uri $Url -UseBasicParsing -TimeoutSec 2 -ErrorAction Stop
if ($resp.StatusCode -eq 200) {
Write-Host " done" -ForegroundColor Cyan
Write-Success "$Label is ready"
return $true
}
} catch {
# Not ready yet — swallow the error
}
Write-Host "." -NoNewline
Start-Sleep -Seconds $IntervalSec
$elapsed += $IntervalSec
}
Write-Host ""
Write-Warn "$Label did not become ready in ${TimeoutSec}s — check logs:`n docker compose --project-directory `"$GovrixDir`" logs"
return $false
}
# =============================================================================
# USER MODE — Docker-only, no Rust/Node needed
# =============================================================================
function Install-User {
Write-Host ""
Write-Host "Govrix — Quick Install (Docker)" -ForegroundColor White -BackgroundColor DarkBlue
Write-Separator
Write-Host ""
Test-Docker
# Create install directory
if (-not (Test-Path $GovrixDir)) {
New-Item -ItemType Directory -Path $GovrixDir -Force | Out-Null
}
Write-Info "Install directory: $GovrixDir"
# Download docker-compose.yml (always re-download to get latest from repo)
$composeDest = Join-Path $GovrixDir "docker-compose.yml"
Write-Info "Downloading docker-compose.yml..."
try {
Invoke-WebRequest -Uri "$REPO_RAW_BASE/docker/docker-compose.production.yml" `
-OutFile $composeDest `
-UseBasicParsing
Write-Success "docker-compose.yml downloaded"
} catch {
Write-Fail "Failed to download docker-compose.yml: $_"
}
# Download database initialization script (always re-download for schema updates)
$initDest = Join-Path $GovrixDir "init-combined.sql"
Write-Info "Downloading database initialization script..."
try {
Invoke-WebRequest -Uri "$REPO_RAW_BASE/docker/init-combined.sql" `
-OutFile $initDest `
-UseBasicParsing
Write-Success "init-combined.sql downloaded"
} catch {
Write-Fail "Failed to download init-combined.sql: $_"
}
# Generate .env with secure random credentials
$envFile = Join-Path $GovrixDir ".env"
if (-not (Test-Path $envFile)) {
Write-Info "Generating .env with secure credentials..."
$dbPass = New-SecureHex -ByteCount 24
$apiKey = New-SecureHex -ByteCount 32
$timestamp = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")
$envContent = @"
# Govrix configuration — generated by install.ps1 $timestamp
# Edit this file to change ports, credentials, or retention settings.
POSTGRES_USER=govrix
POSTGRES_DB=govrix
POSTGRES_PASSWORD=$dbPass
GOVRIX_API_KEY=$apiKey
GOVRIX_DATABASE_URL=postgresql://govrix:${dbPass}@postgres:5432/govrix
GOVRIX_PROXY_PORT=4000
GOVRIX_API_PORT=4001
RUST_LOG=govrix_ai_oss_proxy=info,tower_http=warn
"@
Set-Content -Path $envFile -Value $envContent -Encoding UTF8
Write-Success ".env created"
} else {
Write-Success ".env already exists — keeping existing credentials"
}
# Pull and start
Write-Info "Pulling Docker images (first run takes 2-5 minutes)..."
docker compose --project-directory $GovrixDir pull --quiet
if ($LASTEXITCODE -ne 0) { Write-Fail "docker compose pull failed." }
Write-Success "Images ready"
Write-Info "Starting Govrix services..."
docker compose --project-directory $GovrixDir up -d
if ($LASTEXITCODE -ne 0) { Write-Fail "docker compose up failed." }
Write-Success "Services started"
# Health checks
Write-Host ""
Wait-Healthy -Url "http://localhost:4001/health" -Label "Govrix API" -TimeoutSec 90 | Out-Null
Wait-Healthy -Url "http://localhost:3000" -Label "Govrix Dashboard" -TimeoutSec 30 | Out-Null
# Read API key from .env (if present) for display
$apiKey = ""
if (Test-Path $envFile) {
$apiKeyLine = Select-String -Path $envFile -Pattern '^GOVRIX_API_KEY=' | Select-Object -First 1
if ($apiKeyLine) {
$apiKey = ($apiKeyLine.Line -split '=', 2)[1]
}
}
# Done — success summary
Write-Host ""
Write-Separator
Write-Host "Govrix is running!" -ForegroundColor Green
Write-Host ""
Write-Host " Dashboard: " -NoNewline; Write-Host "http://localhost:3000" -ForegroundColor Cyan
Write-Host " API: " -NoNewline; Write-Host "http://localhost:4001/health" -ForegroundColor Cyan
Write-Host " Metrics: " -NoNewline; Write-Host "http://localhost:9090/metrics" -ForegroundColor Cyan
if ($apiKey) {
Write-Host ""
Write-Host " API Key: " -NoNewline; Write-Host $apiKey -ForegroundColor Yellow
}
Write-Host ""
Write-Host " Point your agents at Govrix (one env var, no code changes):" -ForegroundColor White
Write-Host ""
Write-Host ' $env:OPENAI_BASE_URL = "http://localhost:4000/proxy/openai/v1"'
Write-Host ' $env:ANTHROPIC_BASE_URL = "http://localhost:4000/proxy/anthropic/v1"'
Write-Host ""
Write-Host " Manage:" -ForegroundColor White
Write-Host " docker compose --project-directory `"$GovrixDir`" logs -f"
Write-Host " docker compose --project-directory `"$GovrixDir`" down"
Write-Host " docker compose --project-directory `"$GovrixDir`" up -d"
Write-Host ""
Write-Host " Docs: $REPO_URL" -ForegroundColor White
Write-Separator
Write-Host ""
}
# =============================================================================
# DEV MODE — Full contributor setup
# =============================================================================
function Install-Dev {
Write-Host ""
Write-Host "Govrix — Developer Setup" -ForegroundColor White -BackgroundColor DarkBlue
Write-Separator
Write-Host ""
# Locate repo root — must be run from inside the cloned repo
$repoDir = $null
if (Test-Path (Join-Path (Get-Location) "Cargo.toml")) {
$cargoContent = Get-Content (Join-Path (Get-Location) "Cargo.toml") -Raw
if ($cargoContent -match 'govrix-ai-oss') {
$repoDir = (Get-Location).Path
}
}
if (-not $repoDir -and (Test-Path (Join-Path (Split-Path (Get-Location) -Parent) "Cargo.toml"))) {
$parentCargo = Get-Content (Join-Path (Split-Path (Get-Location) -Parent) "Cargo.toml") -Raw
if ($parentCargo -match 'govrix-ai-oss') {
$repoDir = Split-Path (Get-Location) -Parent
}
}
if (-not $repoDir) {
Write-Host ""
Write-Fail @"
-Dev mode must be run from the cloned govrix-ai-oss repo.
Clone it first:
git clone $REPO_URL
cd govrix-ai-oss
.\install.ps1 -Dev
"@
}
Write-Info "Repo root: $repoDir"
Set-Location $repoDir
Test-Docker
Test-OrInstallRust
Test-Node
Test-OrInstallPnpm
# Dashboard dependencies
Write-Info "Installing dashboard dependencies..."
Set-Location (Join-Path $repoDir "dashboard")
pnpm install --frozen-lockfile
Set-Location $repoDir
Write-Success "Dashboard dependencies installed"
# Build Rust workspace
Write-Info "Building Rust workspace (first build ~2-3 minutes)..."
$env:PATH += ";$env:USERPROFILE\.cargo\bin"
cargo build --workspace
if ($LASTEXITCODE -ne 0) { Write-Fail "cargo build failed." }
Write-Success "Rust workspace built"
# Run tests
Write-Info "Running tests..."
$testOutput = cargo test --workspace 2>&1
$testOutput | Where-Object { $_ -match '^test result|FAILED|error' } | Select-Object -First 20 | ForEach-Object { Write-Host $_ }
Write-Success "Tests complete"
# Start database
Write-Info "Starting database (TimescaleDB)..."
docker compose -f (Join-Path $repoDir "docker\docker-compose.yml") up -d postgres
Wait-Healthy -Url "http://localhost:4001/health" -Label "database" -TimeoutSec 30 | Out-Null
# Done
Write-Host ""
Write-Separator
Write-Host "Dev environment ready!" -ForegroundColor Green
Write-Host ""
Write-Host " make dev-proxy # Start proxy in watch mode (ports 4000, 4001)"
Write-Host " make dev-dashboard # Start React dashboard HMR (port 3000)"
Write-Host " make docker-up # Start full stack in Docker"
Write-Host " make test # Run all Rust tests"
Write-Host " make lint # Run clippy"
Write-Host " make help # All available commands"
Write-Host ""
Write-Host " Proxy: http://localhost:4000"
Write-Host " REST API: http://localhost:4001"
Write-Host " Dashboard: http://localhost:3000"
Write-Separator
Write-Host ""
}
# =============================================================================
# Entrypoint
# =============================================================================
try {
if ($Dev) {
Install-Dev
} else {
Install-User
}
} catch {
Write-Host ""
Write-Host "[govrix] Installation aborted: $($_.Exception.Message)" -ForegroundColor Red
Write-Host "[govrix] If the error persists, please open an issue: $REPO_URL/issues" -ForegroundColor Yellow
Write-Host ""
}