44 lines
1.2 KiB
PowerShell
44 lines
1.2 KiB
PowerShell
param(
|
|
[ValidateRange(1, 65535)]
|
|
[int]$Port = 4173
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
docker compose version | Out-Null
|
|
if ($LASTEXITCODE -ne 0) {
|
|
throw "Docker Compose is not available."
|
|
}
|
|
|
|
docker info | Out-Null
|
|
if ($LASTEXITCODE -ne 0) {
|
|
throw "Docker is not running."
|
|
}
|
|
|
|
$env:APP_PORT = $Port.ToString()
|
|
docker compose up --build --detach
|
|
if ($LASTEXITCODE -ne 0) {
|
|
throw "Docker Compose failed to start the application."
|
|
}
|
|
|
|
$containerId = (docker compose ps --quiet app).Trim()
|
|
if (-not $containerId) {
|
|
throw "The application container was not created."
|
|
}
|
|
|
|
for ($attempt = 0; $attempt -lt 60; $attempt++) {
|
|
$state = docker inspect --format '{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}' $containerId
|
|
if ($state -eq "healthy") {
|
|
Write-Host "Application is ready: http://localhost:$Port"
|
|
exit 0
|
|
}
|
|
if ($state -eq "unhealthy" -or $state -eq "exited" -or $state -eq "dead") {
|
|
docker compose logs --no-color --tail 100 app
|
|
throw "The application container entered state: $state"
|
|
}
|
|
Start-Sleep -Seconds 1
|
|
}
|
|
|
|
docker compose logs --no-color --tail 100 app
|
|
throw "Timed out waiting for the application health check."
|