fix(infra): use conditional docker template to avoid Health key error
Some checks failed
CI / quality-ts (push) Failing after 1m0s
CI / quality-go (push) Failing after 4s
CI / quality-proto (push) Failing after 2s
CI / deploy (push) Has been skipped

Use {{if .State.Health}}...{{end}} instead of direct {{.State.Health.Status}}.
This commit is contained in:
SpecialX
2026-07-09 13:58:55 +08:00
parent 959d58a95d
commit b72c8d81d4
2 changed files with 26 additions and 16 deletions

View File

@@ -34,16 +34,20 @@ $infraContainers = @(
$infraOk = 0
$infraFail = 0
foreach ($svc in $infraContainers) {
$status = docker inspect --format='{{.State.Health.Status}}' $svc.Container 2>$null
if ($status -eq "healthy") {
$running = docker inspect -f '{{.State.Running}}' $svc.Container 2>$null
if ($running -ne "true") {
Write-Host " [FAIL] $($svc.Name) not running" -ForegroundColor Red
$infraFail++
continue
}
# 条件模板Health 不存在时返回空字符串,不报错
$health = docker inspect -f '{{if .State.Health}}{{.State.Health.Status}}{{end}}' $svc.Container 2>$null
if ($health -eq "healthy") {
Write-Host " [OK] $($svc.Name)" -ForegroundColor Green
$infraOk++
} elseif ($status -eq "running") {
} else {
Write-Host " [WARN] $($svc.Name) (running, no healthcheck)" -ForegroundColor Yellow
$infraOk++
} else {
Write-Host " [FAIL] $($svc.Name) (status=$status)" -ForegroundColor Red
$infraFail++
}
}

View File

@@ -36,22 +36,28 @@ if (-not $SkipInfraCheck) {
@{Name="Jaeger"; Container="edu-jaeger"}
)
$allHealthy = $true
$prevEAP = $ErrorActionPreference
$ErrorActionPreference = "Continue"
foreach ($svc in $infraServices) {
$status = docker inspect --format='{{.State.Health.Status}}' $svc.Container 2>$null
if ($status -eq "healthy") {
Write-Host " [OK] $($svc.Name) ($($svc.Container))" -ForegroundColor Green
} elseif ($status -eq "running") {
Write-Host " [WARN] $($svc.Name) running but no healthcheck" -ForegroundColor Yellow
} else {
Write-Host " [FAIL] $($svc.Name) not started or unhealthy (status=$status)" -ForegroundColor Red
Write-Host " Please start infrastructure first:" -ForegroundColor Red
Write-Host " docker compose -f infra/docker-compose.yml --profile p6 --profile observability up -d" -ForegroundColor Red
$running = docker inspect -f '{{.State.Running}}' $svc.Container 2>$null
if ($running -ne "true") {
Write-Host " [FAIL] $($svc.Name) not running" -ForegroundColor Red
$allHealthy = $false
continue
}
# 条件模板Health 不存在时返回空字符串,不报错
$health = docker inspect -f '{{if .State.Health}}{{.State.Health.Status}}{{end}}' $svc.Container 2>$null
if ($health -eq "healthy") {
Write-Host " [OK] $($svc.Name) ($($svc.Container))" -ForegroundColor Green
} else {
Write-Host " [WARN] $($svc.Name) running (no healthcheck)" -ForegroundColor Yellow
}
}
$ErrorActionPreference = $prevEAP
if (-not $allHealthy) {
Write-Host ""
Write-Host "Infrastructure not ready. Start it first." -ForegroundColor Red
Write-Host "Infrastructure not ready. Start it first:" -ForegroundColor Red
Write-Host " docker compose -f infra/docker-compose.yml --profile p6 --profile observability up -d" -ForegroundColor White
exit 1
}
Write-Host ""