fix: 统一前端Harbor镜像发布与拉取部署
This commit is contained in:
+30
-12
@@ -1,27 +1,45 @@
|
||||
param(
|
||||
[Parameter(Position = 0)]
|
||||
[string]$Tag = (Get-Date -Format 'yyyyMMdd')
|
||||
[string]$Tag = (Get-Date -Format 'yyyyMMdd'),
|
||||
[switch]$SaveArchive
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
if ($Tag -notmatch '^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,100}$') {
|
||||
if ($Tag -notmatch '^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,79}$') {
|
||||
Write-Error "无效版本号: $Tag"
|
||||
}
|
||||
|
||||
$Root = Split-Path -Parent $PSScriptRoot
|
||||
$OutDir = $PSScriptRoot
|
||||
$Image = "sw2/frontend:$Tag"
|
||||
$OutDir = Join-Path $Root '.cache\docker'
|
||||
$Image = "harbor.fuhua91.com/game/sw2:$Tag"
|
||||
$Tar = Join-Path $OutDir "sw2-frontend-$Tag.tar"
|
||||
|
||||
Write-Host "构建 $Image"
|
||||
docker build --build-arg "VERSION=$Tag" -t $Image $Root
|
||||
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
||||
$previousAttestations = [Environment]::GetEnvironmentVariable('BUILDX_NO_DEFAULT_ATTESTATIONS', 'Process')
|
||||
try {
|
||||
$env:BUILDX_NO_DEFAULT_ATTESTATIONS = '1'
|
||||
docker buildx version *> $null
|
||||
if ($LASTEXITCODE -eq 0) {
|
||||
docker buildx build --platform linux/amd64 --output type=docker --build-arg "VERSION=$Tag" -t $Image $Root
|
||||
} else {
|
||||
docker build --build-arg "VERSION=$Tag" -t $Image $Root
|
||||
}
|
||||
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
||||
} finally {
|
||||
[Environment]::SetEnvironmentVariable('BUILDX_NO_DEFAULT_ATTESTATIONS', $previousAttestations, 'Process')
|
||||
}
|
||||
|
||||
if (Test-Path $Tar) { Remove-Item $Tar -Force }
|
||||
Write-Host "导出 $Tar"
|
||||
docker save -o $Tar $Image
|
||||
Write-Host "推送 $Image"
|
||||
docker push $Image
|
||||
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
||||
|
||||
$Item = Get-Item $Tar
|
||||
Write-Host ("完成 {0} {1:N1} MB" -f $Item.FullName, ($Item.Length / 1MB))
|
||||
if ($SaveArchive) {
|
||||
New-Item -ItemType Directory -Force -Path $OutDir | Out-Null
|
||||
if (Test-Path -LiteralPath $Tar) { throw "镜像归档已存在:$Tar" }
|
||||
Write-Host "导出 $Tar"
|
||||
docker save -o $Tar $Image
|
||||
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
||||
$Item = Get-Item -LiteralPath $Tar
|
||||
Write-Host ("完成 {0} {1:N1} MB" -f $Item.FullName, ($Item.Length / 1MB))
|
||||
}
|
||||
Write-Host "Harbor 镜像:$Image"
|
||||
|
||||
Reference in New Issue
Block a user