统一 frontend、backend、test、test-log 和 out 目录,更新构建、部署及测试入口;纳入配置管理兼容与首次安全引导修复;排除本机配置、密钥和测试产物。
This commit is contained in:
1 parent
28cd9d3406
commit
f60d3b0880
603 files changed
+2351
-660
No files matched your search
@@ -0,0 +1,23 @@
|
||||
param([switch]$SkipFrontend)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$root = Split-Path -Parent $PSScriptRoot
|
||||
$output = Join-Path $root 'out\backend'
|
||||
New-Item -ItemType Directory -Path $output -Force | Out-Null
|
||||
if (-not $SkipFrontend) {
|
||||
Push-Location (Join-Path $root 'frontend')
|
||||
try {
|
||||
& npm.cmd run build
|
||||
if ($LASTEXITCODE -ne 0) { throw '前端构建失败' }
|
||||
} finally { Pop-Location }
|
||||
}
|
||||
Push-Location (Join-Path $root 'backend')
|
||||
try {
|
||||
& go build -o (Join-Path $output 'smail-dev.exe') .
|
||||
if ($LASTEXITCODE -ne 0) { throw '开发后端构建失败' }
|
||||
& go build -o (Join-Path $output 'smail-admin.exe') ./cmd/smail-admin
|
||||
if ($LASTEXITCODE -ne 0) { throw '管理工具构建失败' }
|
||||
& go build -o (Join-Path $output 'smail-config.exe') ./cmd/smail-config
|
||||
if ($LASTEXITCODE -ne 0) { throw '配置工具构建失败' }
|
||||
} finally { Pop-Location }
|
||||
Write-Output '构建完成:out/frontend 和 out/backend。正式发行请使用 Makefile 的跨平台构建目标。'
|
||||
@@ -11,8 +11,13 @@ install -d -m 0750 /var/lib/smail /run/smail /usr/local/lib/smail
|
||||
if ! getent group smail >/dev/null; then groupadd --system smail; fi
|
||||
if ! getent passwd smail >/dev/null; then useradd --system --gid smail --home-dir /var/lib/smail --shell /usr/sbin/nologin smail; fi
|
||||
chown smail:smail /var/lib/smail
|
||||
install -o root -g root -m 0755 "$root_dir/server/smail" /usr/local/lib/smail/smail
|
||||
install -o root -g root -m 0750 "$root_dir/server/smail-admin" /usr/local/lib/smail/smail-admin
|
||||
case "$(uname -m)" in
|
||||
x86_64) arch=amd64 ;;
|
||||
aarch64|arm64) arch=arm64 ;;
|
||||
*) echo "不支持的系统架构" >&2; exit 1 ;;
|
||||
esac
|
||||
install -o root -g root -m 0755 "$root_dir/out/backend/smail_linux_$arch" /usr/local/lib/smail/smail
|
||||
install -o root -g root -m 0750 "$root_dir/out/backend/smail-admin_linux_$arch" /usr/local/lib/smail/smail-admin
|
||||
install -o root -g root -m 0644 "$root_dir/deploy/systemd/smail.service" /etc/systemd/system/smail.service
|
||||
install -o root -g root -m 0644 "$root_dir/deploy/systemd/smail-admin.service" /etc/systemd/system/smail-admin.service
|
||||
chown smail:smail /run/smail
|
||||
|
||||
@@ -100,14 +100,16 @@ function Stop-SmailService {
|
||||
|
||||
Assert-Administrator
|
||||
$mainSource = Resolve-PackageFile -Candidates @(
|
||||
(Join-Path $PackageRoot "server\smail_windows_amd64.exe"),
|
||||
(Join-Path $PackageRoot "server\smail.exe"),
|
||||
(Join-Path $PackageRoot "out\backend\smail_windows_amd64.exe"),
|
||||
(Join-Path $PackageRoot "backend\smail_windows_amd64.exe"),
|
||||
(Join-Path $PackageRoot "backend\smail.exe"),
|
||||
(Join-Path $PackageRoot "smail_windows_amd64.exe"),
|
||||
(Join-Path $PackageRoot "smail.exe")
|
||||
) -Description "smail.exe"
|
||||
$adminSource = Resolve-PackageFile -Candidates @(
|
||||
(Join-Path $PackageRoot "server\smail-admin_windows_amd64.exe"),
|
||||
(Join-Path $PackageRoot "server\smail-admin.exe"),
|
||||
(Join-Path $PackageRoot "out\backend\smail-admin_windows_amd64.exe"),
|
||||
(Join-Path $PackageRoot "backend\smail-admin_windows_amd64.exe"),
|
||||
(Join-Path $PackageRoot "backend\smail-admin.exe"),
|
||||
(Join-Path $PackageRoot "smail-admin_windows_amd64.exe"),
|
||||
(Join-Path $PackageRoot "smail-admin.exe")
|
||||
) -Description "smail-admin.exe"
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { cp, mkdir, readdir, readFile } from 'node:fs/promises'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import path from 'node:path'
|
||||
|
||||
const root = fileURLToPath(new URL('../', import.meta.url))
|
||||
const plugin = process.argv[2] === 'telegram'
|
||||
const source = path.join(root, 'out', ...(plugin ? ['plugins', 'telegram-ui'] : ['frontend']))
|
||||
const target = path.join(root, ...(plugin ? ['plugins', 'pmail_telegram_push', 'hook', 'dist'] : ['backend', 'listen', 'http_server', 'dist']))
|
||||
|
||||
// Go 嵌入文件不能越过模块目录;这里仅同步构建中间文件,不保存运行数据。
|
||||
await readFile(path.join(source, 'index.html'))
|
||||
await mkdir(target, { recursive: true })
|
||||
for (const entry of await readdir(source)) {
|
||||
await cp(path.join(source, entry), path.join(target, entry), { recursive: true })
|
||||
}
|
||||
console.log('前端产物已生成至 out,并同步 Go 嵌入目录。')
|
||||
@@ -0,0 +1,35 @@
|
||||
param([ValidateSet('backend', 'frontend')][string]$Service = 'backend')
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$root = Split-Path -Parent $PSScriptRoot
|
||||
$logs = Join-Path $root 'test-log\runtime'
|
||||
New-Item -ItemType Directory -Path $logs -Force | Out-Null
|
||||
$stamp = Get-Date -Format 'yyyyMMdd-HHmmss-fff'
|
||||
$previousRoot = $env:SMAIL_ROOT
|
||||
try {
|
||||
if ($Service -eq 'backend') {
|
||||
$binary = Join-Path $root 'out\backend\smail-dev.exe'
|
||||
if (-not (Test-Path -LiteralPath $binary)) { throw '请先运行 deploy/build.ps1 编译后端' }
|
||||
if (Get-NetTCPConnection -State Listen -LocalPort 443 -ErrorAction SilentlyContinue) { throw '443 端口已占用,请先确认并停止旧后端' }
|
||||
# 二进制与配置分离后必须显式指定根目录,不能在 out 下初始化新数据库。
|
||||
$env:SMAIL_ROOT = Join-Path $root 'backend'
|
||||
$arguments = @('--dev-disable-admin-reset')
|
||||
$workingDirectory = $env:SMAIL_ROOT
|
||||
} else {
|
||||
if (Get-NetTCPConnection -State Listen -LocalPort 15173 -ErrorAction SilentlyContinue) { throw '15173 端口已占用,请先确认并停止旧前端' }
|
||||
$binary = (Get-Command node -ErrorAction Stop).Source
|
||||
$vite = Join-Path $root 'frontend\node_modules\vite\bin\vite.js'
|
||||
if (-not (Test-Path -LiteralPath $vite)) { throw '请先安装 frontend 的依赖' }
|
||||
$arguments = @(('"{0}"' -f $vite), '--host', '127.0.0.1', '--port', '15173', '--strictPort')
|
||||
$workingDirectory = Join-Path $root 'frontend'
|
||||
}
|
||||
$process = Start-Process -FilePath $binary -ArgumentList $arguments -WorkingDirectory $workingDirectory -WindowStyle Hidden -PassThru `
|
||||
-RedirectStandardOutput (Join-Path $logs "$Service-$stamp.stdout.log") `
|
||||
-RedirectStandardError (Join-Path $logs "$Service-$stamp.stderr.log")
|
||||
Start-Sleep -Seconds 3
|
||||
$process.Refresh()
|
||||
if ($process.HasExited) { throw "服务启动失败,请检查 test-log/runtime 中的 $Service 日志" }
|
||||
Write-Output "$Service 已启动,进程编号:$($process.Id);日志目录:test-log/runtime"
|
||||
} finally {
|
||||
$env:SMAIL_ROOT = $previousRoot
|
||||
}
|
||||
Reference in new issue
Block a user