#Requires -Version 5.1 <# .SYNOPSIS 构建官网镜像并推送到私有 Registry(对齐 bd-server/scripts/push-main-image.ps1) .DESCRIPTION 使用前: docker login docker-registry.tianyuanapi.com 默认镜像: docker-registry.tianyuanapi.com/haiyushuke/website:latest .EXAMPLE .\scripts\docker\build-push.ps1 .\scripts\docker\build-push.ps1 -ExportTar #> param( [string]$Registry = "docker-registry.tianyuanapi.com", [string]$ImagePath = "haiyushuke/website", [string]$SiteUrl = "https://www.haiyushuke.com", [string]$BaiduVerification = "", [string]$NodeImage = "docker.m.daocloud.io/library/node:20-alpine", [switch]$ExportTar ) $ErrorActionPreference = "Stop" $Tag = "latest" $ProjectRoot = Resolve-Path (Join-Path $PSScriptRoot "../..") $FullImage = "${Registry}/${ImagePath}:${Tag}" $LocalName = "haiyushuke-website:build" $TarPath = Join-Path $PSScriptRoot "haiyushuke-website-latest.tar" Set-Location $ProjectRoot Write-Host "==> Pre-pull base image: $NodeImage" docker pull $NodeImage if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } Write-Host "==> build $LocalName" $buildArgs = @( "build", "-t", $LocalName, "--build-arg", "NODE_IMAGE=$NodeImage", "--build-arg", "NEXT_PUBLIC_SITE_URL=$SiteUrl" ) if ($BaiduVerification) { $buildArgs += @("--build-arg", "BAIDU_SITE_VERIFICATION=$BaiduVerification") } $buildArgs += "." docker @buildArgs if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } if ($ExportTar) { Write-Host "==> tag $FullImage (for save)" docker tag $LocalName $FullImage Write-Host "==> save $TarPath" docker save -o $TarPath $FullImage if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } Write-Host "Done (tar): $TarPath" exit 0 } Write-Host "==> tag $FullImage" docker tag $LocalName $FullImage Write-Host "==> push $FullImage" docker push $FullImage if ($LASTEXITCODE -ne 0) { Write-Host "" Write-Host "Push failed. Check:" -ForegroundColor Yellow Write-Host " docker login $Registry" -ForegroundColor Yellow Write-Host (' curl -sI "https://{0}/v2/{1}/manifests/latest"' -f $Registry, $ImagePath) -ForegroundColor Yellow Write-Host "Registry host must be docker-registry.tianyuanapi.com (not docker-register...)." -ForegroundColor Yellow exit $LASTEXITCODE } Write-Host "" Write-Host "Done. Pushed: $FullImage" Write-Host "Deploy host: cd scripts/docker && ./deploy-pull.sh"