/
kreyndelHam
/
Konstructorium
Обзор
Документация
Войти
/
kreyndelHam
/
Konstructorium
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
1
CI/CD
Аналитика
Безопасность
dev
scripts/docker/verify_dev_stack.ps1
111 строк
3 KB
MihahamYT
Telegram Bot Working
25 май 2026, 20:20
25 май 2026, 20:20
1089971
Код
Авторство
О чём код?
# Readiness check for docker-compose dev stack (native PowerShell, no bash). param( [int]$WaitSec = 240 ) $ErrorActionPreference = "Stop" $Root = (Resolve-Path (Join-Path $PSScriptRoot "..\..")).Path Set-Location $Root $composeFile = if ($env:COMPOSE_FILE) { $env:COMPOSE_FILE } else { "docker-compose.services.yml" } $vpnComposeFile = $env:VPN_COMPOSE_FILE function Invoke-Compose { param([string[]]$ExtraArgs) $args = @("compose", "-f", $composeFile) if ($vpnComposeFile) { $args += @("-f", $vpnComposeFile) } $args += $ExtraArgs & docker @args } function Get-HealthStatus { param([string]$ServiceName) $cid = (Invoke-Compose @("ps", "-q", $ServiceName) 2>$null | Select-Object -First 1) if (-not $cid) { return "missing" } $status = docker inspect -f '{{if .State.Health}}{{.State.Health.Status}}{{else}}no-healthcheck{{end}}' $cid 2>$null if ($status) { return $status.Trim() } return "unknown" } function Wait-Healthy { param([string]$ServiceName) $deadline = (Get-Date).AddSeconds($WaitSec) $last = "" while ((Get-Date) -lt $deadline) { $last = Get-HealthStatus $ServiceName if ($last -eq "healthy") { return $true } if ($last -eq "missing") { Write-Host "Service '$ServiceName' has no running container yet (status=$last)." } else { Write-Host "Waiting for ${ServiceName}: $last" } Start-Sleep -Seconds 3 } Write-Host "Timeout waiting for healthy: $ServiceName (last='$last')" return $false } function Test-HttpOk { param([string]$Url, [int]$TimeoutSec = 10) try { $null = Invoke-WebRequest -Uri $Url -UseBasicParsing -TimeoutSec $TimeoutSec -Method Get return $true } catch { return $false } } Invoke-Compose @("config") | Out-Null if ($LASTEXITCODE -ne 0) { Write-Error "Invalid compose file: $composeFile" } Write-Host "[1/4] PostgreSQL data directory permissions..." & (Join-Path $PSScriptRoot "ensure_postgres_data_dir.ps1") if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } Write-Host "[2/4] Waiting for db and redis health (timeout ${WaitSec}s)..." if (-not (Wait-Healthy "db")) { exit 1 } if (-not (Wait-Healthy "redis")) { exit 1 } Write-Host "[3/4] Waiting for core API health endpoints (timeout ${WaitSec}s)..." $deadline = (Get-Date).AddSeconds($WaitSec) $urls = @( "http://127.0.0.1:8001/api/health/", "http://127.0.0.1:8002/api/health/", "http://127.0.0.1:8003/api/models/" ) while ((Get-Date) -lt $deadline) { $allOk = $true foreach ($u in $urls) { if (-not (Test-HttpOk $u)) { $allOk = $false; break } } if ($allOk) { break } Start-Sleep -Seconds 4 } foreach ($u in $urls) { if (-not (Test-HttpOk $u)) { Write-Host "[FAIL] API not ready: $u" exit 1 } } Write-Host "[4/4] Redis PING..." $redisOk = $false if (Get-Command redis-cli -ErrorAction SilentlyContinue) { $pong = redis-cli -h 127.0.0.1 -p 6379 ping 2>$null $redisOk = ($pong -match "PONG") } else { $pong = Invoke-Compose @("exec", "-T", "redis", "redis-cli", "ping") $redisOk = ("$pong" -match "PONG") } if (-not $redisOk) { Write-Host "[FAIL] Redis PING failed" exit 1 } Write-Host "OK: db/redis healthy; auth, user, product API respond; Redis PONG." exit 0