copy.ps1 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. # Copy backend JARs and SQL (frontend is built in nginx Dockerfile)
  2. param([switch]$SkipBuild)
  3. $ErrorActionPreference = "Stop"
  4. $DockerDir = $PSScriptRoot
  5. $BackendRoot = Join-Path $DockerDir ".."
  6. function Ensure-Dir([string]$Path) {
  7. if (-not (Test-Path $Path)) { New-Item -ItemType Directory -Path $Path -Force | Out-Null }
  8. }
  9. Write-Host "=== SQL ===" -ForegroundColor Cyan
  10. $DbDir = Join-Path $DockerDir "mysql\db"
  11. Ensure-Dir $DbDir
  12. @(
  13. @{ Out = "01-ry-config.sql"; Db = "ry-config"; Src = "sql\ry-config.sql" }
  14. @{ Out = "02-ry-cloud.sql"; Db = "ry-cloud"; Src = "sql\ry-cloud.sql" }
  15. ) | ForEach-Object {
  16. $srcPath = Join-Path $BackendRoot $_.Src
  17. if (-not (Test-Path $srcPath)) { throw "Missing: $srcPath" }
  18. $lines = @("USE ``$($_.Db)``;"; "") + (Get-Content $srcPath -Encoding UTF8)
  19. $lines | Set-Content (Join-Path $DbDir $_.Out) -Encoding UTF8
  20. Write-Host ("OK: " + $_.Out)
  21. }
  22. if (-not $SkipBuild) {
  23. Write-Host "=== Maven build ===" -ForegroundColor Cyan
  24. if (-not (Get-Command mvn -ErrorAction SilentlyContinue)) {
  25. throw "mvn not found. Install JDK 17 and Maven."
  26. }
  27. Push-Location $BackendRoot
  28. try {
  29. mvn clean package -DskipTests -T 1C
  30. if ($LASTEXITCODE -ne 0) { throw "Maven build failed" }
  31. } finally {
  32. Pop-Location
  33. }
  34. }
  35. Write-Host "=== JARs ===" -ForegroundColor Cyan
  36. $jars = @(
  37. @{ Src = "ruoyi-gateway\target\ruoyi-gateway.jar"; Dest = "ruoyi\gateway\jar" }
  38. @{ Src = "ruoyi-auth\target\ruoyi-auth.jar"; Dest = "ruoyi\auth\jar" }
  39. @{ Src = "ruoyi-visual\ruoyi-monitor\target\ruoyi-visual-monitor.jar"; Dest = "ruoyi\visual\monitor\jar" }
  40. @{ Src = "ruoyi-modules\ruoyi-system\target\ruoyi-modules-system.jar"; Dest = "ruoyi\modules\system\jar" }
  41. @{ Src = "ruoyi-modules\ruoyi-file\target\ruoyi-modules-file.jar"; Dest = "ruoyi\modules\file\jar" }
  42. @{ Src = "ruoyi-modules\ruoyi-job\target\ruoyi-modules-job.jar"; Dest = "ruoyi\modules\job\jar" }
  43. @{ Src = "ruoyi-modules\ruoyi-gen\target\ruoyi-modules-gen.jar"; Dest = "ruoyi\modules\gen\jar" }
  44. @{ Src = "ruoyi-modules\ruoyi-haikang\target\ruoyi-modules-haikang.jar"; Dest = "ruoyi\modules\haikang\jar" }
  45. @{ Src = "ruoyi-modules\ruoyi-qs\target\ruoyi-modules-qs.jar"; Dest = "ruoyi\modules\qs\jar" }
  46. @{ Src = "ruoyi-modules\ruoyi-haikang-isup\target\ruoyi-modules-haikang-isup.jar"; Dest = "ruoyi\modules\haikang-isup\jar" }
  47. @{ Src = "ruoyi-modules\ruoyi-dahua\target\ruoyi-modules-dahua.jar"; Dest = "ruoyi\modules\dahua\jar" }
  48. @{ Src = "ruoyi-modules\ruoyi-onvif\target\ruoyi-modules-onvif.jar"; Dest = "ruoyi\modules\onvif\jar" }
  49. @{ Src = "ruoyi-modules\ruoyi-gb28181\target\ruoyi-modules-gb28181.jar"; Dest = "ruoyi\modules\gb28181\jar" }
  50. @{ Src = "ruoyi-modules\ruoyi-jt1078\target\ruoyi-modules-jt1078.jar"; Dest = "ruoyi\modules\jt1078\jar" }
  51. @{ Src = "ruoyi-modules\ruoyi-zlm\target\ruoyi-modules-zlm.jar"; Dest = "ruoyi\modules\zlm\jar" }
  52. )
  53. $missing = [System.Collections.Generic.List[string]]::new()
  54. $copied = 0
  55. foreach ($item in $jars) {
  56. $src = Join-Path $BackendRoot $item.Src
  57. $destDir = Join-Path $DockerDir $item.Dest
  58. if (-not (Test-Path $src)) {
  59. $missing.Add($item.Src)
  60. continue
  61. }
  62. Ensure-Dir $destDir
  63. $jarName = Split-Path $src -Leaf
  64. Copy-Item $src (Join-Path $destDir $jarName) -Force
  65. Write-Host ("OK: " + $jarName)
  66. $copied++
  67. }
  68. if ($copied -eq 0) {
  69. Write-Host ""
  70. Write-Host "No JAR files found. Run full build first:" -ForegroundColor Red
  71. Write-Host " .\start.ps1" -ForegroundColor Yellow
  72. Write-Host "or:" -ForegroundColor Yellow
  73. Write-Host " cd .." -ForegroundColor Yellow
  74. Write-Host " mvn clean package -DskipTests" -ForegroundColor Yellow
  75. if ($missing.Count -gt 0) {
  76. Write-Host ""
  77. Write-Host "Missing:" -ForegroundColor Red
  78. $missing | ForEach-Object { Write-Host (" - " + $_) }
  79. }
  80. throw "No JAR copied."
  81. }
  82. if ($missing.Count -gt 0) {
  83. Write-Host ""
  84. Write-Host ("Warning: " + $missing.Count + " JAR(s) missing (optional modules may be skipped):") -ForegroundColor Yellow
  85. $missing | ForEach-Object { Write-Host (" - " + $_) }
  86. }
  87. Write-Host ("Done. Copied " + $copied + " JAR(s).") -ForegroundColor Green