Files
dyolink/infrastructure/scripts/ci-resolve-node-image.ps1
rameen 957f94cf15 Cache npm and Docker bases on the Windows Gitea host for Iran-only builds.
CI installs via local Verdaccio and prefers Gitea copies of node/postgres/nginx so staging and prod can still ship when Docker Hub and npmjs are unreachable.
2026-09-15 12:04:04 +03:30

109 lines
3.1 KiB
PowerShell

# Prefer Gitea-hosted dyolink-node (node + dumb-init) so docker build does not HEAD registry-1.docker.io
# or run apt-get. Order: Gitea dyolink-node -> Gitea node -> NODE_IMAGE_SOURCE -> Arvan/mirrors -> 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-bookworm-slim',
[AllowEmptyString()]
[string]$ExtraSources = ''
)
$ErrorActionPreference = 'Continue'
$prefix = $RegistryPrefix.Trim().TrimEnd('/')
$dyolink = "$prefix/dyolink-node:20-bookworm-slim"
$mirror = "$prefix/node:20-bookworm-slim"
$nl = [char]10
function Test-Image([string]$Name) {
docker image inspect $Name 2>&1 | Out-Null
return ($LASTEXITCODE -eq 0)
}
function Invoke-Pull([string]$Name, [int]$Attempts) {
for ($i = 1; $i -le $Attempts; $i++) {
Write-Host "docker pull $Name (attempt $i/$Attempts)"
docker pull $Name
if ($LASTEXITCODE -eq 0) { return $true }
if ($i -lt $Attempts) { Start-Sleep -Seconds 5 }
}
return $false
}
function Save-Choice([string]$Name) {
$utf8 = New-Object System.Text.UTF8Encoding $false
$path = Join-Path (Get-Location) $OutFile
[System.IO.File]::WriteAllText($path, ($Name + $nl), $utf8)
Write-Host "NODE_IMAGE=$Name"
}
function Publish-Mirror([string]$Src, [string]$Dest) {
Write-Host "Tagging $Src as $Dest"
docker tag $Src $Dest
if ($LASTEXITCODE -ne 0) { return $false }
docker push $Dest
if ($LASTEXITCODE -ne 0) {
Write-Host "Could not push $Dest - 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 $Dest
return $true
}
if (Test-Image $dyolink) {
Write-Host "Using local $dyolink"
Save-Choice $dyolink
exit 0
}
if (Invoke-Pull $dyolink 1) {
Save-Choice $dyolink
exit 0
}
if (Test-Image $mirror) {
Write-Host "Using local $mirror (no dumb-init; Dockerfile may apt-get)"
Save-Choice $mirror
exit 0
}
if (Invoke-Pull $mirror 1) {
Save-Choice $mirror
exit 0
}
$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) }
}
}
foreach ($src in @(
'docker.arvancloud.ir/library/node:20-bookworm-slim',
'public.ecr.aws/docker/library/node:20-bookworm-slim',
'mirror.gcr.io/library/node:20-bookworm-slim',
$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 $mirror) { exit 0 }
}
}
foreach ($src in $sources) {
if (Invoke-Pull $src 2) {
if (Publish-Mirror $src $mirror) { exit 0 }
}
}
Write-Host "Could not pull node:20-bookworm-slim from Gitea, mirrors, or Docker Hub."
Write-Host "While online run: infrastructure/scripts/seed-gitea-base-images.ps1"
Write-Host "Set repository variable NODE_IMAGE_SOURCE if you have another reachable image."
exit 1