fix: pull node:20-alpine from Arvan/ECR when Docker Hub is blocked
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
# Prefer a Gitea-hosted node:20-alpine so docker build does not HEAD registry-1.docker.io.
|
||||
# Order: local Gitea tag -> pull Gitea -> local Docker Hub tag -> pull Hub (retries) -> tag/push Gitea.
|
||||
# Order: Gitea -> optional NODE_IMAGE_SOURCE -> regional/official mirrors -> Docker Hub last.
|
||||
# ASCII only: Windows PowerShell 5.1 + act_runner mis-parses backtick escapes in this file.
|
||||
param(
|
||||
[Parameter(Mandatory = $true)][string]$RegistryPrefix,
|
||||
[string]$OutFile = '.ci-node-image',
|
||||
[string]$HubImage = 'node:20-alpine'
|
||||
[string]$HubImage = 'node:20-alpine',
|
||||
[string]$ExtraSources = ''
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Continue'
|
||||
@@ -21,7 +22,7 @@ function Invoke-Pull([string]$Name, [int]$Attempts) {
|
||||
Write-Host "docker pull $Name (attempt $i/$Attempts)"
|
||||
docker pull $Name
|
||||
if ($LASTEXITCODE -eq 0) { return $true }
|
||||
if ($i -lt $Attempts) { Start-Sleep -Seconds (10 * $i) }
|
||||
if ($i -lt $Attempts) { Start-Sleep -Seconds 5 }
|
||||
}
|
||||
return $false
|
||||
}
|
||||
@@ -33,39 +34,66 @@ function Save-Choice([string]$Name) {
|
||||
Write-Host "NODE_IMAGE=$Name"
|
||||
}
|
||||
|
||||
function Publish-Mirror([string]$Src) {
|
||||
Write-Host "Tagging $Src as $mirror"
|
||||
docker tag $Src $mirror
|
||||
if ($LASTEXITCODE -ne 0) { return $false }
|
||||
docker push $mirror
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Host "Could not push $mirror - docker build will use the local tag (legacy builder)."
|
||||
$flag = Join-Path (Get-Location) '.ci-use-legacy-builder'
|
||||
New-Item -ItemType File -Path $flag -Force | Out-Null
|
||||
}
|
||||
Save-Choice $mirror
|
||||
return $true
|
||||
}
|
||||
|
||||
if (Test-Image $mirror) {
|
||||
Write-Host "Using local $mirror"
|
||||
Save-Choice $mirror
|
||||
exit 0
|
||||
}
|
||||
|
||||
if (Invoke-Pull $mirror 2) {
|
||||
if (Invoke-Pull $mirror 1) {
|
||||
Save-Choice $mirror
|
||||
exit 0
|
||||
}
|
||||
|
||||
if (-not (Test-Image $HubImage)) {
|
||||
if (-not (Invoke-Pull $HubImage 5)) {
|
||||
Write-Host "Cannot pull $HubImage from Docker Hub (TLS timeout or blocked)."
|
||||
Write-Host "On the Windows runner, when Hub is reachable:"
|
||||
Write-Host " docker pull $HubImage"
|
||||
Write-Host " docker tag $HubImage $mirror"
|
||||
Write-Host " docker push $mirror"
|
||||
Write-Host "Then re-run this workflow."
|
||||
exit 1
|
||||
$sources = New-Object System.Collections.ArrayList
|
||||
if (-not [string]::IsNullOrWhiteSpace($ExtraSources)) {
|
||||
foreach ($part in ($ExtraSources -split ',')) {
|
||||
$src = $part.Trim()
|
||||
if ($src.Length -gt 0) { [void]$sources.Add($src) }
|
||||
}
|
||||
}
|
||||
# Iran-reachable proxy of Docker Hub official images, then public official mirrors, Hub last.
|
||||
foreach ($src in @(
|
||||
'docker.arvancloud.ir/library/node:20-alpine',
|
||||
'public.ecr.aws/docker/library/node:20-alpine',
|
||||
'mirror.gcr.io/library/node:20-alpine',
|
||||
$HubImage
|
||||
)) {
|
||||
if (-not $sources.Contains($src)) { [void]$sources.Add($src) }
|
||||
}
|
||||
|
||||
foreach ($src in $sources) {
|
||||
if (Test-Image $src) {
|
||||
Write-Host "Found local $src"
|
||||
if (Publish-Mirror $src) { exit 0 }
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "Tagging $HubImage as $mirror"
|
||||
docker tag $HubImage $mirror
|
||||
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
||||
|
||||
docker push $mirror
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Host "Could not push $mirror - docker build will use the local tag (legacy builder)."
|
||||
$flag = Join-Path (Get-Location) '.ci-use-legacy-builder'
|
||||
New-Item -ItemType File -Path $flag -Force | Out-Null
|
||||
foreach ($src in $sources) {
|
||||
if (Invoke-Pull $src 2) {
|
||||
if (Publish-Mirror $src) { exit 0 }
|
||||
}
|
||||
}
|
||||
|
||||
Save-Choice $mirror
|
||||
exit 0
|
||||
Write-Host "Could not pull node:20-alpine from Gitea, mirrors, or Docker Hub."
|
||||
Write-Host "Set repository variable NODE_IMAGE_SOURCE to a reachable image, for example:"
|
||||
Write-Host " docker.arvancloud.ir/library/node:20-alpine"
|
||||
Write-Host "Or on the Windows runner:"
|
||||
Write-Host " docker pull docker.arvancloud.ir/library/node:20-alpine"
|
||||
Write-Host " docker tag docker.arvancloud.ir/library/node:20-alpine $mirror"
|
||||
Write-Host " docker push $mirror"
|
||||
exit 1
|
||||
|
||||
Reference in New Issue
Block a user