forked from morphik-org/morphik-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_docker.ps1
More file actions
530 lines (475 loc) · 19.2 KB
/
Copy pathinstall_docker.ps1
File metadata and controls
530 lines (475 loc) · 19.2 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
<#
Morphik Core - Docker installer for Windows PowerShell.
This mirrors install_docker.sh (macOS/Linux) and sets up a Docker-based deployment.
Usage (PowerShell):
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
./install_docker.ps1
Requirements:
- Docker Desktop running (Compose V2 included)
- Internet connectivity to pull the image or fetch config files
#>
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$script:EmbeddingSelection = $null
function Write-Info($msg) { Write-Host "[INFO] $msg" -ForegroundColor Cyan }
function Write-Step($msg) { Write-Host "[STEP] $msg" -ForegroundColor Yellow }
function Write-Ok($msg) { Write-Host "[OK] $msg" -ForegroundColor Green }
function Write-Err($msg) { Write-Host "[ERROR] $msg" -ForegroundColor Red }
$REPO_URL = "https://raw.githubusercontent.com/morphik-org/morphik-core/main"
$REPO_ZIP = "https://codeload.github.com/morphik-org/morphik-core/zip/refs/heads/main"
$COMPOSE = "docker-compose.run.yml"
$IMAGE = "ghcr.io/morphik-org/morphik-core:latest"
$DIRECT_URL = "https://www.morphik.ai/docs/getting-started#self-host-direct-installation-advanced"
function Assert-Docker {
if (-not (Get-Command docker -ErrorAction SilentlyContinue)) {
Write-Err "Docker is required. Please install Docker Desktop and re-run."
throw "Docker not found"
}
cmd.exe /c "docker info >NUL 2>&1"
if ($LASTEXITCODE -ne 0) {
Write-Err "Docker is installed but not running. Start Docker Desktop and retry."
throw "Docker not running"
}
try { docker compose version | Out-Null } catch {
Write-Err "Docker Compose V2 is required. Please update Docker Desktop."
throw "Compose V2 missing"
}
}
function New-RandomHex($bytes) {
$buffer = New-Object byte[] $bytes
$rng = [System.Security.Cryptography.RandomNumberGenerator]::Create()
try {
$rng.GetBytes($buffer)
} finally {
$rng.Dispose()
}
($buffer | ForEach-Object { $_.ToString('x2') }) -join ''
}
function Download-File($url, $outPath) {
Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $outPath -ErrorAction Stop
}
function Set-EnvValue {
param([Parameter(Mandatory)] [string] $Key,
[Parameter(Mandatory)] [string] $Value)
if (-not (Test-Path '.env')) {
Add-Content -Path .env -Value "$Key=$Value"
return
}
$lines = Get-Content .env
$match = $lines | Select-String ("^{0}=" -f [Regex]::Escape($Key)) | Select-Object -First 1
if ($match) {
$index = $match.LineNumber - 1
$lines[$index] = "$Key=$Value"
Set-Content -Path .env -Value $lines
} else {
Add-Content -Path .env -Value "$Key=$Value"
}
}
function Add-ComposeProfile {
param([Parameter(Mandatory)] [string] $Profile)
if (-not (Test-Path '.env')) {
Add-Content -Path .env -Value "COMPOSE_PROFILES=$Profile"
return
}
$lines = Get-Content .env
$match = $lines | Select-String '^COMPOSE_PROFILES=' | Select-Object -First 1
if ($match) {
$index = $match.LineNumber - 1
$value = $lines[$index].Substring("COMPOSE_PROFILES=".Length)
$profiles = $value -split '\s*,\s*' | Where-Object { $_ }
if ($profiles -notcontains $Profile) {
if ($value.Trim()) {
$value = "$value,$Profile"
} else {
$value = $Profile
}
$lines[$index] = "COMPOSE_PROFILES=$value"
Set-Content -Path .env -Value $lines
}
} else {
Add-Content -Path .env -Value "COMPOSE_PROFILES=$Profile"
}
}
function Copy-UiFromImage {
param([Parameter(Mandatory)] [string] $Image)
$cid = ''
try { $cid = docker create $Image } catch { $cid = '' }
if (-not $cid) { return $false }
try {
if (-not (Test-Path "ee")) { New-Item -ItemType Directory -Path "ee" | Out-Null }
if (Test-Path "ee/ui-component") { Remove-Item -Recurse -Force "ee/ui-component" }
docker cp "$cid`:/app/ee/ui-component" "ee/ui-component" | Out-Null
return (Test-Path "ee/ui-component")
} catch {
return $false
} finally {
docker rm $cid | Out-Null
}
}
function Download-UiFromRepo {
param([Parameter(Mandatory)] [string] $ZipUrl)
$tmpRoot = Join-Path ([IO.Path]::GetTempPath()) ([Guid]::NewGuid().ToString())
New-Item -ItemType Directory -Path $tmpRoot | Out-Null
$zipPath = Join-Path $tmpRoot "morphik-ui.zip"
try {
Invoke-WebRequest -UseBasicParsing -Uri $ZipUrl -OutFile $zipPath -ErrorAction Stop
Expand-Archive -LiteralPath $zipPath -DestinationPath $tmpRoot -Force
$folder = Get-ChildItem $tmpRoot | Where-Object { $_.PSIsContainer -and $_.Name -like "morphik-org-morphik-core*" } | Select-Object -First 1
if (-not $folder) { return $false }
$source = Join-Path $folder.FullName "ee/ui-component"
if (-not (Test-Path $source)) { return $false }
if (-not (Test-Path "ee")) { New-Item -ItemType Directory -Path "ee" | Out-Null }
if (Test-Path "ee/ui-component") { Remove-Item -Recurse -Force "ee/ui-component" }
Copy-Item -Path $source -Destination "ee" -Recurse -Force
return $true
} catch {
return $false
} finally {
Remove-Item -Recurse -Force $tmpRoot -ErrorAction SilentlyContinue
}
}
function Ensure-ComposeFile {
Write-Step "Downloading the Docker Compose configuration file..."
try {
Download-File "$REPO_URL/$COMPOSE" $COMPOSE
Write-Ok "Downloaded '$COMPOSE'."
} catch {
Write-Err "Failed to download '$COMPOSE'. Check connectivity and try again."
throw
}
}
function Ensure-EnvFile {
Write-Step "Creating '.env' file for secrets..."
$jwt = "your-super-secret-key-$(New-RandomHex 16)"
$envContent = @(
"# Your OpenAI API key (optional - you can configure other providers in morphik.toml)",
"OPENAI_API_KEY=",
"",
"# A secret key for signing JWTs. A random one is generated for you.",
"JWT_SECRET_KEY=$jwt",
"",
"# Local URI password for secure URI generation (required for creating connection URIs)",
"LOCAL_URI_PASSWORD="
) -join [Environment]::NewLine
Set-Content -Path .env -Value $envContent
$openai = Read-Host "Enter your OpenAI API Key (or press Enter to skip)"
if ($openai) {
(Get-Content .env -Raw) -replace "OPENAI_API_KEY=", "OPENAI_API_KEY=$openai" |
Set-Content .env
Write-Ok "Configured OPENAI_API_KEY in .env"
} else {
Write-Info "No OpenAI API key provided. You can configure providers in morphik.toml later."
Write-Info "Embeddings power ingestion, search, and querying in Morphik. Choose an alternative provider to continue."
while (-not $script:EmbeddingSelection) {
Write-Host ""
Write-Host "Choose an embedding provider:"
Write-Host " 1) Lemonade (download at https://lemonade-server.ai/)"
Write-Host " 2) Ollama (download at https://ollama.com/)"
$choice = Read-Host "Enter 1 or 2"
if ([string]::IsNullOrWhiteSpace($choice)) { $choice = '2' }
switch ($choice) {
'1' {
$script:EmbeddingSelection = [pscustomobject]@{ Model = 'lemonade_embedding'; Label = 'Lemonade embeddings' }
}
'2' {
$script:EmbeddingSelection = [pscustomobject]@{ Model = 'ollama_embedding'; Label = 'Ollama embeddings' }
}
default {
Write-Step "Please enter 1 or 2."
}
}
}
Write-Info ("Embeddings will be configured to use {0} with 768 dimensions." -f $script:EmbeddingSelection.Label)
if ($script:EmbeddingSelection.Model -eq 'lemonade_embedding') {
Write-Step "Ensure the Lemonade SDK is installed and running (you'll see an installer prompt later in this script)."
}
}
}
function Update-EmbeddingConfig {
param(
[Parameter(Mandatory)] [string] $Model,
[Parameter(Mandatory)] [string] $Label
)
if (-not (Test-Path 'morphik.toml')) {
Write-Step "morphik.toml not found. Skipping embedding configuration update."
return
}
Write-Step ("Configuring morphik.toml to use {0} (768 dimensions)..." -f $Label)
$lines = Get-Content 'morphik.toml'
$inEmbedding = $false
for ($i = 0; $i -lt $lines.Length; $i++) {
$line = $lines[$i]
if ($line -match '^\s*\[embedding\]\s*$') { $inEmbedding = $true; continue }
if ($inEmbedding -and $line -match '^\s*\[') { $inEmbedding = $false }
if (-not $inEmbedding) { continue }
if ($line -match '^\s*model\s*=\s*"([^"]*)"(.*)') {
$comment = $Matches[2]
$lines[$i] = 'model = "{0}"{1}' -f $Model, $comment
} elseif ($line -match '^\s*dimensions\s*=\s*\d+(.*)') {
$suffix = $Matches[1]
$lines[$i] = "dimensions = 768$suffix"
}
}
Set-Content -Path 'morphik.toml' -Value $lines
}
function Try-Extract-Config {
Write-Step "Pulling Docker image (this may take several minutes)..."
$pulled = $true
try {
# Use cmd to ensure proper progress display in PowerShell
cmd /c "docker pull $IMAGE"
if ($LASTEXITCODE -eq 0) {
$pulled = $true
Write-Ok "Docker image pulled successfully."
} else {
$pulled = $false
Write-Err "Docker pull failed with exit code $LASTEXITCODE"
}
} catch {
Write-Err "Failed to pull Docker image: $($_.Exception.Message)"
$pulled = $false
}
if ($pulled) {
Write-Ok "Docker image is available. Extracting default 'morphik.toml'..."
$content = ''
try { $content = docker run --rm $IMAGE cat /app/morphik.toml.default }
catch { $content = '' }
if ($content) {
Set-Content -Path morphik.toml -Value $content
if ((Test-Path morphik.toml) -and ((Get-Item morphik.toml).Length -gt 0)) {
Write-Ok "Extracted configuration from Docker image."
return
}
}
Write-Info "Trying alternative extraction method (docker cp)..."
$cid = ''
try { $cid = docker create $IMAGE } catch { $cid = '' }
if ($cid) {
try {
docker cp "$cid`:/app/morphik.toml.default" morphik.toml | Out-Null
} catch { }
try { docker rm $cid | Out-Null } catch { }
if ((Test-Path morphik.toml) -and ((Get-Item morphik.toml).Length -gt 0)) {
Write-Ok "Extracted configuration using docker cp."
return
}
}
} else {
Write-Info "Failed to pull image. Will download configuration from repository instead."
}
Write-Step "Downloading configuration from repository..."
$downloaded = $false
try {
Download-File "$REPO_URL/morphik.docker.toml" "morphik.toml"
$downloaded = $true
Write-Ok "Downloaded Docker-specific configuration."
} catch {
try {
Download-File "$REPO_URL/morphik.toml" "morphik.toml"
$downloaded = $true
Write-Info "Downloaded standard morphik.toml (may need Docker adjustments)."
} catch {
Write-Err "Could not obtain a configuration file."
throw
}
}
}
function Update-AuthBypassOrPassword {
Write-Host ""; Write-Info "Setting up authentication for your Morphik deployment:"
Write-Info " • For external access, set a LOCAL_URI_PASSWORD."
Write-Info " • For local-only access, press Enter to enable bypass_auth_mode."
$password = Read-Host "Enter a secure LOCAL_URI_PASSWORD (or press Enter to skip)"
if ([string]::IsNullOrWhiteSpace($password)) {
Write-Info "No password provided - enabling authentication bypass (bypass_auth_mode=true)."
$content = Get-Content morphik.toml -Raw
$content = $content -replace '(?m)^bypass_auth_mode\s*=\s*false', 'bypass_auth_mode = true'
Set-Content morphik.toml -Value $content
} else {
Write-Ok "LOCAL_URI_PASSWORD set - keeping production mode (bypass_auth_mode=false)."
(Get-Content .env -Raw) -replace 'LOCAL_URI_PASSWORD=', "LOCAL_URI_PASSWORD=$password" |
Set-Content .env
}
}
function Update-GPU-Options {
Write-Host ""; Write-Info "Multimodal embeddings can use GPU for best accuracy."
$gpu = Read-Host "Do you have a GPU available for Morphik to use? (y/N)"
if ($gpu -notin @('y','Y')) {
Write-Info "Disabling multimodal embeddings and reranking (CPU-only)."
$cfg = Get-Content morphik.toml -Raw
$cfg = $cfg -replace '(?m)^enable_colpali\s*=\s*true', 'enable_colpali = false'
$cfg = $cfg -replace '(?m)^use_reranker\s*=\s*.*', 'use_reranker = false'
Set-Content morphik.toml -Value $cfg
Write-Ok "Configuration updated for CPU-only operation."
} else {
Write-Ok "GPU selected. Multimodal embeddings will remain enabled."
}
}
function Enable-Config-Mount {
Write-Step "Enabling configuration mounting in '$COMPOSE'..."
$composeContent = Get-Content $COMPOSE -Raw
$composeContent = $composeContent -replace '#\s*-\s*\./morphik.toml:/app/morphik.toml:ro',
'- ./morphik.toml:/app/morphik.toml:ro'
[System.IO.File]::WriteAllText($COMPOSE, $composeContent, (New-Object System.Text.UTF8Encoding($false)))
}
function Get-ApiPortFromToml {
$lines = Get-Content morphik.toml -ErrorAction Stop
$inApi = $false
$port = $null
foreach ($line in $lines) {
if ($line -match '^\s*\[api\]\s*$') { $inApi = $true; continue }
if ($inApi -and $line -match '^\s*\[') { break }
if ($inApi -and $line -match '^\s*port\s*=\s*"?(\d+)"?') {
$port = $Matches[1]; break
}
}
if (-not $port) { $port = '8000' }
return $port
}
function Update-Port-Mapping($apiPort) {
$composeContent = Get-Content $COMPOSE -Raw
$composeContent = $composeContent -replace '"8000:8000"', '"{0}:{0}"' -f $apiPort
[System.IO.File]::WriteAllText($COMPOSE, $composeContent, (New-Object System.Text.UTF8Encoding($false)))
}
function Maybe-Install-UI($apiPort) {
Write-Host ""; Write-Info "Morphik includes an optional Admin UI."
$ans = Read-Host "Would you like to install the Admin UI? (y/N)"
if ($ans -in @('y','Y')) {
Write-Step "Extracting UI component files from Docker image..."
$installed = Copy-UiFromImage -Image $IMAGE
if (-not $installed) {
Write-Step "Falling back to repository download..."
$installed = Download-UiFromRepo -ZipUrl $REPO_ZIP
}
if ($installed -and (Test-Path "ee/ui-component")) {
Write-Ok "UI component downloaded successfully."
Set-EnvValue -Key "UI_INSTALLED" -Value "true"
Add-ComposeProfile -Profile "ui"
$composeContent = Get-Content $COMPOSE -Raw
$composeContent = $composeContent -replace 'NEXT_PUBLIC_API_URL=http://localhost:8000',
('NEXT_PUBLIC_API_URL=http://localhost:{0}' -f $apiPort)
[System.IO.File]::WriteAllText($COMPOSE, $composeContent, (New-Object System.Text.UTF8Encoding($false)))
return $true
} else {
Write-Err "Failed to download UI component. Continuing without UI."
}
}
return $false
}
function Start-Stack($apiPort, $ui) {
Write-Step "Starting the Morphik stack... (first run can take a few minutes)"
$args = @('-f', $COMPOSE)
if ($ui) { $args += @('--profile','ui') }
docker compose @args up -d
Write-Ok "Morphik has been started!"
Write-Info ("Health check: http://localhost:{0}/health" -f $apiPort)
Write-Info ("API docs: http://localhost:{0}/docs" -f $apiPort)
Write-Info ("Main API: http://localhost:{0}" -f $apiPort)
if ($ui) {
Write-Info "Admin UI: http://localhost:3003"
}
# Create convenience startup script for Windows
$start = @(
"Set-StrictMode -Version Latest",
"`$ErrorActionPreference = 'Stop'",
"",
'function Write-Info($msg) { Write-Host "[INFO] $msg" -ForegroundColor Cyan }',
'function Write-Warn($msg) { Write-Host "[WARN] $msg" -ForegroundColor Yellow }',
"",
"`$apiPortVar = `"$apiPort`"",
"# Read desired port from morphik.toml if available",
"`$desired = `$apiPortVar",
"if (Test-Path 'morphik.toml') {",
" `$lines = Get-Content morphik.toml",
" `$inApi = `$false; `$p = `$null",
" foreach (`$l in `$lines) {",
" if (`$l -match '^\\s*\\[api\\]\\s*`$') { `$inApi = `$true; continue }",
" if (`$inApi -and `$l -match '^\\s*\\[') { break }",
" if (`$inApi -and `$l -match '^\\s*port\\s*=\\s*`"?(\\d+)`"?') {",
" `$p = `$Matches[1]; break } }",
" if (`$p) { `$desired = `$p }",
"}",
"",
"# Update port mapping in compose file if needed",
"`$compose = Get-Content 'docker-compose.run.yml' -Raw",
"if (`$compose -match '`"(\\d+):(\\d+)`"') {",
" `$current = `$Matches[1]",
" if (`$current -ne `$desired) {",
" `$compose = `$compose -replace `"`$(`$current`):`$(`$current`)`", `"`$(`$desired`):`$(`$desired`)`"",
" Set-Content 'docker-compose.run.yml' -Value `$compose } }",
"",
"# Warn if multimodal embeddings disabled",
"if (Test-Path 'morphik.toml') {",
" `$cfg = Get-Content morphik.toml -Raw",
" if (`$cfg -match '(?m)^enable_colpali\\s*=\\s*false') {",
" Write-Warn 'Multimodal embeddings are disabled. Enable in morphik.toml if you have a GPU.' } }",
"",
"# Include UI profile if installed",
"`$ui = `$false",
"if (Test-Path '.env') {",
" `$envText = Get-Content .env -Raw",
" if (`$envText -match 'UI_INSTALLED=true') { `$ui = `$true } }",
"",
"`$args = @('-f','docker-compose.run.yml')",
"if (`$ui) { `$args += @('--profile','ui') }",
"docker compose @args up -d",
"Write-Host `"Morphik is running on http://localhost:`$(`$desired)`""
) -join [Environment]::NewLine
Set-Content -Path 'start-morphik.ps1' -Value $start }
$stop = @(
"Set-StrictMode -Version Latest",
"`$ErrorActionPreference = 'Stop'",
"",
"if (-not (Test-Path 'docker-compose.run.yml')) {",
" Write-Error 'docker-compose.run.yml not found. Run this script from your Morphik install directory.'",
"}",
"",
"`$profiles = @()",
"if (Test-Path '.env') {",
" `$envLines = Get-Content .env",
" `$match = `$envLines | Select-String '^COMPOSE_PROFILES=' | Select-Object -First 1",
" if (`$match) {",
" `$value = `$envLines[`$match.LineNumber - 1].Split('=')[1]",
" `$value.Split(',') | ForEach-Object {",
" `$p = `$_.Trim()",
" if (`$p) { `$profiles += @('--profile', `$p) }",
" }",
" } elseif (`$envLines | Select-String 'UI_INSTALLED=true') {",
" `$profiles += @('--profile','ui')",
" }",
"}",
"",
"`$args = @('-f','docker-compose.run.yml') + `$profiles + @('down','--volumes','--remove-orphans')",
"docker compose @args",
"Write-Host 'Morphik services stopped and cleaned up.'"
) -join [Environment]::NewLine
Set-Content -Path 'stop-morphik.ps1' -Value $stop
# --- Main ---
Write-Info "Checking for Docker and Docker Compose..."
Assert-Docker
Write-Ok "Prerequisites are satisfied."
# Apple Silicon note (informational)
if ($env:PROCESSOR_ARCHITECTURE -eq 'ARM64') {
Write-Host ""
Write-Info "You appear to be on ARM64. For best performance with GPU, consider Direct Installation:"
Write-Info $DIRECT_URL
}
Ensure-ComposeFile
Ensure-EnvFile
Try-Extract-Config
if ($script:EmbeddingSelection) {
Update-EmbeddingConfig -Model $script:EmbeddingSelection.Model -Label $script:EmbeddingSelection.Label
}
Update-AuthBypassOrPassword
Update-GPU-Options
Enable-Config-Mount
$apiPort = Get-ApiPortFromToml
Update-Port-Mapping -apiPort $apiPort
$uiInstalled = Maybe-Install-UI -apiPort $apiPort
Start-Stack -apiPort $apiPort -ui $uiInstalled
Write-Host ""
Write-Ok "Management commands:"
Write-Info "View logs: docker compose -f $COMPOSE $(if($uiInstalled){'--profile ui '})logs -f"
Write-Info "Stop services: ./stop-morphik.ps1 (runs docker compose down --volumes --remove-orphans)"
Write-Info "Restart: ./start-morphik.ps1"
Write-Host ""
Write-Ok "Enjoy using Morphik!"