fix(docker): multi-theme packaging with PS1 orchestration and full bundle export

Replace all-themes bat logic with PowerShell to survive branch checkout; add api-admin and full-themes service modes; fix bat findstr path check and cmd exit codes; document six-in-one tar and update gitignore for player/full-themes artifacts.
This commit is contained in:
2026-06-24 14:18:31 +08:00
parent 25dd0cf514
commit 9c5e8d6f5c
8 changed files with 425 additions and 298 deletions

View File

@@ -1,17 +1,17 @@
# 鏋勫缓 api / player / admin 鐢熶骇闀滃儚骞跺<EFBFBD>鍑轰负 tar
# 鐢ㄦ硶锛堝湪椤圭洰鏍圭洰褰曟垨鏈<EFBFBD>洰褰曟墽琛屽潎鍙<EFBFBD>:
# ?? api / player / admin ???????? tar
# ??????????????????:
# .\docs\docker\build-and-export-images.ps1
# .\docs\docker\build-and-export-images.ps1 -Service admin
# .\docs\docker\build-and-export-images.ps1 -Tag v1.2.3
# .\docs\docker\build-and-export-images.ps1 -UseCache
# .\docs\docker\build-and-export-images.ps1 -ExportOnly
#
# 四套主题玩家端一键打包(自动切分支,推荐):
# ????????????????????????????????????
# docs\docker\build-and-export-all-themes.bat
param(
[ValidateSet("all", "api", "player", "admin")]
[ValidateSet("all", "api", "player", "admin", "api-admin")]
[string]$Service = "all",
[string]$Tag = $env:IMAGE_TAG,
[switch]$UseCache,
@@ -31,27 +31,27 @@ function Get-DefaultTag { "latest" }
function Get-DefaultOutput {
param([string]$Svc, [string]$ImageTag)
if ($Svc -eq "all") { return "thebet365-images-$ImageTag.tar" }
if ($Svc -eq "all" -or $Svc -eq "api-admin") { return "thebet365-images-$ImageTag.tar" }
return "thebet365-$Svc-$ImageTag.tar"
}
function Assert-ImageTag {
param([string]$Value)
if ($Value -notmatch '^[A-Za-z0-9_][A-Za-z0-9_.-]{0,127}$') {
throw "闀滃儚 tag 涓嶅悎娉? $Value"
throw "?? tag ???? $Value"
}
}
if (-not (Test-Path $ComposeFile)) {
throw "<EFBFBD>壘鍒?$ComposeFile锛堝綋鍓嶇洰褰? $Root?
throw "????$ComposeFile?????? $Root??
}
if (-not (Test-Path $EnvFile)) {
if (Test-Path ".env.docker.example") {
Write-Warning "<EFBFBD>壘鍒?.env.docker锛屼娇鐢?.env.docker.example锛堢敓浜ц<EFBFBD>澶嶅埗骞朵慨鏀瑰瘑閽ワ級"
Write-Warning "????.env.docker????.env.docker.example????????????"
$EnvFile = ".env.docker.example"
} else {
throw "<EFBFBD>壘鍒?.env.docker ?.env.docker.example"
throw "????.env.docker ??.env.docker.example"
}
}
@@ -60,7 +60,11 @@ if ([string]::IsNullOrWhiteSpace($Tag)) {
}
Assert-ImageTag $Tag
$BuildServices = if ($Service -eq "all") { $AllServices } else { @($Service) }
$BuildServices = switch ($Service) {
"all" { $AllServices }
"api-admin" { @("api", "admin") }
default { @($Service) }
}
$SaveImages = $BuildServices | ForEach-Object { "thebet365-${_}:${Tag}" }
if ([string]::IsNullOrWhiteSpace($Output)) {
@@ -68,7 +72,7 @@ if ([string]::IsNullOrWhiteSpace($Output)) {
}
if (-not $ExportOnly) {
Write-Host "==> 鏋勫缓闀滃儚: $($BuildServices -join ', ') (tag: $Tag)"
Write-Host "==> ????: $($BuildServices -join ', ') (tag: $Tag)"
$buildArgs = @(
"compose", "-f", $ComposeFile, "--env-file", $EnvFile, "build"
)
@@ -80,7 +84,7 @@ if (-not $ExportOnly) {
try {
$env:IMAGE_TAG = $Tag
& docker @buildArgs
if ($LASTEXITCODE -ne 0) { throw "docker build 澶辫触锛岄鍑虹爜 $LASTEXITCODE" }
if ($LASTEXITCODE -ne 0) { throw "docker build ?????? $LASTEXITCODE" }
} finally {
$env:IMAGE_TAG = $oldImageTag
}
@@ -88,9 +92,9 @@ if (-not $ExportOnly) {
$OutputPath = if ([System.IO.Path]::IsPathRooted($Output)) { $Output } else { Join-Path $Root $Output }
Write-Host "==> 瀵煎嚭闀滃儚 ($Service) -> $OutputPath"
Write-Host "==> ???? ($Service) -> $OutputPath"
& docker save @SaveImages -o $OutputPath
if ($LASTEXITCODE -ne 0) { throw "docker save 澶辫触锛岄鍑虹爜 $LASTEXITCODE" }
if ($LASTEXITCODE -ne 0) { throw "docker save ?????? $LASTEXITCODE" }
$manifestPath = if ($OutputPath.EndsWith(".tar")) {
$OutputPath.Substring(0, $OutputPath.Length - 4) + ".manifest.txt"
@@ -121,7 +125,7 @@ $manifestLines = @(
)
foreach ($svc in $BuildServices) {
$imageId = (& docker image inspect "thebet365-${svc}:${Tag}" --format "{{.Id}}").Trim()
if ($Service -eq "all") {
if ($Service -eq "all" -or $Service -eq "api-admin") {
$manifestLines += "${svc}_image=thebet365-${svc}:${Tag}"
$manifestLines += "${svc}_image_id=$imageId"
} else {
@@ -132,13 +136,17 @@ foreach ($svc in $BuildServices) {
$manifestLines | Set-Content -Encoding UTF8 $manifestPath
$sizeMb = [math]::Round((Get-Item $OutputPath).Length / 1MB, 2)
Write-Host "瀹屾垚: $OutputPath (${sizeMb} MB)"
Write-Host "??: $OutputPath (${sizeMb} MB)"
Write-Host "Manifest: $manifestPath"
$recreate = if ($Service -eq "all") { "api player admin" } else { $Service }
$recreate = switch ($Service) {
"all" { "api player admin" }
"api-admin" { "api admin" }
default { $Service }
}
Write-Host @"
鏈嶅姟鍣ㄥ<EFBFBD>鍏ュ苟閲嶅缓:
????????:
docker load -i $([System.IO.Path]::GetFileName($OutputPath))
docker compose -f docker-compose.prod.yml --env-file .env.docker up -d --force-recreate $recreate
"@