Files
sfera/scripts/smoke-test-docker.ps1
2026-05-16 19:03:49 +03:00

60 lines
2.0 KiB
PowerShell

param(
[string]$ApiUrl = "http://localhost:8000",
[string]$WebUrl = "http://localhost:3000",
[string]$Neo4jUrl = "http://localhost:7474",
[string]$QdrantUrl = "http://localhost:6333",
[string]$ObjectStorageUrl = "http://localhost:9000",
[string]$ProjectName = "",
[switch]$IncludeProjectSetupSmoke,
[string]$BrowserPath = ""
)
$ErrorActionPreference = "Stop"
function Test-Http($Name, $Url) {
$response = Invoke-WebRequest -UseBasicParsing -Uri $Url -TimeoutSec 10
if ($response.StatusCode -lt 200 -or $response.StatusCode -ge 300) {
throw "$Name failed: HTTP $($response.StatusCode)"
}
Write-Host "[ok] $Name $Url"
}
Test-Http "api health" "$ApiUrl/api/health"
Test-Http "web health" "$WebUrl/health"
$compose = @("compose")
if ($ProjectName) {
$compose += @("-p", $ProjectName)
}
$compose += @("-f", "infra/docker/docker-compose.test.yml")
docker @compose exec -T postgres pg_isready -U sfera -d sfera | Out-Host
Write-Host "[ok] postgres health"
Test-Http "neo4j health" "$Neo4jUrl"
Test-Http "qdrant health" "$QdrantUrl/readyz"
docker @compose exec -T redis redis-cli ping | Out-Host
Write-Host "[ok] redis health"
Test-Http "object-storage health" "$ObjectStorageUrl/minio/health/live"
if ($IncludeProjectSetupSmoke) {
$webDir = Join-Path (Get-Location).ProviderPath "frontend\sfera-web"
Write-Host "[run] project setup runtime smoke $WebUrl"
$previousWebUrl = $env:SFERA_WEB_URL
$previousBrowserPath = $env:SFERA_BROWSER_PATH
try {
$env:SFERA_WEB_URL = $WebUrl
if ($BrowserPath) {
$env:SFERA_BROWSER_PATH = $BrowserPath
}
cmd /c "pushd `"$webDir`" && npm run smoke:project-setup"
if ($LASTEXITCODE -ne 0) {
throw "project setup runtime smoke failed with exit code $LASTEXITCODE"
}
Write-Host "[ok] project setup runtime smoke"
} finally {
if ((Get-Location).Path -eq $webDir) {
Pop-Location
}
$env:SFERA_WEB_URL = $previousWebUrl
$env:SFERA_BROWSER_PATH = $previousBrowserPath
}
}