build-push.ps1 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. # 后端 Java 模块:Maven 打包 + Docker 构建 + 打 TCR 标签 + 推送
  2. # 用法:
  3. # cd E:\code\saas\ylrz_saas\java\docker
  4. # .\build-push.ps1 -Version 1.0.0
  5. # .\build-push.ps1 -Version 1.0.0 -Modules fs-admin,fs-saas-admin
  6. # .\build-push.ps1 -Version 1.0.0 -SkipPush # 只打包构建,不推送
  7. # .\build-push.ps1 -Version 1.0.0 -SkipMvn # 跳过 mvn(target 已有 jar)
  8. param(
  9. [Parameter(Mandatory = $true)]
  10. [string]$Version,
  11. [string[]]$Modules = @(),
  12. [switch]$SkipPush,
  13. [switch]$SkipMvn,
  14. [string]$Registry = "ylrz-image.tencentcloudcr.com/ylrz"
  15. )
  16. $ErrorActionPreference = "Stop"
  17. $JavaRoot = Split-Path $PSScriptRoot -Parent
  18. # 模块名 -> TCR 仓库名(默认与模块名相同;特殊映射见下)
  19. $TcrNames = @{
  20. "fs-saas-company" = "fs-company"
  21. }
  22. $AllModules = @(
  23. "fs-admin", "fs-saas-admin", "fs-agent", "fs-saas-company", "fs-company-app",
  24. "fs-store", "fs-user-app", "fs-user-app-ai-chat", "fs-doctor-app",
  25. "fs-ai-chat", "fs-ai-api", "fs-ai-call-task",
  26. "fs-wx-api", "fs-wx-task", "fs-wx-ipad-task",
  27. "fs-qwhook", "fs-qwhook-sop", "fs-qwhook-msg",
  28. "fs-qw-api", "fs-qw-api-msg", "fs-qw-voice", "fs-qw-mq",
  29. "fs-common-api", "fs-ad-api", "fs-ad-new-api",
  30. "fs-worker-app", "fs-live-app", "fs-comm-gateway", "fs-repeat-api",
  31. "fs-redis", "fs-watch", "fs-websocket",
  32. "fs-ipad-task", "fs-cid-workflow", "fs-task"
  33. )
  34. if ($Modules.Count -gt 0) {
  35. $TargetModules = $Modules
  36. } else {
  37. $TargetModules = $AllModules
  38. }
  39. function Get-TcrImage([string]$Module) {
  40. $repo = if ($TcrNames.ContainsKey($Module)) { $TcrNames[$Module] } else { $Module }
  41. return "$Registry/${repo}:$Version"
  42. }
  43. Write-Host "========================================" -ForegroundColor Cyan
  44. Write-Host " 后端镜像构建 Version=$Version 模块数=$($TargetModules.Count)" -ForegroundColor Cyan
  45. Write-Host " Registry: $Registry" -ForegroundColor Cyan
  46. Write-Host "========================================" -ForegroundColor Cyan
  47. if (-not $SkipMvn) {
  48. $moduleList = $TargetModules -join ","
  49. Write-Host "`n[mvn] mvn -pl $moduleList -am clean package -DskipTests" -ForegroundColor Yellow
  50. Push-Location $JavaRoot
  51. try {
  52. mvn -pl $moduleList -am clean package -DskipTests
  53. if ($LASTEXITCODE -ne 0) { throw "Maven build failed" }
  54. } finally {
  55. Pop-Location
  56. }
  57. }
  58. $failed = @()
  59. foreach ($mod in $TargetModules) {
  60. $dir = Join-Path $JavaRoot $mod
  61. $jar = Join-Path $dir "target\$mod.jar"
  62. $tcrImage = Get-TcrImage $mod
  63. $localTag = "${mod}:$Version"
  64. Write-Host "`n--- $mod ---" -ForegroundColor Green
  65. if (-not (Test-Path $jar)) {
  66. Write-Host " [SKIP] jar 不存在: $jar" -ForegroundColor Red
  67. $failed += $mod
  68. continue
  69. }
  70. Push-Location $dir
  71. try {
  72. Write-Host " docker build -t $localTag ."
  73. docker build -t $localTag .
  74. if ($LASTEXITCODE -ne 0) { throw "docker build failed" }
  75. Write-Host " docker tag $localTag $tcrImage"
  76. docker tag $localTag $tcrImage
  77. if (-not $SkipPush) {
  78. Write-Host " docker push $tcrImage"
  79. docker push $tcrImage
  80. if ($LASTEXITCODE -ne 0) { throw "docker push failed" }
  81. }
  82. Write-Host " [OK] $tcrImage" -ForegroundColor Green
  83. } catch {
  84. Write-Host " [FAIL] $_" -ForegroundColor Red
  85. $failed += $mod
  86. } finally {
  87. Pop-Location
  88. }
  89. }
  90. Write-Host "`n========================================" -ForegroundColor Cyan
  91. if ($failed.Count -eq 0) {
  92. Write-Host " 全部完成" -ForegroundColor Green
  93. } else {
  94. Write-Host " 失败模块: $($failed -join ', ')" -ForegroundColor Red
  95. }