chore: update installation script to improve error handling and suppress output in Docker commands

This commit is contained in:
Anish Sarkar 2026-03-03 19:33:21 +05:30
parent e7d6e5f5bd
commit 0fd1d37ed4
2 changed files with 17 additions and 3 deletions

1
.gitignore vendored
View file

@ -5,3 +5,4 @@ node_modules/
.ruff_cache/ .ruff_cache/
.venv .venv
.pnpm-store .pnpm-store
.DS_Store

View file

@ -78,8 +78,10 @@ function Wait-ForPostgres {
} }
Start-Sleep -Seconds 2 Start-Sleep -Seconds 2
Push-Location $InstallDir Push-Location $InstallDir
docker compose exec -T db pg_isready -U $DbUser -q 2>$null $ErrorActionPreference = 'Continue'
docker compose exec -T db pg_isready -U $DbUser -q *>$null
$ready = $LASTEXITCODE -eq 0 $ready = $LASTEXITCODE -eq 0
$ErrorActionPreference = 'Stop'
Pop-Location Pop-Location
} while (-not $ready) } while (-not $ready)
@ -115,7 +117,9 @@ Write-Ok "All files downloaded to $InstallDir/"
# ── Legacy all-in-one detection ───────────────────────────────────────────── # ── Legacy all-in-one detection ─────────────────────────────────────────────
$ErrorActionPreference = 'Continue'
$volumeList = docker volume ls --format '{{.Name}}' 2>$null $volumeList = docker volume ls --format '{{.Name}}' 2>$null
$ErrorActionPreference = 'Stop'
if (($volumeList -split "`n") -contains $OldVolume -and -not (Test-Path $MigrationDoneFile)) { if (($volumeList -split "`n") -contains $OldVolume -and -not (Test-Path $MigrationDoneFile)) {
$MigrationMode = $true $MigrationMode = $true
@ -222,7 +226,9 @@ if ($MigrationMode) {
# Smoke test # Smoke test
Push-Location $InstallDir Push-Location $InstallDir
$ErrorActionPreference = 'Continue'
$tableCount = (docker compose exec -T -e "PGPASSWORD=$DbPass" db psql -U $DbUser -d $DbName -t -c "SELECT count(*) FROM information_schema.tables WHERE table_schema = 'public';" 2>$null).Trim() $tableCount = (docker compose exec -T -e "PGPASSWORD=$DbPass" db psql -U $DbUser -d $DbName -t -c "SELECT count(*) FROM information_schema.tables WHERE table_schema = 'public';" 2>$null).Trim()
$ErrorActionPreference = 'Stop'
Pop-Location Pop-Location
if (-not $tableCount -or $tableCount -eq "0") { if (-not $tableCount -or $tableCount -eq "0") {
@ -255,8 +261,13 @@ if ($SetupWatchtower) {
$wtHours = [math]::Floor($WatchtowerInterval / 3600) $wtHours = [math]::Floor($WatchtowerInterval / 3600)
Write-Step "Setting up Watchtower (auto-updates every ${wtHours}h)" Write-Step "Setting up Watchtower (auto-updates every ${wtHours}h)"
$wtState = docker inspect -f '{{.State.Running}}' $WatchtowerContainer 2>$null try {
if ($LASTEXITCODE -ne 0) { $wtState = "missing" } $ErrorActionPreference = 'Continue'
$wtState = docker inspect -f '{{.State.Running}}' $WatchtowerContainer 2>$null
if ($LASTEXITCODE -ne 0) { $wtState = "missing" }
} finally {
$ErrorActionPreference = 'Stop'
}
if ($wtState -eq "true") { if ($wtState -eq "true") {
Write-Ok "Watchtower is already running - skipping." Write-Ok "Watchtower is already running - skipping."
@ -265,6 +276,7 @@ if ($SetupWatchtower) {
Write-Info "Removing stopped Watchtower container..." Write-Info "Removing stopped Watchtower container..."
docker rm -f $WatchtowerContainer *>$null docker rm -f $WatchtowerContainer *>$null
} }
$ErrorActionPreference = 'Continue'
docker run -d ` docker run -d `
--name $WatchtowerContainer ` --name $WatchtowerContainer `
--restart unless-stopped ` --restart unless-stopped `
@ -272,6 +284,7 @@ if ($SetupWatchtower) {
nickfedor/watchtower ` nickfedor/watchtower `
--label-enable ` --label-enable `
--interval $WatchtowerInterval *>$null --interval $WatchtowerInterval *>$null
$ErrorActionPreference = 'Stop'
if ($LASTEXITCODE -eq 0) { if ($LASTEXITCODE -eq 0) {
Write-Ok "Watchtower started - labeled SurfSense containers will auto-update." Write-Ok "Watchtower started - labeled SurfSense containers will auto-update."