Repository navigation
84 lines (76 loc) · 3.16 KB
/
Copy pathdeploy-local.yml
File metadata and controls
84 lines (76 loc) · 3.16 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
name: Deploy local
on:
push:
branches: [main]
workflow_dispatch:
concurrency:
group: deploy-local-contextmemory
cancel-in-progress: true
permissions:
contents: read
jobs:
deploy:
if: github.repository == 'Kortexio/ContextMemory'
runs-on: [self-hosted, Windows, network-local]
timeout-minutes: 45
steps:
- name: Pull and rebuild on this PC
shell: powershell
env:
GITHUB_TOKEN: ${{ github.token }}
GIT_TERMINAL_PROMPT: "0"
GCM_INTERACTIVE: never
run: |
$ErrorActionPreference = "Stop"
$env:Path = "C:\Program Files\Docker\Docker\resources\bin;C:\Program Files\Git\cmd;" + $env:Path
$dir = "C:\Network\_work\ContextMemory"
if (-not (Test-Path $dir)) { throw "Pasta em falta: $dir" }
Set-Location $dir
if ([string]::IsNullOrWhiteSpace($env:GITHUB_TOKEN)) {
throw "GITHUB_TOKEN missing - cannot fetch non-interactively"
}
$auth = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("x-access-token:$($env:GITHUB_TOKEN)"))
$header = "AUTHORIZATION: basic $auth"
git -c "http.https://github.com/.extraheader=$header" `
-c http.lowSpeedLimit=1000 `
-c http.lowSpeedTime=60 `
fetch origin main
git checkout main
git reset --hard origin/main
if (-not (Test-Path .env) -and (Test-Path .env.example)) {
Copy-Item .env.example .env
Write-Host "Created .env from .env.example"
}
docker network inspect network-local 2>$null | Out-Null
if ($LASTEXITCODE -ne 0) { docker network create network-local }
docker compose -f docker-compose.yml -f docker-compose.network.yml up -d --build
docker compose -f docker-compose.yml -f docker-compose.network.yml ps
$apiPort = "5100"
$adminPort = "5200"
if (Test-Path .env) {
$m = Select-String -Path .env -Pattern '^API_PORT=(.+)$' | Select-Object -First 1
if ($m) { $apiPort = $m.Matches.Groups[1].Value.Trim() }
$m = Select-String -Path .env -Pattern '^ADMIN_PORT=(.+)$' | Select-Object -First 1
if ($m) { $adminPort = $m.Matches.Groups[1].Value.Trim() }
}
function Wait-HttpOk([string]$Url, [int]$Attempts = 40) {
for ($i = 1; $i -le $Attempts; $i++) {
Start-Sleep -Seconds 3
try {
$health = Invoke-WebRequest $Url -UseBasicParsing -TimeoutSec 10
if ($health.StatusCode -eq 200) {
Write-Host "$Url -> $($health.StatusCode) $($health.Content)"
return $true
}
} catch {
Write-Host "Health $Url attempt $i/$Attempts : $($_.Exception.Message)"
}
}
return $false
}
if (-not (Wait-HttpOk "http://localhost:$apiPort/health")) {
throw "API health check falhou (porta $apiPort)"
}
if (-not (Wait-HttpOk "http://localhost:$adminPort/")) {
throw "Admin health check falhou (porta $adminPort)"
}