upd deploy

This commit is contained in:
beo3000 2026-03-01 20:03:31 +01:00
parent 535f3aca38
commit 3214fd5364
2 changed files with 72 additions and 62 deletions

View File

@ -1 +1 @@
1.2.4 1.2.5

View File

@ -129,22 +129,28 @@ Write-Host "=== Restart App Service ===" -ForegroundColor Cyan
az webapp restart --name $APP --resource-group $RG az webapp restart --name $APP --resource-group $RG
Write-Host "=== Post-Deploy DB Validation ===" -ForegroundColor Cyan Write-Host "=== Post-Deploy DB Validation ===" -ForegroundColor Cyan
Write-Host " Waiting for server to boot (~20s)..." -ForegroundColor DarkGray
$bootDeadline = (Get-Date).AddSeconds(45) $validationOk = $false
$serverReady = $false $keepValidating = $true
while ((Get-Date) -lt $bootDeadline) {
while ($keepValidating) {
$keepValidating = $false
Write-Host " Waiting for server to boot (~20s)..." -ForegroundColor DarkGray
$bootDeadline = (Get-Date).AddSeconds(45)
$serverReady = $false
while ((Get-Date) -lt $bootDeadline) {
Start-Sleep -Seconds 3 Start-Sleep -Seconds 3
try { try {
$h = Invoke-RestMethod -Uri "$AppUrl/api/health" -Method GET -UseBasicParsing -TimeoutSec 5 $h = Invoke-RestMethod -Uri "$AppUrl/api/health" -Method GET -UseBasicParsing -TimeoutSec 5
if ($h.status -eq 'ok') { $serverReady = $true; break } if ($h.status -eq 'ok') { $serverReady = $true; break }
} catch { } } catch { }
} }
if (-not $serverReady) { if (-not $serverReady) {
Write-Host " WARNING: Server did not respond within 45s" -ForegroundColor Red Write-Host " WARNING: Server did not respond within 45s" -ForegroundColor Red
} }
$validationOk = $false if ($serverReady -and $env:KA_NOTE_DEPLOY_API_KEY) {
if ($serverReady -and $env:KA_NOTE_DEPLOY_API_KEY) {
$authHeader = @{ Authorization = "Bearer $env:KA_NOTE_DEPLOY_API_KEY" } $authHeader = @{ Authorization = "Bearer $env:KA_NOTE_DEPLOY_API_KEY" }
$maxRetries = 6 $maxRetries = 6
for ($attempt = 1; $attempt -le $maxRetries; $attempt++) { for ($attempt = 1; $attempt -le $maxRetries; $attempt++) {
@ -168,20 +174,23 @@ if ($serverReady -and $env:KA_NOTE_DEPLOY_API_KEY) {
if (-not $validationOk) { if (-not $validationOk) {
Write-Host " DB validation FAILED after $maxRetries attempts" -ForegroundColor Red Write-Host " DB validation FAILED after $maxRetries attempts" -ForegroundColor Red
} }
} elseif (-not $env:KA_NOTE_DEPLOY_API_KEY) { } elseif (-not $env:KA_NOTE_DEPLOY_API_KEY) {
Write-Host " KA_NOTE_DEPLOY_API_KEY not set, skipping DB validation" -ForegroundColor Yellow Write-Host " KA_NOTE_DEPLOY_API_KEY not set, skipping DB validation" -ForegroundColor Yellow
$validationOk = $true $validationOk = $true
} }
if (-not $validationOk) { if (-not $validationOk) {
$latestBackup = Get-ChildItem -Path $BackupDir -Filter "*.db" | $latestBackup = Get-ChildItem -Path $BackupDir -Filter "*.db" |
Sort-Object LastWriteTime -Descending | Select-Object -First 1 Sort-Object LastWriteTime -Descending | Select-Object -First 1
Write-Host "" Write-Host ""
Write-Host " !! DB appears empty or unreachable after deploy !!" -ForegroundColor Red Write-Host " !! DB appears empty or unreachable after deploy !!" -ForegroundColor Red
Write-Host " Pre-deploy backup: $($latestBackup.FullName)" -ForegroundColor Yellow Write-Host " Pre-deploy backup: $($latestBackup.FullName)" -ForegroundColor Yellow
Write-Host "" Write-Host ""
$answer = Read-Host " Restore backup to prod? (yes/no)" $answer = Read-Host " Restore backup to prod? (yes/no/retry)"
if ($answer -eq 'yes') { if ($answer -eq 'retry') {
Write-Host " Retrying validation..." -ForegroundColor Cyan
$keepValidating = $true
} elseif ($answer -eq 'yes') {
Write-Host " Uploading backup to prod..." -ForegroundColor Cyan Write-Host " Uploading backup to prod..." -ForegroundColor Cyan
Invoke-WebRequest -Uri $KuduDbUrl ` Invoke-WebRequest -Uri $KuduDbUrl `
-Method PUT ` -Method PUT `
@ -194,6 +203,7 @@ if (-not $validationOk) {
Write-Host " Restore skipped. Manual intervention required!" -ForegroundColor Red Write-Host " Restore skipped. Manual intervention required!" -ForegroundColor Red
exit 1 exit 1
} }
}
} }
Write-Host "=== Done! $VERSION deployed ===" -ForegroundColor Green Write-Host "=== Done! $VERSION deployed ===" -ForegroundColor Green