upd deploy
This commit is contained in:
parent
535f3aca38
commit
3214fd5364
|
|
@ -1 +1 @@
|
||||||
1.2.4
|
1.2.5
|
||||||
|
|
@ -129,70 +129,80 @@ 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)
|
|
||||||
$serverReady = $false
|
|
||||||
while ((Get-Date) -lt $bootDeadline) {
|
|
||||||
Start-Sleep -Seconds 3
|
|
||||||
try {
|
|
||||||
$h = Invoke-RestMethod -Uri "$AppUrl/api/health" -Method GET -UseBasicParsing -TimeoutSec 5
|
|
||||||
if ($h.status -eq 'ok') { $serverReady = $true; break }
|
|
||||||
} catch { }
|
|
||||||
}
|
|
||||||
if (-not $serverReady) {
|
|
||||||
Write-Host " WARNING: Server did not respond within 45s" -ForegroundColor Red
|
|
||||||
}
|
|
||||||
|
|
||||||
$validationOk = $false
|
$validationOk = $false
|
||||||
if ($serverReady -and $env:KA_NOTE_DEPLOY_API_KEY) {
|
$keepValidating = $true
|
||||||
$authHeader = @{ Authorization = "Bearer $env:KA_NOTE_DEPLOY_API_KEY" }
|
|
||||||
$maxRetries = 6
|
|
||||||
for ($attempt = 1; $attempt -le $maxRetries; $attempt++) {
|
|
||||||
try {
|
|
||||||
$stats = Invoke-RestMethod -Uri "$AppUrl/api/admin/stats" -Method GET `
|
|
||||||
-Headers $authHeader -UseBasicParsing -TimeoutSec 15
|
|
||||||
$contextCount = $stats.contextCount
|
|
||||||
$topicCount = $stats.topicCount
|
|
||||||
Write-Host " [$attempt/$maxRetries] Contexts: $contextCount, Topics: $topicCount" -ForegroundColor DarkGray
|
|
||||||
if ($contextCount -gt 0 -and $topicCount -gt 0) {
|
|
||||||
Write-Host " DB validation passed." -ForegroundColor Green
|
|
||||||
$validationOk = $true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if ($attempt -lt $maxRetries) { Start-Sleep -Seconds 10 }
|
|
||||||
} catch {
|
|
||||||
Write-Host " [$attempt/$maxRetries] Request error: $_" -ForegroundColor Yellow
|
|
||||||
if ($attempt -lt $maxRetries) { Start-Sleep -Seconds 10 }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (-not $validationOk) {
|
|
||||||
Write-Host " DB validation FAILED after $maxRetries attempts" -ForegroundColor Red
|
|
||||||
}
|
|
||||||
} elseif (-not $env:KA_NOTE_DEPLOY_API_KEY) {
|
|
||||||
Write-Host " KA_NOTE_DEPLOY_API_KEY not set, skipping DB validation" -ForegroundColor Yellow
|
|
||||||
$validationOk = $true
|
|
||||||
}
|
|
||||||
|
|
||||||
if (-not $validationOk) {
|
while ($keepValidating) {
|
||||||
$latestBackup = Get-ChildItem -Path $BackupDir -Filter "*.db" |
|
$keepValidating = $false
|
||||||
Sort-Object LastWriteTime -Descending | Select-Object -First 1
|
|
||||||
Write-Host ""
|
Write-Host " Waiting for server to boot (~20s)..." -ForegroundColor DarkGray
|
||||||
Write-Host " !! DB appears empty or unreachable after deploy !!" -ForegroundColor Red
|
$bootDeadline = (Get-Date).AddSeconds(45)
|
||||||
Write-Host " Pre-deploy backup: $($latestBackup.FullName)" -ForegroundColor Yellow
|
$serverReady = $false
|
||||||
Write-Host ""
|
while ((Get-Date) -lt $bootDeadline) {
|
||||||
$answer = Read-Host " Restore backup to prod? (yes/no)"
|
Start-Sleep -Seconds 3
|
||||||
if ($answer -eq 'yes') {
|
try {
|
||||||
Write-Host " Uploading backup to prod..." -ForegroundColor Cyan
|
$h = Invoke-RestMethod -Uri "$AppUrl/api/health" -Method GET -UseBasicParsing -TimeoutSec 5
|
||||||
Invoke-WebRequest -Uri $KuduDbUrl `
|
if ($h.status -eq 'ok') { $serverReady = $true; break }
|
||||||
-Method PUT `
|
} catch { }
|
||||||
-Headers @{ Authorization = "Bearer $KuduToken" } `
|
}
|
||||||
-InFile $latestBackup.FullName -UseBasicParsing | Out-Null
|
if (-not $serverReady) {
|
||||||
Write-Host " Backup uploaded. Restarting app..." -ForegroundColor Cyan
|
Write-Host " WARNING: Server did not respond within 45s" -ForegroundColor Red
|
||||||
az webapp restart --name $APP --resource-group $RG
|
}
|
||||||
Write-Host " Restore complete. Verify manually: $AppUrl" -ForegroundColor Green
|
|
||||||
} else {
|
if ($serverReady -and $env:KA_NOTE_DEPLOY_API_KEY) {
|
||||||
Write-Host " Restore skipped. Manual intervention required!" -ForegroundColor Red
|
$authHeader = @{ Authorization = "Bearer $env:KA_NOTE_DEPLOY_API_KEY" }
|
||||||
exit 1
|
$maxRetries = 6
|
||||||
|
for ($attempt = 1; $attempt -le $maxRetries; $attempt++) {
|
||||||
|
try {
|
||||||
|
$stats = Invoke-RestMethod -Uri "$AppUrl/api/admin/stats" -Method GET `
|
||||||
|
-Headers $authHeader -UseBasicParsing -TimeoutSec 15
|
||||||
|
$contextCount = $stats.contextCount
|
||||||
|
$topicCount = $stats.topicCount
|
||||||
|
Write-Host " [$attempt/$maxRetries] Contexts: $contextCount, Topics: $topicCount" -ForegroundColor DarkGray
|
||||||
|
if ($contextCount -gt 0 -and $topicCount -gt 0) {
|
||||||
|
Write-Host " DB validation passed." -ForegroundColor Green
|
||||||
|
$validationOk = $true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if ($attempt -lt $maxRetries) { Start-Sleep -Seconds 10 }
|
||||||
|
} catch {
|
||||||
|
Write-Host " [$attempt/$maxRetries] Request error: $_" -ForegroundColor Yellow
|
||||||
|
if ($attempt -lt $maxRetries) { Start-Sleep -Seconds 10 }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (-not $validationOk) {
|
||||||
|
Write-Host " DB validation FAILED after $maxRetries attempts" -ForegroundColor Red
|
||||||
|
}
|
||||||
|
} elseif (-not $env:KA_NOTE_DEPLOY_API_KEY) {
|
||||||
|
Write-Host " KA_NOTE_DEPLOY_API_KEY not set, skipping DB validation" -ForegroundColor Yellow
|
||||||
|
$validationOk = $true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-not $validationOk) {
|
||||||
|
$latestBackup = Get-ChildItem -Path $BackupDir -Filter "*.db" |
|
||||||
|
Sort-Object LastWriteTime -Descending | Select-Object -First 1
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host " !! DB appears empty or unreachable after deploy !!" -ForegroundColor Red
|
||||||
|
Write-Host " Pre-deploy backup: $($latestBackup.FullName)" -ForegroundColor Yellow
|
||||||
|
Write-Host ""
|
||||||
|
$answer = Read-Host " Restore backup to prod? (yes/no/retry)"
|
||||||
|
if ($answer -eq 'retry') {
|
||||||
|
Write-Host " Retrying validation..." -ForegroundColor Cyan
|
||||||
|
$keepValidating = $true
|
||||||
|
} elseif ($answer -eq 'yes') {
|
||||||
|
Write-Host " Uploading backup to prod..." -ForegroundColor Cyan
|
||||||
|
Invoke-WebRequest -Uri $KuduDbUrl `
|
||||||
|
-Method PUT `
|
||||||
|
-Headers @{ Authorization = "Bearer $KuduToken" } `
|
||||||
|
-InFile $latestBackup.FullName -UseBasicParsing | Out-Null
|
||||||
|
Write-Host " Backup uploaded. Restarting app..." -ForegroundColor Cyan
|
||||||
|
az webapp restart --name $APP --resource-group $RG
|
||||||
|
Write-Host " Restore complete. Verify manually: $AppUrl" -ForegroundColor Green
|
||||||
|
} else {
|
||||||
|
Write-Host " Restore skipped. Manual intervention required!" -ForegroundColor Red
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue