Files
kra-new/web/docker/pack.ps1
T

28 lines
748 B
PowerShell

param(
[Parameter(Position = 0)]
[string]$Tag = (Get-Date -Format 'yyyyMMdd')
)
$ErrorActionPreference = 'Stop'
if ($Tag -notmatch '^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,100}$') {
Write-Error "无效版本号: $Tag"
}
$Root = Split-Path -Parent $PSScriptRoot
$OutDir = $PSScriptRoot
$Image = "sw2/frontend:$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 }
if (Test-Path $Tar) { Remove-Item $Tar -Force }
Write-Host "导出 $Tar"
docker save -o $Tar $Image
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
$Item = Get-Item $Tar
Write-Host ("完成 {0} {1:N1} MB" -f $Item.FullName, ($Item.Length / 1MB))