From ae6ffc8a089c117843a7fecafcc747d1d2fe6e92 Mon Sep 17 00:00:00 2001 From: Danila Khodjaef Date: Wed, 8 Jul 2026 15:48:51 +0300 Subject: [PATCH] Make dev validateBuild bounds check resilient Retry and prefer LAN bounds URL to avoid transient 504 failures. Co-authored-by: Cursor --- infra/scripts/deploy-dev-to-prod.ps1 | 66 +++++++++++++++++++++------- 1 file changed, 49 insertions(+), 17 deletions(-) diff --git a/infra/scripts/deploy-dev-to-prod.ps1 b/infra/scripts/deploy-dev-to-prod.ps1 index 9c117cd..b65874e 100644 --- a/infra/scripts/deploy-dev-to-prod.ps1 +++ b/infra/scripts/deploy-dev-to-prod.ps1 @@ -170,21 +170,36 @@ function Get-LatestDevBackup { } function Test-BoundsJson { - param([string]$Url, [switch]$Insecure) + param( + [string]$Url, + [switch]$Insecure, + [int]$MaxTimeSeconds = 10, + [int]$Retries = 3 + ) - $curlArgs = @('-s', '-f') - if ($Insecure) { $curlArgs += '-k' } - $curlArgs += $Url - $body = & curl.exe @curlArgs 2>$null - if ($LASTEXITCODE -ne 0 -or -not $body) { - return $false - } - try { - $json = $body | ConvertFrom-Json - return ($null -ne $json.min_year -and $null -ne $json.max_year) - } catch { - return $false + for ($attempt = 1; $attempt -le $Retries; $attempt++) { + $curlArgs = @('-s', '-f', '--max-time', $MaxTimeSeconds) + if ($Insecure) { $curlArgs += '-k' } + $curlArgs += $Url + + $body = & curl.exe @curlArgs 2>$null + if ($LASTEXITCODE -eq 0 -and $body) { + try { + $json = $body | ConvertFrom-Json + if ($null -ne $json.min_year -and $null -ne $json.max_year) { + return $true + } + } catch { + # Continue retries below. + } + } + + if ($attempt -lt $Retries) { + Start-Sleep -Seconds 2 + } } + + return $false } # --- Load config --- @@ -232,12 +247,29 @@ if (Get-StepEnabled $steps 'validateBuild') { $code = Invoke-Npm 'prod:build' if ($code -ne 0) { return $code } - $devUrl = if ($cfg.verify.devUrl) { $cfg.verify.devUrl } else { 'https://devgallery.mysuperlab.netcraze.pro/api/bounds' } - if (-not (Test-BoundsJson -Url $devUrl -Insecure)) { - Write-Host "Dev API check failed: $devUrl" -ForegroundColor Red + $devCandidates = @() + if ($cfg.verify.lanUrl) { $devCandidates += $cfg.verify.lanUrl } + if ($cfg.verify.devUrl -and ($devCandidates -notcontains $cfg.verify.devUrl)) { $devCandidates += $cfg.verify.devUrl } + if (-not $devCandidates -or $devCandidates.Count -eq 0) { + $devCandidates = @('https://devgallery.mysuperlab.netcraze.pro/api/bounds') + } + + $devOk = $false + foreach ($u in $devCandidates) { + Write-Host "Checking dev /api/bounds: $u" + $useInsecure = $u.StartsWith('https://', [System.StringComparison]::OrdinalIgnoreCase) + if (Test-BoundsJson -Url $u -Insecure:$useInsecure -MaxTimeSeconds 10 -Retries 3) { + Write-Host "Dev API OK: $u" + $devOk = $true + break + } + Write-Host "Dev API check failed for: $u" -ForegroundColor DarkYellow + } + + if (-not $devOk) { + Write-Host "Dev API check failed on all URLs." -ForegroundColor Red return 1 } - Write-Host "Dev API OK: $devUrl" return 0 } if (-not $ok) { Write-ReleaseBanner -Success $false -FailedAt $FailedStep; exit 1 }