| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- # 后端 Java 模块:Maven 打包 + Docker 构建 + 打 TCR 标签 + 推送
- # 用法:
- # cd E:\code\saas\ylrz_saas\java\docker
- # .\build-push.ps1 -Version 1.0.0
- # .\build-push.ps1 -Version 1.0.0 -Modules fs-admin,fs-saas-admin
- # .\build-push.ps1 -Version 1.0.0 -SkipPush # 只打包构建,不推送
- # .\build-push.ps1 -Version 1.0.0 -SkipMvn # 跳过 mvn(target 已有 jar)
- param(
- [Parameter(Mandatory = $true)]
- [string]$Version,
- [string[]]$Modules = @(),
- [switch]$SkipPush,
- [switch]$SkipMvn,
- [string]$Registry = "ylrz-image.tencentcloudcr.com/ylrz"
- )
- $ErrorActionPreference = "Stop"
- $JavaRoot = Split-Path $PSScriptRoot -Parent
- # 模块名 -> TCR 仓库名(默认与模块名相同;特殊映射见下)
- $TcrNames = @{
- "fs-saas-company" = "fs-company"
- }
- $AllModules = @(
- "fs-admin", "fs-saas-admin", "fs-agent", "fs-saas-company", "fs-company-app",
- "fs-store", "fs-user-app", "fs-user-app-ai-chat", "fs-doctor-app",
- "fs-ai-chat", "fs-ai-api", "fs-ai-call-task",
- "fs-wx-api", "fs-wx-task", "fs-wx-ipad-task",
- "fs-qwhook", "fs-qwhook-sop", "fs-qwhook-msg",
- "fs-qw-api", "fs-qw-api-msg", "fs-qw-voice", "fs-qw-mq",
- "fs-common-api", "fs-ad-api", "fs-ad-new-api",
- "fs-worker-app", "fs-live-app", "fs-comm-gateway", "fs-repeat-api",
- "fs-redis", "fs-watch", "fs-websocket",
- "fs-ipad-task", "fs-cid-workflow", "fs-task"
- )
- if ($Modules.Count -gt 0) {
- $TargetModules = $Modules
- } else {
- $TargetModules = $AllModules
- }
- function Get-TcrImage([string]$Module) {
- $repo = if ($TcrNames.ContainsKey($Module)) { $TcrNames[$Module] } else { $Module }
- return "$Registry/${repo}:$Version"
- }
- Write-Host "========================================" -ForegroundColor Cyan
- Write-Host " 后端镜像构建 Version=$Version 模块数=$($TargetModules.Count)" -ForegroundColor Cyan
- Write-Host " Registry: $Registry" -ForegroundColor Cyan
- Write-Host "========================================" -ForegroundColor Cyan
- if (-not $SkipMvn) {
- $moduleList = $TargetModules -join ","
- Write-Host "`n[mvn] mvn -pl $moduleList -am clean package -DskipTests" -ForegroundColor Yellow
- Push-Location $JavaRoot
- try {
- mvn -pl $moduleList -am clean package -DskipTests
- if ($LASTEXITCODE -ne 0) { throw "Maven build failed" }
- } finally {
- Pop-Location
- }
- }
- $failed = @()
- foreach ($mod in $TargetModules) {
- $dir = Join-Path $JavaRoot $mod
- $jar = Join-Path $dir "target\$mod.jar"
- $tcrImage = Get-TcrImage $mod
- $localTag = "${mod}:$Version"
- Write-Host "`n--- $mod ---" -ForegroundColor Green
- if (-not (Test-Path $jar)) {
- Write-Host " [SKIP] jar 不存在: $jar" -ForegroundColor Red
- $failed += $mod
- continue
- }
- Push-Location $dir
- try {
- Write-Host " docker build -t $localTag ."
- docker build -t $localTag .
- if ($LASTEXITCODE -ne 0) { throw "docker build failed" }
- Write-Host " docker tag $localTag $tcrImage"
- docker tag $localTag $tcrImage
- if (-not $SkipPush) {
- Write-Host " docker push $tcrImage"
- docker push $tcrImage
- if ($LASTEXITCODE -ne 0) { throw "docker push failed" }
- }
- Write-Host " [OK] $tcrImage" -ForegroundColor Green
- } catch {
- Write-Host " [FAIL] $_" -ForegroundColor Red
- $failed += $mod
- } finally {
- Pop-Location
- }
- }
- Write-Host "`n========================================" -ForegroundColor Cyan
- if ($failed.Count -eq 0) {
- Write-Host " 全部完成" -ForegroundColor Green
- } else {
- Write-Host " 失败模块: $($failed -join ', ')" -ForegroundColor Red
- }
|