Add deploy workflow: build.bat packaging script plus gitignore zip exclusion

This commit is contained in:
2026-05-25 22:54:36 +08:00
parent d972421312
commit b66adcddde
5 changed files with 195 additions and 2 deletions
+1
View File
@@ -67,3 +67,4 @@ test-uploads/
*.bak
matrix-media-*.png
maven-wrapper.zip
deploy/*.zip
+44
View File
@@ -0,0 +1,44 @@
# 部署说明
## 快速打包
```powershell
powershell -File deploy/package.ps1
```
生成 `deploy/publish_deploy.zip`,解压到 `/usr/local/publish_dishboard/` 自动对齐目录。
## 目录结构
解压后:
```
/usr/local/publish_dishboard/
frontend/
index.html ← 前端入口
server.js ← Node.js 静态文件服务
assets/ ← JS/CSS 等静态资源
app.jar ← 后端 Spring Boot JAR
```
## 服务端口
| 服务 | 端口 | 说明 |
|--------|-------|------------------------|
| 前端 | 30080 | Node.js (`server.js`) |
| 后端 | 30081 | Java (`app.jar`) |
## Nginx 路由配置
```
location /publish_dishboard/ {
proxy_pass http://127.0.0.1:30080/;
}
location /publish_server/ {
proxy_pass http://127.0.0.1:30081/;
}
```
## 前端资源路径
前端构建使用 `router basename = /publish_dishboard`Nginx 需确保 `/assets/` 路径可访问。
+59
View File
@@ -0,0 +1,59 @@
@echo off
REM AI 发布平台 - 一键打包脚本
REM 用法: deploy\build.bat
REM
REM 前端构建: npm run build
REM 后端构建: mvn package
REM 打包: PowerShell Compress-Archive
echo === AI 发布平台 打包 ===
echo.
echo [1/4] Building frontend...
cd /d "%~dp0.."
call npm run build
if errorlevel 1 (
echo ERROR: Frontend build failed
pause
exit /b 1
)
echo.
echo [2/4] Building backend...
call mvnw.cmd package -DskipTests -q
if errorlevel 1 (
echo ERROR: Backend build failed
pause
exit /b 1
)
echo.
echo [3/4] Preparing files...
set TMPDIR=%TEMP%\publish_deploy_%RANDOM%
mkdir "%TMPDIR%\frontend" 2>nul
copy "dist\index.html" "%TMPDIR%\frontend\" >nul
copy "dist\assets\*" "%TMPDIR%\frontend\assets\" >nul
copy "server.js" "%TMPDIR%\frontend\" >nul
copy "target\daily-report-distribution-1.0.0.jar" "%TMPDIR%\app.jar" >nul
echo.
echo [4/4] Creating zip...
powershell -Command "Compress-Archive -Path '%TMPDIR%\*' -DestinationPath 'deploy\publish_deploy.zip' -Force"
if errorlevel 1 (
echo ERROR: Zip failed
pause
exit /b 1
)
rmdir /s /q "%TMPDIR%" 2>nul
echo.
echo === Done ===
echo Output: deploy\publish_deploy.zip
echo.
echo Deploy:
echo 1. Upload to NAS: /usr/local/publish_dishboard/
echo 2. Extract
echo 3. Restart services
echo.
pause
+89
View File
@@ -0,0 +1,89 @@
$ErrorActionPreference = 'Stop'
$ProjectRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
if (-not $ProjectRoot) { $ProjectRoot = $PSScriptRoot }
Write-Host '=== AI 发布平台 打包工具 ===' -ForegroundColor Cyan
Write-Host ''
# 1. 检查环境
Write-Host '[1/5] 检查环境...' -ForegroundColor Yellow
$node = Get-Command node -ErrorAction SilentlyContinue
if (-not $node) {
Write-Host 'ERROR: Node.js 未安装' -ForegroundColor Red
exit 1
}
Write-Host (' Node: ' + $node.Version)
Write-Host (' npm: ' + (npm --version))
# 2. 构建前端
Write-Host '[2/5] 构建前端 (npm run build)...' -ForegroundColor Yellow
Push-Location $ProjectRoot
try {
npm run build 2>&1 | Out-Null
if ($LASTEXITCODE -ne 0) {
Write-Host 'ERROR: 前端构建失败' -ForegroundColor Red
exit 1
}
} finally {
Pop-Location
}
Write-Host ' 前端构建完成'
# 3. 构建后端 JAR
Write-Host '[3/5] 构建后端 (mvn package)...' -ForegroundColor Yellow
Push-Location $ProjectRoot
try {
if (-not $env:JAVA_HOME) {
$javaDirs = Get-ChildItem 'C:\Program Files\Java' -ErrorAction SilentlyContinue
$java = $javaDirs | Sort-Object LastWriteTime -Descending | Select-Object -First 1
if ($java) {
$env:JAVA_HOME = $java.FullName
$env:PATH = $env:JAVA_HOME + '\bin;' + $env:PATH
Write-Host (' JAVA_HOME: ' + $env:JAVA_HOME)
}
}
.\mvnw.cmd package -DskipTests -q 2>&1 | Out-Null
if ($LASTEXITCODE -ne 0) {
Write-Host 'ERROR: 后端构建失败' -ForegroundColor Red
exit 1
}
} finally {
Pop-Location
}
Write-Host ' 后端构建完成'
# 4. 准备打包目录
Write-Host '[4/5] 准备打包文件...' -ForegroundColor Yellow
$tmpDir = $env:TEMP + '\publish_deploy_' + (Get-Date -Format 'yyyyMMdd_HHmmss')
$frontendDir = $tmpDir + '\frontend'
New-Item -ItemType Directory -Path $frontendDir -Force | Out-Null
Copy-Item ($ProjectRoot + '\dist\index.html') $frontendDir -Force
Copy-Item ($ProjectRoot + '\dist\assets') $frontendDir -Recurse -Force
Copy-Item ($ProjectRoot + '\server.js') $frontendDir -Force
Copy-Item ($ProjectRoot + '\target\daily-report-distribution-1.0.0.jar') $tmpDir -Force
Write-Host ' 打包结构:'
Write-Host ' frontend/'
Write-Host ' index.html'
Write-Host ' server.js'
Write-Host ' assets/'
Write-Host ' app.jar'
# 5. 打包
Write-Host '[5/5] 打包 zip...' -ForegroundColor Yellow
$outputZip = $ProjectRoot + '\deploy\publish_deploy.zip'
Compress-Archive -Path ($tmpDir + '\*') -DestinationPath $outputZip -Force
$zipSize = [math]::Round((Get-Item $outputZip).Length / 1MB, 1)
Write-Host (' 打包完成: ' + $outputZip + ' (' + $zipSize + ' MB)')
Remove-Item $tmpDir -Recurse -Force -ErrorAction SilentlyContinue
Write-Host ''
Write-Host '=== 打包成功 ===' -ForegroundColor Green
Write-Host ''
Write-Host '部署步骤:' -ForegroundColor Cyan
Write-Host ' 1. 上传 deploy\publish_deploy.zip 到 NAS: /usr/local/publish_dishboard/'
Write-Host ' 2. 解压覆盖'
Write-Host ' 3. 重启前后端服务'
Write-Host ''
+1 -1
View File
@@ -17,7 +17,7 @@ services:
networks:
- app-network
# Frontend: Python HTTP server with API proxy
# Frontend: Node.js static file server with API proxy
frontend:
build:
context: .