* Add template api endpoints Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com> * Added template bypass Pools and scale sets will automatically migrate to the new template system for runner install scripts. If a pool or a scale set cannot be migrate, it is left alone. It is expected that users set a runner install template manually for scenarios we don't yet have a template for (windows on gitea for example). Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com> * Integrate templates with pool create/update Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com> * Add webapp integration with templates Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com> * Add unit tests Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com> * Populate all relevant context fields Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com> * Update dependencies Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com> * Fix lint Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com> * Validate uint Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com> * Add CLI template management Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com> * Some editor improvements and bugfixes Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com> * Fix scale set return values post create Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com> * Fix template websocket events filter Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com> --------- Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
57 lines
No EOL
2.2 KiB
Cheetah
57 lines
No EOL
2.2 KiB
Cheetah
$ErrorActionPreference="Stop"
|
|
|
|
function Start-ExecuteWithRetry {
|
|
[CmdletBinding()]
|
|
param(
|
|
[Parameter(Mandatory=$true)]
|
|
[ScriptBlock]$ScriptBlock,
|
|
[int]$MaxRetryCount=10,
|
|
[int]$RetryInterval=3,
|
|
[string]$RetryMessage,
|
|
[array]$ArgumentList=@()
|
|
)
|
|
PROCESS {
|
|
$currentErrorActionPreference = $ErrorActionPreference
|
|
$ErrorActionPreference = "Continue"
|
|
$retryCount = 0
|
|
while ($true) {
|
|
try {
|
|
$res = Invoke-Command -ScriptBlock $ScriptBlock -ArgumentList $ArgumentList
|
|
$ErrorActionPreference = $currentErrorActionPreference
|
|
return $res
|
|
} catch [System.Exception] {
|
|
$retryCount++
|
|
|
|
if ($_.Exception -is [System.Net.WebException]) {
|
|
$webResponse = $_.Exception.Response
|
|
# Skip retry on Error: 4XX (e.g. 401 Unauthorized, 404 Not Found etc.)
|
|
if ($webResponse -and $webResponse.StatusCode -ge 400 -and $webResponse.StatusCode -lt 500) {
|
|
# Skip retry on 4xx errors
|
|
Write-Output "Encountered non-retryable error (4xx): $($_.Exception.Message)"
|
|
$ErrorActionPreference = $currentErrorActionPreference
|
|
throw
|
|
}
|
|
}
|
|
|
|
if ($retryCount -gt $MaxRetryCount) {
|
|
$ErrorActionPreference = $currentErrorActionPreference
|
|
throw
|
|
} else {
|
|
if ($RetryMessage) {
|
|
Write-Output $RetryMessage
|
|
} elseif ($_) {
|
|
Write-Output $_
|
|
}
|
|
Start-Sleep -Seconds $RetryInterval
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$installScript = (Join-Path $env:TMP, "garm-install.ps1")
|
|
Start-ExecuteWithRetry -ScriptBlock {
|
|
wget -UseBasicParsing -Headers @{"Accept"="application/json"; "Authorization"="Bearer {{ .CallbackToken }}"} -Uri {{ .MetadataURL }}/install-script/ -OutFile $installScript
|
|
} -MaxRetryCount 5 -RetryInterval 5 -RetryMessage "Retrying download of runner install script..."
|
|
|
|
$installScript |