Merge remote-tracking branch 'origin/main' into feature/renshen-order-data-upstream
This commit is contained in:
commit
3d98e493f0
@ -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)
|
||||
|
||||
@ -227,6 +252,7 @@ function Start-RegistryTunnel {
|
||||
'-o', 'ConnectTimeout=10',
|
||||
'-o', 'ExitOnForwardFailure=yes',
|
||||
'-o', 'ServerAliveInterval=15',
|
||||
'-o', 'ServerAliveCountMax=20',
|
||||
'-L', "127.0.0.1:${LocalPort}:127.0.0.1:5000",
|
||||
$sshTarget
|
||||
)) {
|
||||
@ -397,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 无法复用。
|
||||
@ -424,11 +450,45 @@ try {
|
||||
$beforeBytesOutput = @(& ssh -i $keyFullPath -o BatchMode=yes $sshTarget "du -sb /var/lib/docker-registry 2>/dev/null | cut -f1")
|
||||
$beforeBytes = [long](($beforeBytesOutput -join '').Trim())
|
||||
$uploadTimer = [Diagnostics.Stopwatch]::StartNew()
|
||||
Invoke-Native {
|
||||
& $regctlPath `
|
||||
--host "reg=127.0.0.1:${localRegistryPort},tls=disabled" `
|
||||
image import $registryImage $localTar
|
||||
} '增量镜像层上传失败。'
|
||||
$uploadSucceeded = $false
|
||||
for ($uploadAttempt = 1; $uploadAttempt -le 2; $uploadAttempt++) {
|
||||
if ($uploadAttempt -gt 1) {
|
||||
if ($sshTunnel) {
|
||||
if (-not $sshTunnel.HasExited) {
|
||||
$sshTunnel.Kill()
|
||||
$sshTunnel.WaitForExit()
|
||||
}
|
||||
$sshTunnel.Dispose()
|
||||
}
|
||||
|
||||
$localRegistryPort = Get-AvailableLocalPort
|
||||
$sshTunnel = Start-RegistryTunnel -LocalPort $localRegistryPort
|
||||
$registryImage = "127.0.0.1:${localRegistryPort}/caiwuxitong/app:$imageTag"
|
||||
}
|
||||
|
||||
if ($sshTunnel.HasExited) {
|
||||
$uploadExitCode = 255
|
||||
}
|
||||
else {
|
||||
& $regctlPath `
|
||||
--host "reg=127.0.0.1:${localRegistryPort},tls=disabled" `
|
||||
image import $registryImage $localTar
|
||||
$uploadExitCode = $LASTEXITCODE
|
||||
}
|
||||
|
||||
if ($uploadExitCode -eq 0) {
|
||||
$uploadSucceeded = $true
|
||||
break
|
||||
}
|
||||
|
||||
if ($uploadAttempt -eq 1) {
|
||||
Write-Warning '增量镜像隧道在上传期间中断,正在重新建立隧道并重试一次。'
|
||||
}
|
||||
}
|
||||
|
||||
if (-not $uploadSucceeded) {
|
||||
throw '增量镜像层上传失败。'
|
||||
}
|
||||
$uploadTimer.Stop()
|
||||
$afterBytesOutput = @(& ssh -i $keyFullPath -o BatchMode=yes $sshTarget "du -sb /var/lib/docker-registry 2>/dev/null | cut -f1")
|
||||
$afterBytes = [long](($afterBytesOutput -join '').Trim())
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user