收敛正式发布为Web和服务端并保留桌面历史源码

This commit is contained in:
xuans committed 2026-09-27 17:22:00 +08:00
1 parent 8b33282a6e
commit 25fd4cf89c
11 files changed
+87 -112

No files matched your search

+18 -11
View File
@@ -1,6 +1,6 @@
# Scert 发布构建
`build-release.ps1` 默认构建 Windows amd64 和 Linux amd64 的核心服务与密码重置程序。当前主机能够直接构建的 Wails 桌面版也会同时写入对应平台目录,并记录到 `manifest.json`。
`build-release.ps1` 默认构建 Windows amd64 和 Linux amd64 的服务端、运维辅助程序及 Web 静态资源。正式交付仅限 Web 和服务端:不调用 Wails,不打包桌面端,也不依赖桌面目录是否存在。
```text
build/release/
@@ -10,11 +10,14 @@ build/release/
│ ├── windows-amd64/
│ │ ├── scert.exe
│ │ ├── scert-admin.exe
│ │ └── ScertDesktop.exe
│ │ ├── web/
│ │ ├── install-windows.ps1
│ │ └── SHA256SUMS
│ └── linux-amd64/
│ ├── scert
│ ├── scert-admin
│ ├── scert-nginx
│ ├── scert-storage
│ ├── web/
│ └── SHA256SUMS
├── Scert-20260915-V0.1.0-linux-amd64.tar.gz
@@ -29,16 +32,16 @@ build/release/
powershell -ExecutionPolicy Bypass -File .\build\build-release.ps1
```
只构建 Windows 核心服务和桌面版:
只构建 Windows 服务端和 Web:
```powershell
powershell -ExecutionPolicy Bypass -File .\build\build-release.ps1 -Target windows-amd64
```
只构建核心服务,不构建桌面版:
只构建 Linux 服务端和 Web:
```powershell
powershell -ExecutionPolicy Bypass -File .\build\build-release.ps1 -SkipDesktop
powershell -ExecutionPolicy Bypass -File .\build\build-release.ps1 -Target linux-amd64
```
指定输出目录:
@@ -47,15 +50,17 @@ powershell -ExecutionPolicy Bypass -File .\build\build-release.ps1 -SkipDesktop
powershell -ExecutionPolicy Bypass -File .\build\build-release.ps1 -OutputDirectory D:\release\Scert
```
桌面版构建需要已安装 Wails v2、Go 和 Node.js。Wails 桌面版使用当前主机原生平台构建;Windows 主机不能直接完成 Linux GTK 桌面交叉构建,Linux 桌面产物需要在 Linux 主机上执行同一脚本。
正式构建需要 Go、Node.js 和 npm,不要求 Wails、WebView2 或 GTK 开发依赖。具体版本见 `doc/构建版本与数据库支持矩阵.md`。桌面窗口、托盘、自动更新、桌面配置及桌面 UI 测试属于范围外;`desktop/` 历史源码保留供独立开发,不得混入正式包。
旧参数 `-SkipDesktop` 保留兼容并输出警告,无论是否传入或显式设为假,都不会构建桌面端。旧参数 `-DesktopDirectory` 在构建前直接报错,避免误以为指定目录仍能加入正式发布。
脚本仅创建新的发布目录。发布目录或对应归档已存在时,在构建前拒绝执行,不覆盖旧包。前端直接构建到本次发布目录中的 `web-build/`,不清空或覆盖已有 `frontend/dist/`。失败产生的目录保留供排查,再次构建请使用新的输出目录。
`manifest.json` 记录源码提交、已跟踪文件是否未提交、实际 Go 工具链、目标平台、是否请求桌面端以及文件和归档的 SHA256。`source_dirty=true` 的包仅用于开发,正式发布必须从已复审提交构建。未跟踪本地产物不计入源码脏状态,也不会自动打包。
`manifest.json` 记录源码提交、已跟踪文件是否未提交、实际 Go 工具链、目标平台和文件及归档的 SHA256。`delivery_scope` 固定为 `web`、`server`,兼容字段 `desktop_requested` 固定为 `false`。`source_dirty=true` 的包仅用于开发,正式发布必须从已复审提交构建。未跟踪本地产物不计入源码脏状态,也不会自动打包。
## 本机路径保护
核心服务、辅助程序和 Wails 桌面版统一使用 `-trimpath`。手动构建也必须保留此参数,例如 `go build -trimpath -o scert ./cmd/scert` 和 `wails build -trimpath -nopackage`。前端生产构建明确关闭源码映射。
正式服务端和辅助程序统一使用 `-trimpath`。手动构建也必须保留此参数,例如 `go build -trimpath -o scert ./cmd/scert`。前端生产构建明确关闭源码映射。
归档前逐个读取 Go 二进制构建信息,确认 `-trimpath=true`;同时扫描发布目录全部文件,拒绝工作区、用户目录、Windows 的 Go/Node 安装目录、实际 Go 工具链、模块缓存、构建缓存、临时目录和输出目录路径残留。Linux 的通用 `/usr/bin` 等运行时目录不因安装工具而被禁用。检查覆盖正反斜杠、JSON 转义、UTF-8 和 UTF-16。发现残留或无法读取构建信息时停止归档,保留失败目录用于排查。
@@ -64,9 +69,11 @@ powershell -ExecutionPolicy Bypass -File .\build\build-release.ps1 -OutputDirect
仅构建本轮 Linux 服务候选包示例:
```powershell
powershell -ExecutionPolicy Bypass -File .\build\build-release.ps1 -Target linux-amd64 -SkipDesktop -OutputDirectory .\build\release-candidate-20260915
powershell -ExecutionPolicy Bypass -File .\build\build-release.ps1 -Target linux-amd64 -OutputDirectory .\build\release-candidate-20260927
```
此命令不构建 Windows 或 Wails 桌面端,不代表跨平台发布验收。归档包含 `scert`、`scert-admin`、`scert-nginx`、Web 静态资源、安装器、systemd 模板、`nginx/` 策略模板和部署说明。解压后先运行 `sha256sum -c SHA256SUMS`,再按部署说明操作。`scert-nginx` 仅随包提供,普通安装器不会安装或启用它;启用前按 `nginx/Nginx辅助服务部署说明.md` 单独完成 root 策略、安全初始化、本地 socket、Nginx 接线和实机验收。
此命令不构建 Windows,不代表跨平台发布验收。Linux 归档包含 `scert`、`scert-admin`、`scert-nginx`、`scert-storage`、Web 静态资源、安装器、systemd 模板、`nginx/` 策略模板和部署说明。解压后先运行 `sha256sum -c SHA256SUMS`,再按部署说明操作。`scert-nginx` 仅随包提供,普通安装器不会安装或启用它;启用前按 `nginx/Nginx辅助服务部署说明.md` 单独完成 root 策略、安全初始化、本地 socket、Nginx 接线和实机验收。
构建通过不等于生产验收通过;真实 DNS、ACME、SSH、Windows Service、systemd、WebView2 和 HTTPS 仍需在授权环境复核。
正式构建验收应检查两个平台的归档与 `manifest.json`:包含对应服务端、运维程序和 Web;不存在 `ScertDesktop`、桌面产物类型或 Wails 依赖;路径扫描及 SHA256 检查通过。不以桌面构建或 WebView2 测试作为门禁。
构建通过不等于生产验收通过;真实 DNS、ACME、SSH、Windows Service、systemd 和 HTTPS 仍需在授权环境复核。
+8 -89
View File
@@ -23,8 +23,11 @@ if ([string]::IsNullOrWhiteSpace($BackendDirectory)) {
if ([string]::IsNullOrWhiteSpace($OutputDirectory)) {
$OutputDirectory = Join-Path $scriptDirectory "release"
}
if ([string]::IsNullOrWhiteSpace($DesktopDirectory)) {
$DesktopDirectory = Join-Path $scriptDirectory "..\desktop"
if ($PSBoundParameters.ContainsKey("DesktopDirectory")) {
throw "正式发布仅包含 Web 和服务端,不再接受 DesktopDirectory;历史桌面源码请在 desktop 目录单独开发。"
}
if ($PSBoundParameters.ContainsKey("SkipDesktop")) {
Write-Warning "SkipDesktop 仅用于兼容旧命令;正式发布始终排除桌面端,无需再传入此参数。"
}
if ([string]::IsNullOrWhiteSpace($DeployDirectory)) {
$DeployDirectory = Join-Path $scriptDirectory "..\deploy"
@@ -65,68 +68,6 @@ function Invoke-GoBuild {
}
}
function Get-HostDesktopTarget {
if ([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform(
[System.Runtime.InteropServices.OSPlatform]::Windows
)) {
return "windows-amd64"
}
if ([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform(
[System.Runtime.InteropServices.OSPlatform]::Linux
)) {
return "linux-amd64"
}
return ""
}
function Invoke-DesktopBuild {
param(
[Parameter(Mandatory = $true)]
[string]$ProjectDirectory,
[Parameter(Mandatory = $true)]
[string]$TargetName,
[Parameter(Mandatory = $true)]
[string]$Destination
)
if (-not (Get-Command wails -ErrorAction SilentlyContinue)) {
throw "未找到 Wails CLI,请先安装 Wails v2."
}
if (-not (Test-Path -LiteralPath (Join-Path $ProjectDirectory "wails.json") -PathType Leaf)) {
throw "桌面项目中没有找到 wails.json:$ProjectDirectory"
}
Write-Host "正在构建 $TargetName 的 Scert 桌面版……"
$desktopGoOS = $env:GOOS
$desktopGoArch = $env:GOARCH
$desktopCGOEnabled = $env:CGO_ENABLED
Push-Location $ProjectDirectory
try {
$env:GOOS = ""
$env:GOARCH = ""
if ($TargetName.StartsWith("linux-")) {
$env:CGO_ENABLED = "1"
}
& wails build -trimpath -nopackage -platform ($TargetName.Replace("-", "/")) -o "ScertDesktop"
if ($LASTEXITCODE -ne 0) {
throw "构建 $TargetName 的 Scert 桌面版失败。"
}
$builtExtension = if ($TargetName.StartsWith("windows-")) { ".exe" } else { "" }
$builtDirectory = Join-Path (Join-Path $ProjectDirectory "build") "bin"
$builtPath = Join-Path $builtDirectory ("ScertDesktop" + $builtExtension)
if (-not (Test-Path -LiteralPath $builtPath -PathType Leaf)) {
throw "Wails 构建完成但没有找到桌面产物:$builtPath"
}
Copy-Item -LiteralPath $builtPath -Destination $Destination -Force
}
finally {
Pop-Location
$env:GOOS = $desktopGoOS
$env:GOARCH = $desktopGoArch
$env:CGO_ENABLED = $desktopCGOEnabled
}
}
function Write-Utf8NoBom {
param(
[Parameter(Mandatory = $true)]
@@ -261,7 +202,6 @@ function Test-ReleasePaths {
$backend = Resolve-SafeDirectory -Path $BackendDirectory -Label "后端目录"
$output = Resolve-SafeDirectory -Path $OutputDirectory -Label "输出目录"
$desktop = Resolve-SafeDirectory -Path $DesktopDirectory -Label "桌面项目目录"
$deploy = Resolve-SafeDirectory -Path $DeployDirectory -Label "部署目录"
$frontend = Resolve-SafeDirectory -Path (Join-Path $scriptDirectory "..\frontend") -Label "前端目录"
@@ -348,7 +288,6 @@ $oldGoOS = $env:GOOS
$oldGoArch = $env:GOARCH
$oldCGOEnabled = $env:CGO_ENABLED
$manifestArtifacts = [System.Collections.Generic.List[object]]::new()
$hostDesktopTarget = Get-HostDesktopTarget
Push-Location $backend
try {
@@ -362,7 +301,7 @@ try {
}
$goEnvironment = ($goEnvironmentJSON -join "`n") | ConvertFrom-Json
$forbiddenPaths = @(
(Split-Path -Parent $scriptDirectory), $backend, $desktop, $frontend, $deploy, $output,
(Split-Path -Parent $scriptDirectory), $backend, $frontend, $deploy, $output,
$env:USERPROFILE, $env:HOME, [System.IO.Path]::GetTempPath(),
$goEnvironment.GOROOT, $goEnvironment.GOMODCACHE, $goEnvironment.GOCACHE, $goEnvironment.GOTMPDIR
) + $goEnvironment.GOPATH.Split([System.IO.Path]::PathSeparator)
@@ -408,27 +347,6 @@ try {
Copy-Item -LiteralPath (Join-Path $deploy "install-windows.ps1") -Destination (Join-Path $targetDirectory "install-windows.ps1")
}
if (-not $SkipDesktop) {
if ($item -eq $hostDesktopTarget) {
$desktopExtension = if ($goos -eq "windows") { ".exe" } else { "" }
$desktopPath = Join-Path $targetDirectory ("ScertDesktop" + $desktopExtension)
Invoke-DesktopBuild -ProjectDirectory $desktop -TargetName $item -Destination $desktopPath
$binaries += ("ScertDesktop" + $desktopExtension)
$file = Get-Item -LiteralPath $desktopPath
$hash = Get-FileHash -LiteralPath $desktopPath -Algorithm SHA256
$manifestArtifacts.Add([ordered]@{
target = $item
type = "desktop"
file = Get-RelativeReleasePath -BaseDirectory $releaseDirectory -Path $file.FullName
size = $file.Length
sha256 = $hash.Hash.ToLowerInvariant()
})
}
else {
Write-Warning "当前主机不能直接构建 $item 的 Wails 桌面版;请在对应平台主机上执行同一脚本。"
}
}
$checkedPaths = @($forbiddenPaths | Where-Object { -not [string]::IsNullOrWhiteSpace($_) } | Select-Object -Unique)
Test-ReleasePaths -Source $targetDirectory -Binaries $binaries -ForbiddenPaths $checkedPaths
Write-TargetChecksums -TargetDirectory $targetDirectory | Out-Null
@@ -479,7 +397,8 @@ $manifest = [ordered]@{
trimpath = $true
local_path_check = "passed"
targets = @($Target)
desktop_requested = -not [bool]$SkipDesktop
delivery_scope = @("web", "server")
desktop_requested = $false
generated_at = [DateTimeOffset]::UtcNow.ToString("o")
artifacts = $manifestArtifacts
}