-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathinstall-docker.ps1
More file actions
697 lines (593 loc) · 23.7 KB
/
install-docker.ps1
File metadata and controls
697 lines (593 loc) · 23.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
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
# Rikune - Docker profile installer
# Requires: PowerShell 7+, Docker Desktop / Docker Engine, Node.js 22+
param(
[ValidateSet("static", "full", "hybrid")]
[string]$Profile = "static",
[Parameter(HelpMessage = "Persistent data root directory")]
[string]$DataRoot = "D:\Docker\rikune",
[Parameter(HelpMessage = "Project root directory")]
[string]$ProjectRoot = $PSScriptRoot,
[Parameter(HelpMessage = "Skip Docker image build")]
[switch]$SkipBuild,
[Parameter(HelpMessage = "Skip starting the Compose service after build")]
[switch]$SkipStart,
[Parameter(HelpMessage = "Delete and recreate the data root before installing")]
[switch]$ResetData,
[Parameter(HelpMessage = "Enable verbose output")]
[switch]$EnableVerbose,
[Parameter(HelpMessage = "HTTP proxy URL for npm and Docker build")]
[string]$HttpProxy,
[Parameter(HelpMessage = "HTTPS proxy URL for npm and Docker build")]
[string]$HttpsProxy,
[Parameter(HelpMessage = "Use Windows system proxy if available")]
[switch]$UseProxy,
[Parameter(HelpMessage = "Windows Host Agent endpoint for hybrid profile")]
[string]$HostAgentEndpoint,
[Parameter(HelpMessage = "Windows Host Agent API key for hybrid profile")]
[string]$HostAgentApiKey,
[Parameter(HelpMessage = "Windows Runtime Node API key for hybrid profile")]
[string]$RuntimeApiKey,
[ValidateSet("None", "Claude", "Copilot", "Codex", "Generic")]
[string]$ConfigureClient = "None",
[Parameter(HelpMessage = "Force guided prompts even when some parameters are provided")]
[switch]$Interactive
)
$ErrorActionPreference = "Stop"
$ColorPrimary = "Cyan"
$ColorSuccess = "Green"
$ColorWarning = "Yellow"
$ColorError = "Red"
$ColorInfo = "White"
$DefaultNoProxy = "localhost,127.0.0.1,deb.debian.org,security.debian.org,mirrors.aliyun.com,archive.ubuntu.com,security.ubuntu.com,aliyuncs.com"
$Profiles = @{
static = @{
Generator = "static"
Compose = "docker-compose.analyzer.yml"
Service = "analyzer"
Image = "rikune-analyzer:latest"
Container = "rikune-analyzer"
RuntimeMode = "disabled"
Description = "Static-only Docker analyzer"
}
full = @{
Generator = "full"
Compose = "docker-compose.yml"
Service = "mcp-server"
Image = "rikune:latest"
Container = "rikune"
RuntimeMode = "disabled"
Description = "Full Linux Docker analysis stack"
}
hybrid = @{
Generator = "hybrid"
Compose = "docker-compose.hybrid.yml"
Service = "analyzer"
Image = "rikune-analyzer:latest"
Container = "rikune-analyzer"
RuntimeMode = "remote-sandbox"
Description = "Linux Docker analyzer with remote Windows Sandbox runtime"
}
}
function Write-Header {
param([string]$Text)
Write-Host "`n==================================================" -ForegroundColor $ColorPrimary
Write-Host " $Text" -ForegroundColor $ColorPrimary
Write-Host "==================================================" -ForegroundColor $ColorPrimary
}
function Write-Step {
param([string]$Text)
Write-Host "`n[STEP] $Text" -ForegroundColor $ColorPrimary
Write-Host "-----------------------------------------" -ForegroundColor $ColorPrimary
}
function Write-Info {
param([string]$Text)
Write-Host " $Text" -ForegroundColor $ColorInfo
}
function Write-Success {
param([string]$Text)
Write-Host "[OK] " -ForegroundColor $ColorSuccess -NoNewline
Write-Host $Text -ForegroundColor $ColorSuccess
}
function Write-Warning-Message {
param([string]$Text)
Write-Host "[WARN] " -ForegroundColor $ColorWarning -NoNewline
Write-Host $Text -ForegroundColor $ColorWarning
}
function Write-Error-Message {
param([string]$Text)
Write-Host "[ERROR] " -ForegroundColor $ColorError -NoNewline
Write-Host $Text -ForegroundColor $ColorError
}
function Require-Command {
param(
[string]$Name,
[string]$InstallHint
)
if (-not (Get-Command $Name -ErrorAction SilentlyContinue)) {
Write-Error-Message "$Name not found"
if ($InstallHint) { Write-Host " $InstallHint" -ForegroundColor $ColorError }
exit 1
}
}
function Resolve-ComposeCommand {
try {
& docker compose version *> $null
if ($LASTEXITCODE -eq 0) {
return "docker"
}
} catch {
}
if (Get-Command docker-compose -ErrorAction SilentlyContinue) {
return "docker-compose"
}
return $null
}
function Invoke-Compose {
param([string[]]$Arguments)
if ($script:ComposeCommand -eq "docker") {
$cmdArgs = @("compose") + $Arguments
& docker @cmdArgs
} else {
& docker-compose @Arguments
}
}
function Convert-ProxyForDocker {
param([string]$Proxy)
if ([string]::IsNullOrWhiteSpace($Proxy)) { return "" }
return ($Proxy -replace "://127\.0\.0\.1:", "://host.docker.internal:" -replace "://localhost:", "://host.docker.internal:")
}
function Convert-EndpointForHostAgent {
param([string]$Endpoint)
if ([string]::IsNullOrWhiteSpace($Endpoint)) { return "" }
return ($Endpoint -replace "://host\.docker\.internal:", "://localhost:")
}
function Get-SystemProxy {
try {
$registryPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
$proxyEnable = Get-ItemProperty -Path $registryPath -Name "ProxyEnable" -ErrorAction SilentlyContinue
if ($proxyEnable.ProxyEnable -ne 1) { return $null }
$proxyServer = Get-ItemProperty -Path $registryPath -Name "ProxyServer" -ErrorAction SilentlyContinue
if (-not $proxyServer.ProxyServer) { return $null }
$value = $proxyServer.ProxyServer.ToString()
if ($value -match "=") {
$http = ($value -split ";") | Where-Object { $_ -like "http=*" } | Select-Object -First 1
if ($http) { return ($http -replace "^http=", "") }
}
return $value
} catch {
return $null
}
}
function ConvertTo-TomlString {
param([string]$Value)
if ($null -eq $Value) { return '""' }
$escaped = $Value.Replace('\', '\\').Replace('"', '\"')
return '"' + $escaped + '"'
}
function ConvertTo-TomlArray {
param([string[]]$Values)
return "[" + (($Values | ForEach-Object { ConvertTo-TomlString $_ }) -join ", ") + "]"
}
function Set-CodexMcpConfig {
param(
[string]$ConfigFile,
[hashtable]$ProfileConfig
)
$configDir = Split-Path -Parent $ConfigFile
if (-not (Test-Path $configDir)) {
New-Item -ItemType Directory -Path $configDir -Force | Out-Null
}
$mcpArgs = @("stdio")
$block = @"
[mcp_servers.rikune]
type = "stdio"
command = "rikune-agent"
startup_timeout_sec = 180
args = $(ConvertTo-TomlArray $mcpArgs)
[mcp_servers.rikune.env]
RIKUNE_DOCKER_CONTAINER = $(ConvertTo-TomlString $ProfileConfig.Container)
RIKUNE_ANALYZER_ENDPOINT = "http://localhost:18080"
"@
if ($ProfileConfig.RuntimeMode -eq "remote-sandbox") {
$agentHostEndpoint = Convert-EndpointForHostAgent $HostAgentEndpoint
$block += @"
RIKUNE_VM_ENDPOINT = $(ConvertTo-TomlString $agentHostEndpoint)
RUNTIME_HOST_AGENT_ENDPOINT = $(ConvertTo-TomlString $HostAgentEndpoint)
RUNTIME_HOST_AGENT_API_KEY = $(ConvertTo-TomlString $HostAgentApiKey)
RUNTIME_API_KEY = $(ConvertTo-TomlString $RuntimeApiKey)
"@
}
$content = ""
if (Test-Path $ConfigFile) {
$content = Get-Content -Path $ConfigFile -Raw
$content = [regex]::Replace($content, '(?ms)^\[mcp_servers\.rikune(?:\.env)?\]\r?\n.*?(?=^\[|\z)', '').TrimEnd()
}
if ([string]::IsNullOrWhiteSpace($content)) {
$block | Set-Content -Path $ConfigFile -Encoding UTF8
} else {
($content + "`r`n`r`n" + $block) | Set-Content -Path $ConfigFile -Encoding UTF8
}
}
function Test-HttpHealth {
param(
[string]$Uri,
[int]$TimeoutSec = 90
)
$deadline = (Get-Date).AddSeconds($TimeoutSec)
$lastError = $null
while ((Get-Date) -lt $deadline) {
try {
$healthParams = @{
Uri = $Uri
UseBasicParsing = $true
TimeoutSec = 5
}
if ((Get-Command Invoke-WebRequest).Parameters.ContainsKey("NoProxy")) {
$healthParams.NoProxy = $true
}
$response = Invoke-WebRequest @healthParams
if ($response.StatusCode -eq 200) {
return @{ Ok = $true; Error = $null }
}
$lastError = "HTTP status $($response.StatusCode)"
} catch {
$lastError = $_.Exception.Message
}
Start-Sleep -Seconds 2
}
return @{ Ok = $false; Error = $lastError }
}
function Write-EnvFile {
param(
[string]$Path,
[string]$Root,
[hashtable]$ProfileConfig,
[string]$BuildHttpProxy,
[string]$BuildHttpsProxy,
[string]$HybridEndpoint,
[string]$HybridHostKey,
[string]$HybridRuntimeKey
)
$rootForCompose = $Root -replace "\\", "/"
$lines = @(
"# Rikune Docker runtime environment - generated by install-docker.ps1",
"RIKUNE_DATA_ROOT=$rootForCompose",
"RIKUNE_BUILD_HTTP_PROXY=$BuildHttpProxy",
"RIKUNE_BUILD_HTTPS_PROXY=$BuildHttpsProxy",
"RIKUNE_BUILD_NO_PROXY=$DefaultNoProxy"
)
if ($ProfileConfig.RuntimeMode -eq "remote-sandbox") {
$lines += "RUNTIME_HOST_AGENT_ENDPOINT=$HybridEndpoint"
$lines += "RUNTIME_HOST_AGENT_API_KEY=$HybridHostKey"
$lines += "RUNTIME_API_KEY=$HybridRuntimeKey"
}
$lines | Set-Content -Path $Path -Encoding UTF8
}
function Configure-McpClient {
param(
[string]$Client,
[hashtable]$ProfileConfig
)
if ($Client -eq "None") { return }
$config = @{
mcpServers = @{
rikune = @{
command = "rikune-agent"
args = @("stdio")
env = @{
RIKUNE_DOCKER_CONTAINER = $ProfileConfig.Container
RIKUNE_ANALYZER_ENDPOINT = "http://localhost:18080"
}
timeout = 300000
}
}
}
if ($ProfileConfig.RuntimeMode -eq "remote-sandbox") {
$agentHostEndpoint = Convert-EndpointForHostAgent $HostAgentEndpoint
$config.mcpServers.rikune.env.RIKUNE_VM_ENDPOINT = $agentHostEndpoint
$config.mcpServers.rikune.env.RUNTIME_HOST_AGENT_ENDPOINT = $HostAgentEndpoint
$config.mcpServers.rikune.env.RUNTIME_HOST_AGENT_API_KEY = $HostAgentApiKey
$config.mcpServers.rikune.env.RUNTIME_API_KEY = $RuntimeApiKey
}
switch ($Client) {
"Claude" {
$configDir = Join-Path $env:APPDATA "Claude"
$configFile = Join-Path $configDir "claude_desktop_config.json"
}
"Copilot" {
$configDir = Join-Path $env:APPDATA "GitHub Copilot"
$configFile = Join-Path $configDir "mcp.json"
}
"Codex" {
$configDir = Join-Path $env:USERPROFILE ".codex"
$configFile = Join-Path $configDir "config.toml"
}
"Generic" {
$configDir = Join-Path $DataRoot "config"
$configFile = Join-Path $configDir "mcp-client-config.json"
}
}
if ($Client -eq "Codex") {
Set-CodexMcpConfig -ConfigFile $configFile -ProfileConfig $ProfileConfig
} else {
if (-not (Test-Path $configDir)) {
New-Item -ItemType Directory -Path $configDir -Force | Out-Null
}
$config | ConvertTo-Json -Depth 10 | Set-Content -Path $configFile -Encoding UTF8
}
Write-Success "MCP client config written: $configFile"
}
function Read-DefaultString {
param(
[string]$Prompt,
[string]$DefaultValue
)
$value = Read-Host "$Prompt [$DefaultValue]"
if ([string]::IsNullOrWhiteSpace($value)) {
return $DefaultValue
}
return $value
}
function Read-YesNo {
param(
[string]$Prompt,
[bool]$DefaultValue = $false
)
$suffix = if ($DefaultValue) { "Y/n" } else { "y/N" }
$value = Read-Host "$Prompt ($suffix)"
if ([string]::IsNullOrWhiteSpace($value)) {
return $DefaultValue
}
return ($value -eq "y" -or $value -eq "Y")
}
function Read-Profile {
Write-Host ""
Write-Host "Select deployment profile:" -ForegroundColor $ColorPrimary
Write-Host " [1] static - safe default, static/offline analyzer only" -ForegroundColor $ColorInfo
Write-Host " [2] hybrid - Docker analyzer + Windows Host Agent / Sandbox" -ForegroundColor $ColorInfo
Write-Host " [3] full - heavier all-in-one Linux toolchain image" -ForegroundColor $ColorInfo
$choice = Read-Host "Select (default: 1)"
switch ($choice) {
"2" { return "hybrid" }
"3" { return "full" }
default { return "static" }
}
}
function Read-ClientChoice {
Write-Host ""
Write-Host "Configure an MCP client now?" -ForegroundColor $ColorPrimary
Write-Host " [0] Skip" -ForegroundColor $ColorInfo
Write-Host " [1] Claude Desktop" -ForegroundColor $ColorInfo
Write-Host " [2] GitHub Copilot" -ForegroundColor $ColorInfo
Write-Host " [3] Codex" -ForegroundColor $ColorInfo
Write-Host " [4] Generic file under DataRoot/config" -ForegroundColor $ColorInfo
$choice = Read-Host "Select (default: 0)"
switch ($choice) {
"1" { return "Claude" }
"2" { return "Copilot" }
"3" { return "Codex" }
"4" { return "Generic" }
default { return "None" }
}
}
try { Clear-Host } catch { }
Write-Header "Rikune Docker Installer"
$ProjectRoot = (Resolve-Path $ProjectRoot).Path
$PromptMode = $Interactive -or ($PSBoundParameters.Count -eq 0)
if ($PromptMode) {
Write-Host "Guided mode is active. Press Enter to accept defaults." -ForegroundColor $ColorInfo
$Profile = Read-Profile
$DataRoot = Read-DefaultString "Persistent data root" $DataRoot
$ResetData = Read-YesNo "Delete and recreate the data root" $false
if (Read-YesNo "Configure build proxy" $false) {
$detectedProxy = Get-SystemProxy
if ($detectedProxy) {
if (-not ($detectedProxy -match "^\w+://")) { $detectedProxy = "http://$detectedProxy" }
Write-Info "Detected Windows proxy: $detectedProxy"
$HttpProxy = Read-DefaultString "HTTP proxy" $detectedProxy
} else {
$HttpProxy = Read-DefaultString "HTTP proxy" "http://127.0.0.1:7890"
}
$HttpsProxy = Read-DefaultString "HTTPS proxy" $HttpProxy
}
if ($Profile -eq "hybrid") {
$HostAgentEndpoint = Read-DefaultString "Windows Host Agent endpoint" "http://192.168.1.10:18082"
$HostAgentApiKey = Read-Host "Windows Host Agent API key"
$RuntimeApiKey = Read-DefaultString "Runtime Node API key" $HostAgentApiKey
}
$SkipBuild = Read-YesNo "Skip Docker image build" $false
$SkipStart = Read-YesNo "Skip starting the service" $false
$ConfigureClient = Read-ClientChoice
}
$profileConfig = $Profiles[$Profile]
$composePath = Join-Path $ProjectRoot $profileConfig.Compose
$envFile = Join-Path $ProjectRoot ".docker-runtime.env"
Write-Info "Profile: $Profile - $($profileConfig.Description)"
Write-Info "Project root: $ProjectRoot"
Write-Info "Data root: $DataRoot"
Write-Step "Checking prerequisites"
Require-Command "docker" "Install Docker Desktop: https://www.docker.com/products/docker-desktop/"
Require-Command "node" "Install Node.js 22+: https://nodejs.org/"
Require-Command "npm" "Install npm with Node.js 22+"
try {
& docker info *> $null
if ($LASTEXITCODE -ne 0) { throw "docker info failed" }
Write-Success "Docker daemon is running"
} catch {
Write-Error-Message "Docker is not running. Start Docker Desktop and retry."
exit 1
}
$script:ComposeCommand = Resolve-ComposeCommand
if (-not $script:ComposeCommand) {
Write-Error-Message "Docker Compose was not found"
exit 1
}
Write-Success "Docker Compose available: $(if ($script:ComposeCommand -eq 'docker') { 'docker compose' } else { 'docker-compose' })"
Write-Success "Node.js: $((node --version).Trim())"
Write-Success "npm: $((npm --version).Trim())"
Write-Step "Resolving proxy and runtime settings"
if ($UseProxy -and [string]::IsNullOrWhiteSpace($HttpProxy) -and [string]::IsNullOrWhiteSpace($HttpsProxy)) {
$systemProxy = Get-SystemProxy
if ($systemProxy) {
if (-not ($systemProxy -match "^\w+://")) { $systemProxy = "http://$systemProxy" }
$HttpProxy = $systemProxy
$HttpsProxy = $systemProxy
Write-Success "Using Windows system proxy: $systemProxy"
} else {
Write-Warning-Message "UseProxy was set, but no Windows system proxy was detected"
}
}
if ([string]::IsNullOrWhiteSpace($HttpsProxy)) { $HttpsProxy = $HttpProxy }
$buildHttpProxy = Convert-ProxyForDocker $HttpProxy
$buildHttpsProxy = Convert-ProxyForDocker $HttpsProxy
if ([string]::IsNullOrWhiteSpace($buildHttpProxy) -and [string]::IsNullOrWhiteSpace($buildHttpsProxy)) {
Write-Info "Docker build proxy args will be cleared to avoid inherited localhost proxy failures"
} else {
Write-Info "Docker build HTTP proxy: $buildHttpProxy"
Write-Info "Docker build HTTPS proxy: $buildHttpsProxy"
}
if (-not [string]::IsNullOrWhiteSpace($HttpProxy) -or -not [string]::IsNullOrWhiteSpace($HttpsProxy)) {
if ([string]::IsNullOrWhiteSpace($HttpsProxy)) { $HttpsProxy = $HttpProxy }
if ([string]::IsNullOrWhiteSpace($HttpProxy)) { $HttpProxy = $HttpsProxy }
$env:HTTP_PROXY = $HttpProxy
$env:http_proxy = $HttpProxy
$env:HTTPS_PROXY = $HttpsProxy
$env:https_proxy = $HttpsProxy
$env:NO_PROXY = $DefaultNoProxy
$env:no_proxy = $DefaultNoProxy
Write-Info "Process proxy env set for npm and Docker CLI: $HttpsProxy"
}
if ($Profile -eq "hybrid") {
if ([string]::IsNullOrWhiteSpace($HostAgentEndpoint)) { $HostAgentEndpoint = $env:RUNTIME_HOST_AGENT_ENDPOINT }
if ([string]::IsNullOrWhiteSpace($HostAgentApiKey)) { $HostAgentApiKey = $env:RUNTIME_HOST_AGENT_API_KEY }
if ([string]::IsNullOrWhiteSpace($HostAgentApiKey)) { $HostAgentApiKey = $env:HOST_AGENT_API_KEY }
if ([string]::IsNullOrWhiteSpace($RuntimeApiKey)) { $RuntimeApiKey = $env:RUNTIME_API_KEY }
if ([string]::IsNullOrWhiteSpace($RuntimeApiKey)) { $RuntimeApiKey = $HostAgentApiKey }
if ([string]::IsNullOrWhiteSpace($HostAgentEndpoint) -or [string]::IsNullOrWhiteSpace($HostAgentApiKey)) {
Write-Error-Message "Hybrid profile requires -HostAgentEndpoint and -HostAgentApiKey"
Write-Info "Example: .\install-docker.ps1 -Profile hybrid -HostAgentEndpoint http://192.168.1.10:18082 -HostAgentApiKey <key>"
exit 1
}
Write-Success "Hybrid Host Agent endpoint: $HostAgentEndpoint"
}
Write-Step "Preparing persistent storage"
if (-not [System.IO.Path]::IsPathRooted($DataRoot)) {
$DataRoot = Join-Path $ProjectRoot $DataRoot
}
if ($ResetData -and (Test-Path $DataRoot)) {
$resolvedDataRoot = (Resolve-Path $DataRoot).Path
$root = [System.IO.Path]::GetPathRoot($resolvedDataRoot)
if ($resolvedDataRoot -eq $root) {
Write-Error-Message "Refusing to delete drive root: $resolvedDataRoot"
exit 1
}
Write-Warning-Message "Deleting data root because -ResetData was specified: $resolvedDataRoot"
Remove-Item -LiteralPath $resolvedDataRoot -Recurse -Force
}
$directories = @("samples", "workspaces", "data", "cache", "logs", "storage", "ghidra-projects", "ghidra-logs", "qiling-rootfs", "config")
foreach ($dir in $directories) {
$path = Join-Path $DataRoot $dir
if (-not (Test-Path $path)) {
New-Item -ItemType Directory -Path $path -Force | Out-Null
if ($EnableVerbose) { Write-Info "Created: $path" }
}
}
Write-Success "Persistent directories ready"
Write-EnvFile `
-Path $envFile `
-Root $DataRoot `
-ProfileConfig $profileConfig `
-BuildHttpProxy $buildHttpProxy `
-BuildHttpsProxy $buildHttpsProxy `
-HybridEndpoint $HostAgentEndpoint `
-HybridHostKey $HostAgentApiKey `
-HybridRuntimeKey $RuntimeApiKey
Write-Success "Compose env file: $envFile"
Write-Step "Building project and generating Docker profile"
Push-Location $ProjectRoot
try {
Write-Info "Installing npm dependencies..."
& npm install
if ($LASTEXITCODE -ne 0) { throw "npm install failed" }
Write-Info "Building TypeScript and workspace packages..."
& npm run build
if ($LASTEXITCODE -ne 0) { throw "npm run build failed" }
Write-Info "Generating Docker files for profile '$Profile'..."
& node scripts/generate-docker.mjs "--profile=$($profileConfig.Generator)"
if ($LASTEXITCODE -ne 0) { throw "Docker profile generation failed" }
if (-not (Test-Path $composePath)) {
throw "Expected Compose file not found: $composePath"
}
Write-Success "Generated $($profileConfig.Compose)"
} catch {
Write-Error-Message $_.Exception.Message
exit 1
} finally {
Pop-Location
}
Write-Step "Docker Compose"
Push-Location $ProjectRoot
try {
$baseArgs = @("--env-file", ".docker-runtime.env", "-f", $profileConfig.Compose)
if ($SkipBuild) {
Write-Warning-Message "Skipping Docker build"
} else {
Write-Info "Building image: $($profileConfig.Image)"
Invoke-Compose ($baseArgs + @("build", $profileConfig.Service))
if ($LASTEXITCODE -ne 0) { throw "Docker Compose build failed" }
Write-Success "Docker image built: $($profileConfig.Image)"
}
if ($SkipStart) {
Write-Warning-Message "Skipping service start"
} else {
Write-Info "Starting service: $($profileConfig.Service)"
Invoke-Compose ($baseArgs + @("up", "-d", $profileConfig.Service))
if ($LASTEXITCODE -ne 0) { throw "Docker Compose up failed" }
Write-Success "Service started: $($profileConfig.Container)"
}
} catch {
Write-Error-Message $_.Exception.Message
exit 1
} finally {
Pop-Location
}
Write-Step "Health check"
if ($SkipStart) {
Write-Warning-Message "Health check skipped because -SkipStart was specified"
} else {
Write-Info "Waiting for HTTP API to become ready..."
$health = Test-HttpHealth -Uri "http://localhost:18080/api/v1/health" -TimeoutSec 90
if ($health.Ok) {
Write-Success "HTTP API health check passed"
} else {
Write-Warning-Message "HTTP API health check failed: $($health.Error)"
Write-Info "Check logs with: docker logs $($profileConfig.Container)"
}
}
Configure-McpClient -Client $ConfigureClient -ProfileConfig $profileConfig
$installInfo = @{
InstallDate = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
Profile = $Profile
DataRoot = $DataRoot
ProjectRoot = $ProjectRoot
ComposeFile = $profileConfig.Compose
Service = $profileConfig.Service
Container = $profileConfig.Container
Image = $profileConfig.Image
RuntimeMode = $profileConfig.RuntimeMode
ComposeEnvFile = $envFile
}
$installInfo | ConvertTo-Json -Depth 5 | Set-Content -Path (Join-Path $DataRoot "install-info.json") -Encoding UTF8
Write-Header "Docker Install Complete"
Write-Host "Profile: $Profile" -ForegroundColor $ColorSuccess
Write-Host "Image: $($profileConfig.Image)" -ForegroundColor $ColorSuccess
Write-Host "Container: $($profileConfig.Container)" -ForegroundColor $ColorSuccess
Write-Host "Compose file: $($profileConfig.Compose)" -ForegroundColor $ColorSuccess
Write-Host "Data root: $DataRoot" -ForegroundColor $ColorSuccess
Write-Host ""
Write-Host "Useful commands:" -ForegroundColor $ColorPrimary
Write-Host " docker compose --env-file .docker-runtime.env -f $($profileConfig.Compose) ps"
Write-Host " docker compose --env-file .docker-runtime.env -f $($profileConfig.Compose) logs -f $($profileConfig.Service)"
Write-Host " docker compose --env-file .docker-runtime.env -f $($profileConfig.Compose) down"
Write-Host ""
Write-Host "Dashboard: http://localhost:18080/dashboard" -ForegroundColor $ColorPrimary