From b99c7000405befeb5940128a7cdde05616c337c8 Mon Sep 17 00:00:00 2001 From: WuYongJie <549727955@qq.com> Date: Tue, 11 Aug 2026 12:52:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=BC=BA=E5=8F=91=E5=B8=83=20SSH=20?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E9=87=8D=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/deploy-from-workstation.ps1 | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/scripts/deploy-from-workstation.ps1 b/scripts/deploy-from-workstation.ps1 index 7133c053..a890dc9b 100644 --- a/scripts/deploy-from-workstation.ps1 +++ b/scripts/deploy-from-workstation.ps1 @@ -49,6 +49,31 @@ function Invoke-Native { } } +function Invoke-NativeWithRetry { + param( + [Parameter(Mandatory = $true)] + [scriptblock]$Command, + [Parameter(Mandatory = $true)] + [string]$FailureMessage, + [int]$Attempts = 3, + [int]$DelaySeconds = 3 + ) + + for ($attempt = 1; $attempt -le $Attempts; $attempt++) { + & $Command + if ($LASTEXITCODE -eq 0) { + return + } + + if ($attempt -lt $Attempts) { + Write-Warning "$FailureMessage 正在重试($attempt/$Attempts)。" + Start-Sleep -Seconds $DelaySeconds + } + } + + throw $FailureMessage +} + function Get-PrivateEnvironmentValue { param([Parameter(Mandatory = $true)][string]$Name) @@ -398,8 +423,8 @@ try { } '服务器激活、健康检查或增量仓库初始化失败。' } else { - Invoke-Native { - ssh -i $keyFullPath -o BatchMode=yes $sshTarget "chmod 700 '$RemotePath/'*.sh && chmod 644 '$RemotePath/config-db-init.sh' && (curl -fsS -o /dev/null http://127.0.0.1:5000/v2/ || '$RemotePath/setup-incremental-registry.sh' '$RemotePath' '$RemotePath/registry-config.yml')" + Invoke-NativeWithRetry { + ssh -i $keyFullPath -o BatchMode=yes -o ConnectTimeout=10 -o ConnectionAttempts=1 $sshTarget "chmod 700 '$RemotePath/'*.sh && chmod 644 '$RemotePath/config-db-init.sh' && (curl -fsS -o /dev/null http://127.0.0.1:5000/v2/ || '$RemotePath/setup-incremental-registry.sh' '$RemotePath' '$RemotePath/registry-config.yml')" } '服务器增量镜像仓库初始化失败。' # docker save 导出未压缩层,每次导入重新压缩会改变摘要,导致 Registry 无法复用。 -- 2.47.2