整理项目文档与脚本目录
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
# 0.0.1 版本基线与后续迭代规则
|
||||
|
||||
更新时间:2026-06-28
|
||||
|
||||
## 版本基线
|
||||
|
||||
当前仓库代码、脚本、配置、SQL 和项目文档固定为 `0.0.1` 版本基线。
|
||||
|
||||
纳入本次基线的运行入口:
|
||||
|
||||
- `JC-ArtList-Core`:`pom.xml` 版本为 `0.0.1`。
|
||||
- `JC-ArtList-Gateway`:`pom.xml` 版本为 `0.0.1`。
|
||||
- `JC-ArtList-Frontend`:`package.json` 和 `package-lock.json` 版本为 `0.0.1`。
|
||||
- `JC-ArtList-WeChat`:以当前微信小程序项目配置、页面和脚本作为 `0.0.1` 用户端小程序基线。
|
||||
- `JC-Salon-WeChat`:以当前微信小程序项目配置、页面和脚本作为 `0.0.1` 管理师小程序基线。
|
||||
- `docs/scripts/sql/init/FingertipDesigner.sql`:作为 `0.0.1` 空库初始化 SQL 基线。
|
||||
- `docs/scripts/sql/migrations/`:作为 `0.0.1` 后续数据库版本变更脚本目录。
|
||||
|
||||
## 初始化 SQL 冻结规则
|
||||
|
||||
从 `0.0.1` 起,`docs/scripts/sql/init/FingertipDesigner.sql` 只作为空库首次初始化基线,不再在后续需求、修复或配置变更中修改。
|
||||
|
||||
后续涉及表结构、补列、索引、权限种子、系统参数、运行必需种子数据或数据修复时,必须新增版本变更 SQL,不得回写初始化 SQL。
|
||||
|
||||
## 后续迭代文件规则
|
||||
|
||||
- SQL 变更脚本放在 `docs/scripts/sql/migrations/`。
|
||||
- SQL 文件名必须使用中文,体现功能和日期,例如 `员工排班规则和例外_20260626.sql`。
|
||||
- SQL 内容必须是完整可执行脚本,包含必要的幂等判断、过程清理和明确失败条件。
|
||||
- 配置变更必须新增说明文档,放在 `docs/scripts/` 目录。
|
||||
- 配置说明文档文件名必须使用中文,体现功能和日期。
|
||||
- 脚本、配置、SQL 的新增或修改必须在对应任务的记忆和交接文档中记录原因、影响范围和验证方式。
|
||||
|
||||
## 已发现问题与处理
|
||||
|
||||
- 问题:旧记忆和交接文档仍记录“新增表字段后同步更新初始化 SQL”。
|
||||
- 原因:`0.0.1` 前的上线基线阶段曾把历史 SQL 合并回唯一初始化脚本。
|
||||
- 处理:本次将规则改为 `0.0.1` 初始化 SQL 冻结,后续变更全部通过 `docs/scripts/sql/migrations/` 和 `docs/scripts/` 中的版本化说明文件迭代。
|
||||
@@ -0,0 +1,40 @@
|
||||
# FingertipDesigner 配置整理说明
|
||||
|
||||
## 命名空间
|
||||
|
||||
- `FingertipDesigner-Dev`:开发环境配置。
|
||||
- `FingertipDesigner`:正式环境配置。
|
||||
|
||||
## 配置文件
|
||||
|
||||
- `core.yaml`:Core 服务独有配置,包括端口、业务缓存、慢请求、对象存储业务规则和 MessageHub 客户端参数。
|
||||
- `gateway.yaml`:Gateway 服务独有配置,包括端口、路由、鉴权白名单和网关慢请求参数。
|
||||
- `infra.yaml`:公共基础设施配置,包括数据库、Redis、MyBatis-Plus 和 RabbitMQ。
|
||||
- `secret.yaml`:敏感配置,包括数据库密码、Redis 密码、RabbitMQ 密码、JWT、微信小程序和对象存储密钥。
|
||||
- `logging.yaml`:公共日志配置。
|
||||
|
||||
## 本地启动配置
|
||||
|
||||
`JC-ArtList-Core` 和 `JC-ArtList-Gateway` 默认读取开发环境命名空间:
|
||||
|
||||
```powershell
|
||||
$env:NACOS_SERVER_ADDR='192.168.5.103:8848'
|
||||
$env:NACOS_NAMESPACE='FingertipDesigner-Dev'
|
||||
$env:NACOS_USERNAME='xiaowang'
|
||||
$env:NACOS_PASSWORD='122503wcy....'
|
||||
```
|
||||
|
||||
正式环境部署时设置:
|
||||
|
||||
```powershell
|
||||
$env:NACOS_SERVER_ADDR='192.168.5.101:8848,192.168.5.102:8848,192.168.10.145:8848'
|
||||
$env:NACOS_NAMESPACE='FingertipDesigner'
|
||||
```
|
||||
|
||||
如 Nacos 地址、账号、密码发生变化,通过以下环境变量覆盖:
|
||||
|
||||
```powershell
|
||||
$env:NACOS_SERVER_ADDR='192.168.5.103:8848'
|
||||
$env:NACOS_USERNAME='nacos'
|
||||
$env:NACOS_PASSWORD='122503wcy....'
|
||||
```
|
||||
@@ -0,0 +1,841 @@
|
||||
param(
|
||||
[string]$RepoRoot = (Split-Path -Parent $PSScriptRoot),
|
||||
[string]$ServerInfoPath = "",
|
||||
[switch]$DryRun,
|
||||
[switch]$Deploy,
|
||||
[switch]$UsePuttyPassword,
|
||||
[switch]$SkipBuild,
|
||||
[switch]$SkipTests,
|
||||
[switch]$AllowDirtyWorkingTree,
|
||||
[switch]$SkipDatabaseInit,
|
||||
[string]$DatabaseTargetName = "mysql02",
|
||||
[int]$DatabasePort = 3306,
|
||||
[string]$DatabaseName = "FingertipDesigner",
|
||||
[string]$DatabaseUser = "",
|
||||
[string]$DatabasePassword = "",
|
||||
[string]$InitSqlPath = "",
|
||||
[string]$CorePattern = "^JC-ArtList-Core",
|
||||
[string]$GatewayPattern = "^JC-ArtList-Gateway",
|
||||
[string]$WebTargetName = "",
|
||||
[string]$WebTargetHost = "8.137.35.61",
|
||||
[string]$CoreRemoteAppDir = "/opt/jc-artlist-core",
|
||||
[string]$GatewayRemoteAppDir = "/opt/jc-artlist-gateway",
|
||||
[string]$WebRemoteDir = "/opt/jc-artlist-frontend",
|
||||
[string]$CoreServiceName = "jc-artlist-core",
|
||||
[string]$GatewayServiceName = "jc-artlist-gateway",
|
||||
[int]$CoreHealthPort = 81,
|
||||
[int]$GatewayHealthPort = 80,
|
||||
[string]$HealthPath = "/health/check",
|
||||
[int]$HealthTimeoutSeconds = 120,
|
||||
[string]$PublicBaseUrl = "https://yunail.art",
|
||||
[string]$MavenPath = ""
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
$releaseTimestamp = Get-Date -Format "yyyyMMdd-HHmmss"
|
||||
$resolvedRepoRoot = (Resolve-Path -LiteralPath $RepoRoot).Path
|
||||
$releaseRoot = Join-Path $resolvedRepoRoot "artifacts\release"
|
||||
$releaseDir = Join-Path $releaseRoot $releaseTimestamp
|
||||
$backendDir = Join-Path $releaseDir "backend"
|
||||
$frontendDir = Join-Path $releaseDir "frontend"
|
||||
$sqlDir = Join-Path $releaseDir "sql"
|
||||
$manifestPath = Join-Path $releaseDir "manifest.json"
|
||||
$defaultInitSqlPath = Join-Path $resolvedRepoRoot "docs\scripts\sql\init\FingertipDesigner.sql"
|
||||
if (-not $InitSqlPath) {
|
||||
$InitSqlPath = $defaultInitSqlPath
|
||||
}
|
||||
|
||||
function Write-Step {
|
||||
param([string]$Message)
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "==> $Message"
|
||||
}
|
||||
|
||||
function ConvertTo-BashSingleQuoted {
|
||||
param([AllowNull()][string]$Value)
|
||||
|
||||
if ($null -eq $Value) {
|
||||
$Value = ""
|
||||
}
|
||||
return "'" + $Value.Replace("'", "'""'""'") + "'"
|
||||
}
|
||||
|
||||
function Resolve-Maven {
|
||||
param([string]$PreferredPath)
|
||||
|
||||
if ($PreferredPath -and (Test-Path -LiteralPath $PreferredPath)) {
|
||||
return (Resolve-Path -LiteralPath $PreferredPath).Path
|
||||
}
|
||||
|
||||
$fromPath = Get-Command mvn.cmd -ErrorAction SilentlyContinue
|
||||
if ($fromPath) {
|
||||
return $fromPath.Source
|
||||
}
|
||||
|
||||
$fromPath = Get-Command mvn -ErrorAction SilentlyContinue
|
||||
if ($fromPath) {
|
||||
return $fromPath.Source
|
||||
}
|
||||
|
||||
throw "找不到 Maven,请通过 -MavenPath 传入 Maven 可执行文件绝对路径。"
|
||||
}
|
||||
|
||||
function Invoke-Native {
|
||||
param(
|
||||
[string]$FilePath,
|
||||
[string[]]$Arguments,
|
||||
[string]$WorkingDirectory = "",
|
||||
[switch]$RemoteMutation,
|
||||
[switch]$Sensitive
|
||||
)
|
||||
|
||||
if ($Sensitive) {
|
||||
Write-Host ">> $FilePath <敏感参数已隐藏>"
|
||||
}
|
||||
else {
|
||||
Write-Host ">> $FilePath $($Arguments -join ' ')"
|
||||
}
|
||||
|
||||
if ($DryRun -and $RemoteMutation) {
|
||||
return
|
||||
}
|
||||
|
||||
$previousLocation = Get-Location
|
||||
try {
|
||||
if ($WorkingDirectory) {
|
||||
Set-Location -LiteralPath $WorkingDirectory
|
||||
}
|
||||
& $FilePath @Arguments
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "命令执行失败,退出码 ${LASTEXITCODE}:$FilePath"
|
||||
}
|
||||
}
|
||||
finally {
|
||||
Set-Location $previousLocation
|
||||
}
|
||||
}
|
||||
|
||||
function Read-ZipEntryText {
|
||||
param($Zip, [string]$Name)
|
||||
|
||||
$entry = $Zip.GetEntry($Name)
|
||||
if (-not $entry) {
|
||||
return $null
|
||||
}
|
||||
|
||||
$stream = $entry.Open()
|
||||
try {
|
||||
$reader = [System.IO.StreamReader]::new($stream, [System.Text.Encoding]::UTF8)
|
||||
try {
|
||||
return $reader.ReadToEnd()
|
||||
}
|
||||
finally {
|
||||
$reader.Dispose()
|
||||
}
|
||||
}
|
||||
finally {
|
||||
$stream.Dispose()
|
||||
}
|
||||
}
|
||||
|
||||
function Get-RelationshipId {
|
||||
param($Element)
|
||||
|
||||
foreach ($attribute in $Element.Attributes) {
|
||||
if ($attribute.LocalName -eq "id") {
|
||||
return $attribute.Value
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
function Get-ColumnIndex {
|
||||
param([string]$CellRef)
|
||||
|
||||
$letters = ([regex]::Match($CellRef, "^[A-Z]+")).Value
|
||||
$index = 0
|
||||
foreach ($character in $letters.ToCharArray()) {
|
||||
$index = ($index * 26) + ([int][char]$character - [int][char]"A" + 1)
|
||||
}
|
||||
return $index
|
||||
}
|
||||
|
||||
function Get-XlsxFirstSheetRows {
|
||||
param([string]$Path)
|
||||
|
||||
Add-Type -AssemblyName System.IO.Compression.FileSystem
|
||||
$zip = [System.IO.Compression.ZipFile]::OpenRead($Path)
|
||||
try {
|
||||
$sharedStrings = @()
|
||||
$sharedText = Read-ZipEntryText $zip "xl/sharedStrings.xml"
|
||||
if ($sharedText) {
|
||||
[xml]$sharedXml = $sharedText
|
||||
foreach ($sharedItem in $sharedXml.GetElementsByTagName("si")) {
|
||||
$sharedStrings += $sharedItem.InnerText
|
||||
}
|
||||
}
|
||||
|
||||
[xml]$workbookXml = Read-ZipEntryText $zip "xl/workbook.xml"
|
||||
[xml]$relsXml = Read-ZipEntryText $zip "xl/_rels/workbook.xml.rels"
|
||||
$firstSheet = $workbookXml.GetElementsByTagName("sheet").Item(0)
|
||||
if (-not $firstSheet) {
|
||||
throw "服务器清单没有工作表:$Path"
|
||||
}
|
||||
|
||||
$relationshipId = Get-RelationshipId $firstSheet
|
||||
$relationship = $null
|
||||
foreach ($candidate in $relsXml.GetElementsByTagName("Relationship")) {
|
||||
if ($candidate.GetAttribute("Id") -eq $relationshipId) {
|
||||
$relationship = $candidate
|
||||
break
|
||||
}
|
||||
}
|
||||
if (-not $relationship) {
|
||||
throw "无法解析工作表关系:$relationshipId"
|
||||
}
|
||||
|
||||
$target = $relationship.Target
|
||||
$sheetPath = if ($target.StartsWith("/")) {
|
||||
$target.TrimStart("/")
|
||||
}
|
||||
elseif ($target.StartsWith("xl/")) {
|
||||
$target
|
||||
}
|
||||
else {
|
||||
"xl/$target"
|
||||
}
|
||||
|
||||
[xml]$sheetXml = Read-ZipEntryText $zip $sheetPath
|
||||
$rows = @()
|
||||
foreach ($row in $sheetXml.GetElementsByTagName("row")) {
|
||||
$valuesByIndex = @{}
|
||||
$maxIndex = 0
|
||||
foreach ($cell in $row.GetElementsByTagName("c")) {
|
||||
$index = Get-ColumnIndex $cell.r
|
||||
$maxIndex = [Math]::Max($maxIndex, $index)
|
||||
$valueNodes = $cell.GetElementsByTagName("v")
|
||||
$valueNode = if ($valueNodes.Count -gt 0) { $valueNodes.Item(0) } else { $null }
|
||||
$value = ""
|
||||
if ($cell.GetAttribute("t") -eq "s" -and $valueNode -and $valueNode.InnerText -ne "") {
|
||||
$sharedIndex = [int]$valueNode.InnerText
|
||||
if ($sharedIndex -lt $sharedStrings.Count) {
|
||||
$value = $sharedStrings[$sharedIndex]
|
||||
}
|
||||
}
|
||||
elseif ($cell.GetAttribute("t") -eq "inlineStr") {
|
||||
$value = $cell.InnerText
|
||||
}
|
||||
elseif ($valueNode) {
|
||||
$value = $valueNode.InnerText
|
||||
}
|
||||
$valuesByIndex[$index] = $value
|
||||
}
|
||||
|
||||
if ($maxIndex -gt 0) {
|
||||
$values = for ($index = 1; $index -le $maxIndex; $index++) {
|
||||
if ($valuesByIndex.ContainsKey($index)) { $valuesByIndex[$index] } else { "" }
|
||||
}
|
||||
if (($values -join "").Trim()) {
|
||||
$rows += ,$values
|
||||
}
|
||||
}
|
||||
}
|
||||
return $rows
|
||||
}
|
||||
finally {
|
||||
$zip.Dispose()
|
||||
}
|
||||
}
|
||||
|
||||
function Get-HeaderIndex {
|
||||
param([string[]]$Header, [string[]]$Candidates)
|
||||
|
||||
foreach ($candidate in $Candidates) {
|
||||
$index = [Array]::IndexOf($Header, $candidate.ToLowerInvariant())
|
||||
if ($index -ge 0) {
|
||||
return $index
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
function Get-CellValue {
|
||||
param([object[]]$Row, [int]$Index)
|
||||
|
||||
if ($Index -lt 0 -or $Index -ge $Row.Count) {
|
||||
return ""
|
||||
}
|
||||
return ([string]$Row[$Index]).Trim()
|
||||
}
|
||||
|
||||
function Get-ServerPort {
|
||||
param([object[]]$Row, [int]$Index)
|
||||
|
||||
$value = Get-CellValue $Row $Index
|
||||
if (-not $value) {
|
||||
return 22
|
||||
}
|
||||
$value = ($value -split "[/,;,;\s]+")[0]
|
||||
$port = 0
|
||||
if (-not [int]::TryParse($value, [ref]$port)) {
|
||||
throw "服务器清单端口不是数字:$value"
|
||||
}
|
||||
return $port
|
||||
}
|
||||
|
||||
function Get-ServersFromWorkbook {
|
||||
param([string]$Path)
|
||||
|
||||
if (-not (Test-Path -LiteralPath $Path)) {
|
||||
throw "服务器清单不存在:$Path"
|
||||
}
|
||||
|
||||
$rows = @(Get-XlsxFirstSheetRows (Resolve-Path -LiteralPath $Path).Path)
|
||||
if ($rows.Count -lt 2) {
|
||||
throw "服务器清单没有数据行:$Path"
|
||||
}
|
||||
|
||||
$header = @($rows[0] | ForEach-Object { ([string]$_).Trim().ToLowerInvariant() })
|
||||
$nameIndex = Get-HeaderIndex $header @("name", "名称", "服务器名称")
|
||||
$hostIndex = Get-HeaderIndex $header @("host", "ip", "ip/域名", "ip地址", "主机", "公网ip", "内网ip")
|
||||
$portIndex = Get-HeaderIndex $header @("port", "端口", "ssh端口")
|
||||
$userIndex = Get-HeaderIndex $header @("user", "username", "用户名", "账号")
|
||||
$passwordIndex = Get-HeaderIndex $header @("password", "密码", "口令")
|
||||
$purposeIndex = Get-HeaderIndex $header @("purpose", "功能定位", "业务作用", "用途", "类型")
|
||||
$noteIndex = Get-HeaderIndex $header @("note", "备注", "说明")
|
||||
$environmentIndex = Get-HeaderIndex $header @("environment", "环境", "所属中心")
|
||||
|
||||
foreach ($row in $rows[1..($rows.Count - 1)]) {
|
||||
if ((-not (Get-CellValue $row $nameIndex)) -or (-not (Get-CellValue $row $hostIndex))) {
|
||||
continue
|
||||
}
|
||||
[pscustomobject]@{
|
||||
Name = Get-CellValue $row $nameIndex
|
||||
Host = Get-CellValue $row $hostIndex
|
||||
Port = Get-ServerPort $row $portIndex
|
||||
User = Get-CellValue $row $userIndex
|
||||
Password = Get-CellValue $row $passwordIndex
|
||||
Purpose = Get-CellValue $row $purposeIndex
|
||||
Note = Get-CellValue $row $noteIndex
|
||||
Environment = Get-CellValue $row $environmentIndex
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function Resolve-ServerInfoPath {
|
||||
param([string]$ExplicitPath)
|
||||
|
||||
if ($ExplicitPath) {
|
||||
if (-not (Test-Path -LiteralPath $ExplicitPath)) {
|
||||
throw "服务器清单不存在:$ExplicitPath"
|
||||
}
|
||||
return (Resolve-Path -LiteralPath $ExplicitPath).Path
|
||||
}
|
||||
|
||||
$codeRoot = "Y:\code"
|
||||
if (-not (Test-Path -LiteralPath $codeRoot)) {
|
||||
throw "未传入 -ServerInfoPath,且默认目录不存在:$codeRoot"
|
||||
}
|
||||
|
||||
$workbooks = @(Get-ChildItem -LiteralPath $codeRoot -Filter "*.xlsx" -File | Sort-Object LastWriteTime -Descending)
|
||||
if ($workbooks.Count -eq 0) {
|
||||
throw "默认目录下没有服务器清单 xlsx,请显式传入 -ServerInfoPath。"
|
||||
}
|
||||
|
||||
return $workbooks[0].FullName
|
||||
}
|
||||
|
||||
function Assert-ProductionTarget {
|
||||
param([object[]]$Servers)
|
||||
|
||||
$blocked = @($Servers | Where-Object { $_.Name -match "^(?i:MessageHub|mysql|nacos|redis|rabbitmq)" })
|
||||
if ($blocked.Count -gt 0) {
|
||||
throw "拒绝把应用发布到基础设施节点:$($blocked.Name -join ', ')"
|
||||
}
|
||||
|
||||
$knownNonProduction = @($Servers | Where-Object { $_.Environment -match "(?i)\b(dev|test|local|staging)\b" })
|
||||
if ($knownNonProduction.Count -gt 0) {
|
||||
throw "拒绝发布到非生产环境节点:$($knownNonProduction.Name -join ', ')"
|
||||
}
|
||||
}
|
||||
|
||||
function Get-SshTarget {
|
||||
param([object]$Server)
|
||||
|
||||
return "$($Server.User)@$($Server.Host)"
|
||||
}
|
||||
|
||||
function Invoke-RemoteShell {
|
||||
param(
|
||||
[object]$Server,
|
||||
[string]$Command,
|
||||
[switch]$Sensitive
|
||||
)
|
||||
|
||||
if ($UsePuttyPassword) {
|
||||
$plink = Get-Command plink -ErrorAction SilentlyContinue
|
||||
if ((-not $DryRun) -and (-not $plink)) {
|
||||
throw "找不到 PuTTY plink,请安装 PuTTY 工具或改用 SSH key。"
|
||||
}
|
||||
$plinkPath = if ($plink) { $plink.Source } else { "plink" }
|
||||
Invoke-Native $plinkPath @("-batch", "-ssh", "-P", [string]$Server.Port, "-l", $Server.User, "-pw", $Server.Password, $Server.Host, $Command) -Sensitive:$Sensitive -RemoteMutation
|
||||
}
|
||||
else {
|
||||
Invoke-Native "ssh" @("-o", "BatchMode=yes", "-o", "StrictHostKeyChecking=accept-new", "-p", [string]$Server.Port, (Get-SshTarget $Server), $Command) -Sensitive:$Sensitive -RemoteMutation
|
||||
}
|
||||
}
|
||||
|
||||
function Copy-FileToRemote {
|
||||
param(
|
||||
[string]$LocalPath,
|
||||
[object]$Server,
|
||||
[string]$RemotePath,
|
||||
[switch]$Sensitive
|
||||
)
|
||||
|
||||
if (-not (Test-Path -LiteralPath $LocalPath)) {
|
||||
throw "本地上传文件不存在:$LocalPath"
|
||||
}
|
||||
|
||||
if ($UsePuttyPassword) {
|
||||
$pscp = Get-Command pscp -ErrorAction SilentlyContinue
|
||||
if ((-not $DryRun) -and (-not $pscp)) {
|
||||
throw "找不到 PuTTY pscp,请安装 PuTTY 工具或改用 SSH key。"
|
||||
}
|
||||
$pscpPath = if ($pscp) { $pscp.Source } else { "pscp" }
|
||||
Invoke-Native $pscpPath @("-batch", "-P", [string]$Server.Port, "-pw", $Server.Password, $LocalPath, "$(Get-SshTarget $Server):$RemotePath") -Sensitive:$Sensitive -RemoteMutation
|
||||
}
|
||||
else {
|
||||
Invoke-Native "scp" @("-o", "BatchMode=yes", "-o", "StrictHostKeyChecking=accept-new", "-P", [string]$Server.Port, $LocalPath, "$(Get-SshTarget $Server):$RemotePath") -Sensitive:$Sensitive -RemoteMutation
|
||||
}
|
||||
}
|
||||
|
||||
function Invoke-RemoteShellMany {
|
||||
param(
|
||||
[object[]]$Servers,
|
||||
[string]$Command,
|
||||
[string]$GroupName
|
||||
)
|
||||
|
||||
foreach ($server in $Servers) {
|
||||
Write-Host "$GroupName target: $($server.Name) $($server.User)@$($server.Host):$($server.Port)"
|
||||
Invoke-RemoteShell $server $Command
|
||||
}
|
||||
}
|
||||
|
||||
function Test-GitState {
|
||||
Push-Location $resolvedRepoRoot
|
||||
try {
|
||||
$commit = (& git rev-parse HEAD).Trim()
|
||||
$branch = (& git branch --show-current).Trim()
|
||||
$status = @(& git status --porcelain)
|
||||
if ($status.Count -gt 0) {
|
||||
Write-Warning "当前工作区有 $($status.Count) 个变更路径。"
|
||||
$status | Select-Object -First 40 | ForEach-Object { Write-Warning $_ }
|
||||
if ($Deploy -and (-not $DryRun) -and (-not $AllowDirtyWorkingTree)) {
|
||||
throw "拒绝从脏工作区发布生产,请先提交/暂存,或显式传入 -AllowDirtyWorkingTree。"
|
||||
}
|
||||
}
|
||||
return [pscustomobject]@{
|
||||
Branch = $branch
|
||||
Commit = $commit
|
||||
Dirty = $status.Count -gt 0
|
||||
ChangedPathCount = $status.Count
|
||||
}
|
||||
}
|
||||
finally {
|
||||
Pop-Location
|
||||
}
|
||||
}
|
||||
|
||||
function Assert-InitSqlSafe {
|
||||
param([string]$Path)
|
||||
|
||||
if (-not (Test-Path -LiteralPath $Path)) {
|
||||
throw "初始化 SQL 不存在:$Path"
|
||||
}
|
||||
|
||||
$content = Get-Content -LiteralPath $Path -Raw
|
||||
if ($content -notmatch "CREATE DATABASE IF NOT EXISTS\s+FingertipDesigner") {
|
||||
throw "初始化 SQL 未声明目标库 FingertipDesigner:$Path"
|
||||
}
|
||||
if ($content -notmatch "(?im)^\s*use\s+FingertipDesigner\s*;") {
|
||||
throw "初始化 SQL 未切换到目标库 FingertipDesigner:$Path"
|
||||
}
|
||||
|
||||
$dangerousMatch = [regex]::Match($content, "(?im)^\s*(drop\s+(database|schema|table)|truncate\s+table)\b")
|
||||
if ($dangerousMatch.Success) {
|
||||
throw "初始化 SQL 包含危险语句:$($dangerousMatch.Value)"
|
||||
}
|
||||
}
|
||||
|
||||
function Build-ReleasePackage {
|
||||
param([object]$GitState)
|
||||
|
||||
New-Item -ItemType Directory -Force -Path $backendDir, $frontendDir, $sqlDir | Out-Null
|
||||
$maven = Resolve-Maven $MavenPath
|
||||
|
||||
if (-not $SkipBuild) {
|
||||
$mavenArgs = @("-q", "package")
|
||||
if ($SkipTests) {
|
||||
$mavenArgs += "-DskipTests"
|
||||
}
|
||||
|
||||
Write-Step "构建 JC-ArtList-Core"
|
||||
Invoke-Native $maven $mavenArgs (Join-Path $resolvedRepoRoot "JC-ArtList-Core")
|
||||
|
||||
Write-Step "构建 JC-ArtList-Gateway"
|
||||
Invoke-Native $maven $mavenArgs (Join-Path $resolvedRepoRoot "JC-ArtList-Gateway")
|
||||
|
||||
Write-Step "构建 JC-ArtList-Frontend"
|
||||
$frontendRoot = Join-Path $resolvedRepoRoot "JC-ArtList-Frontend"
|
||||
if (-not (Test-Path -LiteralPath (Join-Path $frontendRoot "node_modules"))) {
|
||||
Invoke-Native "npm" @("ci") $frontendRoot
|
||||
}
|
||||
Invoke-Native "npm" @("run", "build") $frontendRoot
|
||||
}
|
||||
|
||||
$coreJar = Join-Path $resolvedRepoRoot "JC-ArtList-Core\target\JC-ArtList-Core.jar"
|
||||
$gatewayJar = Join-Path $resolvedRepoRoot "JC-ArtList-Gateway\target\JC-ArtList-Gateway.jar"
|
||||
$frontendDist = Join-Path $resolvedRepoRoot "JC-ArtList-Frontend\dist"
|
||||
foreach ($requiredPath in @($coreJar, $gatewayJar, $frontendDist, $InitSqlPath)) {
|
||||
if (-not (Test-Path -LiteralPath $requiredPath)) {
|
||||
throw "缺少发布产物:$requiredPath"
|
||||
}
|
||||
}
|
||||
|
||||
$coreArtifact = Join-Path $backendDir "JC-ArtList-Core.jar"
|
||||
$gatewayArtifact = Join-Path $backendDir "JC-ArtList-Gateway.jar"
|
||||
$frontendArtifact = Join-Path $frontendDir "jc-artlist-frontend-dist.tar.gz"
|
||||
$sqlArtifact = Join-Path $sqlDir "FingertipDesigner.sql"
|
||||
Copy-Item -LiteralPath $coreJar -Destination $coreArtifact -Force
|
||||
Copy-Item -LiteralPath $gatewayJar -Destination $gatewayArtifact -Force
|
||||
Copy-Item -LiteralPath $InitSqlPath -Destination $sqlArtifact -Force
|
||||
|
||||
$tar = Get-Command tar -ErrorAction SilentlyContinue
|
||||
if (-not $tar) {
|
||||
throw "缺少 tar,无法打包前端 dist。"
|
||||
}
|
||||
if (Test-Path -LiteralPath $frontendArtifact) {
|
||||
Remove-Item -LiteralPath $frontendArtifact -Force
|
||||
}
|
||||
Invoke-Native $tar.Source @("-czf", $frontendArtifact, "-C", (Join-Path $resolvedRepoRoot "JC-ArtList-Frontend"), "dist")
|
||||
|
||||
$hashes = foreach ($artifact in @($coreArtifact, $gatewayArtifact, $frontendArtifact, $sqlArtifact)) {
|
||||
$hash = Get-FileHash -LiteralPath $artifact -Algorithm SHA256
|
||||
[pscustomobject]@{
|
||||
Path = $artifact.Replace($resolvedRepoRoot, "").TrimStart("\", "/")
|
||||
Sha256 = $hash.Hash
|
||||
}
|
||||
}
|
||||
|
||||
return [pscustomobject]@{
|
||||
Directory = $releaseDir
|
||||
CoreJar = $coreArtifact
|
||||
GatewayJar = $gatewayArtifact
|
||||
FrontendArchive = $frontendArtifact
|
||||
InitSql = $sqlArtifact
|
||||
Hashes = @($hashes)
|
||||
Git = $GitState
|
||||
}
|
||||
}
|
||||
|
||||
function Get-BackendDeployCommand {
|
||||
param(
|
||||
[string]$RemoteAppDir,
|
||||
[string]$ServiceName,
|
||||
[string]$ReleaseName,
|
||||
[int]$HealthPort
|
||||
)
|
||||
|
||||
$appDir = ConvertTo-BashSingleQuoted $RemoteAppDir
|
||||
$service = ConvertTo-BashSingleQuoted $ServiceName
|
||||
$releaseName = ConvertTo-BashSingleQuoted $ReleaseName
|
||||
$healthPath = ConvertTo-BashSingleQuoted $HealthPath
|
||||
$timeout = [string]$HealthTimeoutSeconds
|
||||
$healthPortText = [string]$HealthPort
|
||||
|
||||
return @"
|
||||
set -e
|
||||
APP_DIR=$appDir
|
||||
SERVICE=$service
|
||||
RELEASE_NAME=$releaseName
|
||||
HEALTH_PATH=$healthPath
|
||||
HEALTH_PORT=$healthPortText
|
||||
HEALTH_TIMEOUT=$timeout
|
||||
RELEASE="`$APP_DIR/releases/`$RELEASE_NAME"
|
||||
BACKUP_NAME="app-$releaseTimestamp.jar"
|
||||
mkdir -p "`$APP_DIR/releases" "`$APP_DIR/backups" "`$APP_DIR/logs"
|
||||
test -f "`$RELEASE"
|
||||
if command -v systemctl >/dev/null 2>&1 && systemctl list-unit-files | grep -q "^`$SERVICE.service"; then
|
||||
systemctl stop "`$SERVICE" || true
|
||||
fi
|
||||
if [ -f "`$APP_DIR/app.jar" ]; then
|
||||
cp "`$APP_DIR/app.jar" "`$APP_DIR/backups/`$BACKUP_NAME"
|
||||
fi
|
||||
cp "`$RELEASE" "`$APP_DIR/app.jar"
|
||||
if command -v systemctl >/dev/null 2>&1 && systemctl list-unit-files | grep -q "^`$SERVICE.service"; then
|
||||
systemctl start "`$SERVICE"
|
||||
else
|
||||
if [ -f "`$APP_DIR/app.pid" ]; then kill "`$(cat "`$APP_DIR/app.pid")" >/dev/null 2>&1 || true; fi
|
||||
pkill -f "java .*`$APP_DIR/app.jar" >/dev/null 2>&1 || true
|
||||
nohup java -jar "`$APP_DIR/app.jar" > "`$APP_DIR/logs/app-$releaseTimestamp.log" 2>&1 &
|
||||
echo `$! > "`$APP_DIR/app.pid"
|
||||
fi
|
||||
deadline=`$((`$(date +%s) + `$HEALTH_TIMEOUT))
|
||||
until curl -fsS "http://127.0.0.1:`$HEALTH_PORT`$HEALTH_PATH" >/tmp/fingertip-designer-health.out 2>/tmp/fingertip-designer-health.err; do
|
||||
if [ "`$(date +%s)" -ge "`$deadline" ]; then
|
||||
echo "Health check failed for `$SERVICE on port `$HEALTH_PORT"
|
||||
cat /tmp/fingertip-designer-health.err || true
|
||||
if command -v systemctl >/dev/null 2>&1; then journalctl -u "`$SERVICE" -n 80 --no-pager || true; fi
|
||||
exit 43
|
||||
fi
|
||||
sleep 3
|
||||
done
|
||||
cat /tmp/fingertip-designer-health.out
|
||||
"@
|
||||
}
|
||||
|
||||
function Publish-BackendGroup {
|
||||
param(
|
||||
[string]$GroupName,
|
||||
[object[]]$Servers,
|
||||
[string]$ArtifactPath,
|
||||
[string]$RemoteAppDir,
|
||||
[string]$ServiceName,
|
||||
[int]$HealthPort
|
||||
)
|
||||
|
||||
$artifactBaseName = [System.IO.Path]::GetFileNameWithoutExtension($ArtifactPath)
|
||||
$releaseName = "$artifactBaseName-$releaseTimestamp.jar"
|
||||
$quotedRemoteAppDir = ConvertTo-BashSingleQuoted $RemoteAppDir
|
||||
Write-Step "准备 $GroupName 目标机器"
|
||||
foreach ($server in $Servers) {
|
||||
Write-Host "$GroupName target: $($server.Name) $($server.User)@$($server.Host):$($server.Port)"
|
||||
Invoke-RemoteShell $server "mkdir -p $quotedRemoteAppDir/releases $quotedRemoteAppDir/backups $quotedRemoteAppDir/logs"
|
||||
Copy-FileToRemote $ArtifactPath $server "$RemoteAppDir/releases/$releaseName"
|
||||
}
|
||||
|
||||
Write-Step "切换 $GroupName 发布版本"
|
||||
$deployCommand = Get-BackendDeployCommand $RemoteAppDir $ServiceName $releaseName $HealthPort
|
||||
Invoke-RemoteShellMany $Servers $deployCommand $GroupName
|
||||
}
|
||||
|
||||
function Get-WebDeployCommand {
|
||||
param([string]$ArchiveName)
|
||||
|
||||
$webDir = ConvertTo-BashSingleQuoted $WebRemoteDir
|
||||
$archiveName = ConvertTo-BashSingleQuoted $ArchiveName
|
||||
return @"
|
||||
set -e
|
||||
WEB_DIR=$webDir
|
||||
ARCHIVE_NAME=$archiveName
|
||||
RELEASE_BASE="`$WEB_DIR/releases/$releaseTimestamp"
|
||||
ARCHIVE="`$WEB_DIR/releases/`$ARCHIVE_NAME"
|
||||
mkdir -p "`$RELEASE_BASE"
|
||||
if [ -L "`$WEB_DIR/current" ]; then readlink "`$WEB_DIR/current" > "`$WEB_DIR/previous-release.txt"; fi
|
||||
tar -xzf "`$ARCHIVE" -C "`$RELEASE_BASE"
|
||||
if [ -d "`$RELEASE_BASE/dist" ]; then
|
||||
TARGET="`$RELEASE_BASE/dist"
|
||||
else
|
||||
TARGET="`$RELEASE_BASE"
|
||||
fi
|
||||
ln -sfn "`$TARGET" "`$WEB_DIR/current"
|
||||
nginx -t
|
||||
if command -v systemctl >/dev/null 2>&1 && systemctl list-unit-files | grep -q "^nginx.service"; then
|
||||
systemctl reload nginx
|
||||
else
|
||||
nginx -s reload
|
||||
fi
|
||||
echo "Web current -> `$TARGET"
|
||||
"@
|
||||
}
|
||||
|
||||
function Publish-Web {
|
||||
param([object]$Server, [string]$ArchivePath)
|
||||
|
||||
$archiveName = "jc-artlist-frontend-dist-$releaseTimestamp.tar.gz"
|
||||
$quotedWebRemoteDir = ConvertTo-BashSingleQuoted $WebRemoteDir
|
||||
Write-Step "准备 Web 目标机器"
|
||||
Invoke-RemoteShell $Server "mkdir -p $quotedWebRemoteDir/releases"
|
||||
Copy-FileToRemote $ArchivePath $Server "$WebRemoteDir/releases/$archiveName"
|
||||
|
||||
Write-Step "切换 Web 发布版本"
|
||||
Invoke-RemoteShell $Server (Get-WebDeployCommand $archiveName)
|
||||
}
|
||||
|
||||
function Initialize-ProductionDatabase {
|
||||
param([object]$DatabaseServer, [string]$SqlArtifact)
|
||||
|
||||
Assert-InitSqlSafe $SqlArtifact
|
||||
|
||||
$dbUserValue = if ($DatabaseUser) { $DatabaseUser } else { $DatabaseServer.User }
|
||||
$dbPasswordValue = if ($DatabasePassword) { $DatabasePassword } else { $DatabaseServer.Password }
|
||||
if (-not $dbUserValue) {
|
||||
throw "数据库用户名为空,请传入 -DatabaseUser 或在服务器清单中填写。"
|
||||
}
|
||||
|
||||
$remoteSqlPath = "/tmp/fingertip-designer-init-$releaseTimestamp.sql"
|
||||
Write-Step "初始化生产空库"
|
||||
Write-Host "数据库目标:$($DatabaseServer.Name) $($DatabaseServer.Host):$DatabasePort/$DatabaseName"
|
||||
Invoke-RemoteShell $DatabaseServer "rm -f '$remoteSqlPath'"
|
||||
Copy-FileToRemote $SqlArtifact $DatabaseServer $remoteSqlPath -Sensitive
|
||||
|
||||
$dbName = ConvertTo-BashSingleQuoted $DatabaseName
|
||||
$dbUser = ConvertTo-BashSingleQuoted $dbUserValue
|
||||
$dbPassword = ConvertTo-BashSingleQuoted $dbPasswordValue
|
||||
$dbPort = [string]$DatabasePort
|
||||
$sqlFile = ConvertTo-BashSingleQuoted $remoteSqlPath
|
||||
$command = @'
|
||||
set -e
|
||||
DB_NAME=__DB_NAME__
|
||||
DB_PORT=__DB_PORT__
|
||||
DB_USER=__DB_USER__
|
||||
SQL_FILE=__SQL_FILE__
|
||||
export MYSQL_PWD=__DB_PASSWORD__
|
||||
if ! command -v mysql >/dev/null 2>&1; then
|
||||
echo "mysql client not found on database host"
|
||||
exit 48
|
||||
fi
|
||||
mysql -h 127.0.0.1 -P "$DB_PORT" -u"$DB_USER" --default-character-set=utf8mb4 --batch --skip-column-names -e "CREATE DATABASE IF NOT EXISTS \`$DB_NAME\` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
|
||||
TABLE_COUNT=$(mysql -h 127.0.0.1 -P "$DB_PORT" -u"$DB_USER" --default-character-set=utf8mb4 --batch --skip-column-names -e "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema='${DB_NAME}';")
|
||||
if [ "$TABLE_COUNT" != "0" ]; then
|
||||
echo "Database ${DB_NAME} is not empty: ${TABLE_COUNT} tables. Refusing initialization."
|
||||
rm -f "$SQL_FILE"
|
||||
unset MYSQL_PWD
|
||||
exit 49
|
||||
fi
|
||||
mysql -h 127.0.0.1 -P "$DB_PORT" -u"$DB_USER" --default-character-set=utf8mb4 < "$SQL_FILE"
|
||||
ADMIN_COUNT=$(mysql -h 127.0.0.1 -P "$DB_PORT" -u"$DB_USER" --default-character-set=utf8mb4 --batch --skip-column-names "$DB_NAME" -e "SELECT COUNT(*) FROM t_user WHERE account='xiaowang';")
|
||||
rm -f "$SQL_FILE"
|
||||
unset MYSQL_PWD
|
||||
echo "Database initialized. Admin account rows: ${ADMIN_COUNT}"
|
||||
'@
|
||||
$command = $command.Replace("__DB_NAME__", $dbName)
|
||||
$command = $command.Replace("__DB_PORT__", $dbPort)
|
||||
$command = $command.Replace("__DB_USER__", $dbUser)
|
||||
$command = $command.Replace("__DB_PASSWORD__", $dbPassword)
|
||||
$command = $command.Replace("__SQL_FILE__", $sqlFile)
|
||||
Invoke-RemoteShell $DatabaseServer $command -Sensitive
|
||||
}
|
||||
|
||||
function Write-ReleaseManifest {
|
||||
param(
|
||||
[object]$Package,
|
||||
[object[]]$CoreServers,
|
||||
[object[]]$GatewayServers,
|
||||
[object]$WebServer,
|
||||
[object]$DatabaseServer,
|
||||
[string]$ResolvedServerInfoPath
|
||||
)
|
||||
|
||||
$manifest = [pscustomobject]@{
|
||||
releaseTimestamp = $releaseTimestamp
|
||||
repoRoot = $resolvedRepoRoot
|
||||
git = $Package.Git
|
||||
artifacts = $Package.Hashes
|
||||
targets = [pscustomobject]@{
|
||||
core = @($CoreServers | Select-Object Name, Host, Port, User, Purpose, Environment)
|
||||
gateway = @($GatewayServers | Select-Object Name, Host, Port, User, Purpose, Environment)
|
||||
web = $WebServer | Select-Object Name, Host, Port, User, Purpose, Environment
|
||||
database = if ($DatabaseServer) { $DatabaseServer | Select-Object Name, Host, Port, User, Purpose, Environment } else { $null }
|
||||
}
|
||||
parameters = [pscustomobject]@{
|
||||
initializeDatabase = -not [bool]$SkipDatabaseInit
|
||||
databaseName = $DatabaseName
|
||||
serverInfoPath = $ResolvedServerInfoPath
|
||||
coreRemoteAppDir = $CoreRemoteAppDir
|
||||
gatewayRemoteAppDir = $GatewayRemoteAppDir
|
||||
webRemoteDir = $WebRemoteDir
|
||||
publicBaseUrl = $PublicBaseUrl
|
||||
managerMiniProgramApi = "$PublicBaseUrl/api/admin"
|
||||
nacosNamespace = "FingertipDesigner"
|
||||
dryRun = [bool]$DryRun
|
||||
deploy = [bool]$Deploy
|
||||
}
|
||||
}
|
||||
$manifest | ConvertTo-Json -Depth 8 | Set-Content -LiteralPath $manifestPath -Encoding UTF8
|
||||
Write-Host "Manifest: $manifestPath"
|
||||
}
|
||||
|
||||
function Invoke-PublicSmokeTests {
|
||||
if ($DryRun) {
|
||||
Write-Host "DryRun public smoke tests:"
|
||||
Write-Host "GET $PublicBaseUrl/health/check"
|
||||
Write-Host "GET $PublicBaseUrl/api/shop/list"
|
||||
return
|
||||
}
|
||||
|
||||
Write-Step "生产公开冒烟"
|
||||
foreach ($url in @("$PublicBaseUrl/health/check", "$PublicBaseUrl/api/shop/list")) {
|
||||
Write-Host "GET $url"
|
||||
$response = Invoke-WebRequest -Uri $url -UseBasicParsing -TimeoutSec 20
|
||||
Write-Host "Status $($response.StatusCode) Length $($response.RawContentLength)"
|
||||
}
|
||||
}
|
||||
|
||||
Write-Step "读取服务器清单"
|
||||
$resolvedServerInfoPath = Resolve-ServerInfoPath $ServerInfoPath
|
||||
$servers = @(Get-ServersFromWorkbook $resolvedServerInfoPath)
|
||||
$coreServers = @($servers | Where-Object { $_.Name -match $CorePattern })
|
||||
$gatewayServers = @($servers | Where-Object { $_.Name -match $GatewayPattern })
|
||||
$webServers = @(if ($WebTargetName) {
|
||||
$servers | Where-Object { $_.Name -eq $WebTargetName }
|
||||
}
|
||||
else {
|
||||
$servers | Where-Object { $_.Host -eq $WebTargetHost }
|
||||
})
|
||||
$databaseServers = @($servers | Where-Object { $_.Name -eq $DatabaseTargetName })
|
||||
|
||||
if ($coreServers.Count -eq 0) {
|
||||
throw "没有匹配到 Core 服务器,匹配规则:$CorePattern"
|
||||
}
|
||||
if ($gatewayServers.Count -eq 0) {
|
||||
throw "没有匹配到 Gateway 服务器,匹配规则:$GatewayPattern"
|
||||
}
|
||||
if ($webServers.Count -ne 1) {
|
||||
$webSelector = if ($WebTargetName) { "名称 $WebTargetName" } else { "主机 $WebTargetHost" }
|
||||
throw "Web 目标必须唯一,当前按 $webSelector 找到 $($webServers.Count) 个。"
|
||||
}
|
||||
if ((-not $SkipDatabaseInit) -and $databaseServers.Count -ne 1) {
|
||||
throw "数据库初始化目标必须唯一,当前按 $DatabaseTargetName 找到 $($databaseServers.Count) 个。"
|
||||
}
|
||||
|
||||
Assert-ProductionTarget (@($coreServers) + @($gatewayServers) + @($webServers))
|
||||
$databaseServer = if (-not $SkipDatabaseInit) { $databaseServers[0] } else { $null }
|
||||
|
||||
Write-Host "服务器清单:$resolvedServerInfoPath"
|
||||
@($coreServers + $gatewayServers + $webServers) | Select-Object Name, Host, Port, User, Purpose, Environment | Format-Table -AutoSize
|
||||
if ($databaseServer) {
|
||||
Write-Host "数据库初始化目标:"
|
||||
$databaseServer | Select-Object Name, Host, Port, User, Purpose, Environment | Format-Table -AutoSize
|
||||
}
|
||||
|
||||
Write-Step "检查工作区"
|
||||
$gitState = Test-GitState
|
||||
|
||||
Write-Step "构建发布包"
|
||||
$package = Build-ReleasePackage $gitState
|
||||
Write-ReleaseManifest $package $coreServers $gatewayServers $webServers[0] $databaseServer $resolvedServerInfoPath
|
||||
|
||||
if (-not $Deploy) {
|
||||
Write-Host "发布包已生成。传入 -Deploy 才会发布到生产;传入 -DryRun 可打印远程动作但不修改远端。"
|
||||
exit 0
|
||||
}
|
||||
|
||||
if (-not $SkipDatabaseInit) {
|
||||
Initialize-ProductionDatabase $databaseServer $package.InitSql
|
||||
}
|
||||
else {
|
||||
Write-Host "已跳过数据库初始化。"
|
||||
}
|
||||
|
||||
Publish-BackendGroup "Core" $coreServers $package.CoreJar $CoreRemoteAppDir $CoreServiceName $CoreHealthPort
|
||||
Publish-BackendGroup "Gateway" $gatewayServers $package.GatewayJar $GatewayRemoteAppDir $GatewayServiceName $GatewayHealthPort
|
||||
Publish-Web $webServers[0] $package.FrontendArchive
|
||||
Invoke-PublicSmokeTests
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "FingertipDesigner 生产发布流程完成。"
|
||||
@@ -0,0 +1,841 @@
|
||||
param(
|
||||
[string]$RepoRoot = (Split-Path -Parent $PSScriptRoot),
|
||||
[string]$ServerInfoPath = "",
|
||||
[switch]$DryRun,
|
||||
[switch]$Deploy,
|
||||
[switch]$UsePuttyPassword,
|
||||
[switch]$SkipBuild,
|
||||
[switch]$SkipTests,
|
||||
[switch]$AllowDirtyWorkingTree,
|
||||
[switch]$SkipDatabaseInit,
|
||||
[string]$DatabaseTargetName = "mysql02",
|
||||
[int]$DatabasePort = 3306,
|
||||
[string]$DatabaseName = "jayucloud_salon",
|
||||
[string]$DatabaseUser = "",
|
||||
[string]$DatabasePassword = "",
|
||||
[string]$InitSqlPath = "",
|
||||
[string]$CorePattern = "^JC-Salon-Core",
|
||||
[string]$GatewayPattern = "^JC-Salon-Gateway",
|
||||
[string]$WebTargetName = "",
|
||||
[string]$WebTargetHost = "8.137.35.61",
|
||||
[string]$CoreRemoteAppDir = "/opt/jc-salon-core",
|
||||
[string]$GatewayRemoteAppDir = "/opt/jc-salon-gateway",
|
||||
[string]$WebRemoteDir = "/opt/jc-salon-frontend",
|
||||
[string]$CoreServiceName = "jc-salon-core",
|
||||
[string]$GatewayServiceName = "jc-salon-gateway",
|
||||
[int]$CoreHealthPort = 81,
|
||||
[int]$GatewayHealthPort = 80,
|
||||
[string]$HealthPath = "/health/check",
|
||||
[int]$HealthTimeoutSeconds = 120,
|
||||
[string]$PublicBaseUrl = "https://salon.yunail.art",
|
||||
[string]$MavenPath = ""
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
$releaseTimestamp = Get-Date -Format "yyyyMMdd-HHmmss"
|
||||
$resolvedRepoRoot = (Resolve-Path -LiteralPath $RepoRoot).Path
|
||||
$releaseRoot = Join-Path $resolvedRepoRoot "artifacts\release"
|
||||
$releaseDir = Join-Path $releaseRoot $releaseTimestamp
|
||||
$backendDir = Join-Path $releaseDir "backend"
|
||||
$frontendDir = Join-Path $releaseDir "frontend"
|
||||
$sqlDir = Join-Path $releaseDir "sql"
|
||||
$manifestPath = Join-Path $releaseDir "manifest.json"
|
||||
$defaultInitSqlPath = Join-Path $resolvedRepoRoot "docs\scripts\sql\migrations\20260825-双端独立数据库\店务独立数据库_20260825.sql"
|
||||
if (-not $InitSqlPath) {
|
||||
$InitSqlPath = $defaultInitSqlPath
|
||||
}
|
||||
|
||||
function Write-Step {
|
||||
param([string]$Message)
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "==> $Message"
|
||||
}
|
||||
|
||||
function ConvertTo-BashSingleQuoted {
|
||||
param([AllowNull()][string]$Value)
|
||||
|
||||
if ($null -eq $Value) {
|
||||
$Value = ""
|
||||
}
|
||||
return "'" + $Value.Replace("'", "'""'""'") + "'"
|
||||
}
|
||||
|
||||
function Resolve-Maven {
|
||||
param([string]$PreferredPath)
|
||||
|
||||
if ($PreferredPath -and (Test-Path -LiteralPath $PreferredPath)) {
|
||||
return (Resolve-Path -LiteralPath $PreferredPath).Path
|
||||
}
|
||||
|
||||
$fromPath = Get-Command mvn.cmd -ErrorAction SilentlyContinue
|
||||
if ($fromPath) {
|
||||
return $fromPath.Source
|
||||
}
|
||||
|
||||
$fromPath = Get-Command mvn -ErrorAction SilentlyContinue
|
||||
if ($fromPath) {
|
||||
return $fromPath.Source
|
||||
}
|
||||
|
||||
throw "找不到 Maven,请通过 -MavenPath 传入 Maven 可执行文件绝对路径。"
|
||||
}
|
||||
|
||||
function Invoke-Native {
|
||||
param(
|
||||
[string]$FilePath,
|
||||
[string[]]$Arguments,
|
||||
[string]$WorkingDirectory = "",
|
||||
[switch]$RemoteMutation,
|
||||
[switch]$Sensitive
|
||||
)
|
||||
|
||||
if ($Sensitive) {
|
||||
Write-Host ">> $FilePath <敏感参数已隐藏>"
|
||||
}
|
||||
else {
|
||||
Write-Host ">> $FilePath $($Arguments -join ' ')"
|
||||
}
|
||||
|
||||
if ($DryRun -and $RemoteMutation) {
|
||||
return
|
||||
}
|
||||
|
||||
$previousLocation = Get-Location
|
||||
try {
|
||||
if ($WorkingDirectory) {
|
||||
Set-Location -LiteralPath $WorkingDirectory
|
||||
}
|
||||
& $FilePath @Arguments
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "命令执行失败,退出码 ${LASTEXITCODE}:$FilePath"
|
||||
}
|
||||
}
|
||||
finally {
|
||||
Set-Location $previousLocation
|
||||
}
|
||||
}
|
||||
|
||||
function Read-ZipEntryText {
|
||||
param($Zip, [string]$Name)
|
||||
|
||||
$entry = $Zip.GetEntry($Name)
|
||||
if (-not $entry) {
|
||||
return $null
|
||||
}
|
||||
|
||||
$stream = $entry.Open()
|
||||
try {
|
||||
$reader = [System.IO.StreamReader]::new($stream, [System.Text.Encoding]::UTF8)
|
||||
try {
|
||||
return $reader.ReadToEnd()
|
||||
}
|
||||
finally {
|
||||
$reader.Dispose()
|
||||
}
|
||||
}
|
||||
finally {
|
||||
$stream.Dispose()
|
||||
}
|
||||
}
|
||||
|
||||
function Get-RelationshipId {
|
||||
param($Element)
|
||||
|
||||
foreach ($attribute in $Element.Attributes) {
|
||||
if ($attribute.LocalName -eq "id") {
|
||||
return $attribute.Value
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
function Get-ColumnIndex {
|
||||
param([string]$CellRef)
|
||||
|
||||
$letters = ([regex]::Match($CellRef, "^[A-Z]+")).Value
|
||||
$index = 0
|
||||
foreach ($character in $letters.ToCharArray()) {
|
||||
$index = ($index * 26) + ([int][char]$character - [int][char]"A" + 1)
|
||||
}
|
||||
return $index
|
||||
}
|
||||
|
||||
function Get-XlsxFirstSheetRows {
|
||||
param([string]$Path)
|
||||
|
||||
Add-Type -AssemblyName System.IO.Compression.FileSystem
|
||||
$zip = [System.IO.Compression.ZipFile]::OpenRead($Path)
|
||||
try {
|
||||
$sharedStrings = @()
|
||||
$sharedText = Read-ZipEntryText $zip "xl/sharedStrings.xml"
|
||||
if ($sharedText) {
|
||||
[xml]$sharedXml = $sharedText
|
||||
foreach ($sharedItem in $sharedXml.GetElementsByTagName("si")) {
|
||||
$sharedStrings += $sharedItem.InnerText
|
||||
}
|
||||
}
|
||||
|
||||
[xml]$workbookXml = Read-ZipEntryText $zip "xl/workbook.xml"
|
||||
[xml]$relsXml = Read-ZipEntryText $zip "xl/_rels/workbook.xml.rels"
|
||||
$firstSheet = $workbookXml.GetElementsByTagName("sheet").Item(0)
|
||||
if (-not $firstSheet) {
|
||||
throw "服务器清单没有工作表:$Path"
|
||||
}
|
||||
|
||||
$relationshipId = Get-RelationshipId $firstSheet
|
||||
$relationship = $null
|
||||
foreach ($candidate in $relsXml.GetElementsByTagName("Relationship")) {
|
||||
if ($candidate.GetAttribute("Id") -eq $relationshipId) {
|
||||
$relationship = $candidate
|
||||
break
|
||||
}
|
||||
}
|
||||
if (-not $relationship) {
|
||||
throw "无法解析工作表关系:$relationshipId"
|
||||
}
|
||||
|
||||
$target = $relationship.Target
|
||||
$sheetPath = if ($target.StartsWith("/")) {
|
||||
$target.TrimStart("/")
|
||||
}
|
||||
elseif ($target.StartsWith("xl/")) {
|
||||
$target
|
||||
}
|
||||
else {
|
||||
"xl/$target"
|
||||
}
|
||||
|
||||
[xml]$sheetXml = Read-ZipEntryText $zip $sheetPath
|
||||
$rows = @()
|
||||
foreach ($row in $sheetXml.GetElementsByTagName("row")) {
|
||||
$valuesByIndex = @{}
|
||||
$maxIndex = 0
|
||||
foreach ($cell in $row.GetElementsByTagName("c")) {
|
||||
$index = Get-ColumnIndex $cell.r
|
||||
$maxIndex = [Math]::Max($maxIndex, $index)
|
||||
$valueNodes = $cell.GetElementsByTagName("v")
|
||||
$valueNode = if ($valueNodes.Count -gt 0) { $valueNodes.Item(0) } else { $null }
|
||||
$value = ""
|
||||
if ($cell.GetAttribute("t") -eq "s" -and $valueNode -and $valueNode.InnerText -ne "") {
|
||||
$sharedIndex = [int]$valueNode.InnerText
|
||||
if ($sharedIndex -lt $sharedStrings.Count) {
|
||||
$value = $sharedStrings[$sharedIndex]
|
||||
}
|
||||
}
|
||||
elseif ($cell.GetAttribute("t") -eq "inlineStr") {
|
||||
$value = $cell.InnerText
|
||||
}
|
||||
elseif ($valueNode) {
|
||||
$value = $valueNode.InnerText
|
||||
}
|
||||
$valuesByIndex[$index] = $value
|
||||
}
|
||||
|
||||
if ($maxIndex -gt 0) {
|
||||
$values = for ($index = 1; $index -le $maxIndex; $index++) {
|
||||
if ($valuesByIndex.ContainsKey($index)) { $valuesByIndex[$index] } else { "" }
|
||||
}
|
||||
if (($values -join "").Trim()) {
|
||||
$rows += ,$values
|
||||
}
|
||||
}
|
||||
}
|
||||
return $rows
|
||||
}
|
||||
finally {
|
||||
$zip.Dispose()
|
||||
}
|
||||
}
|
||||
|
||||
function Get-HeaderIndex {
|
||||
param([string[]]$Header, [string[]]$Candidates)
|
||||
|
||||
foreach ($candidate in $Candidates) {
|
||||
$index = [Array]::IndexOf($Header, $candidate.ToLowerInvariant())
|
||||
if ($index -ge 0) {
|
||||
return $index
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
function Get-CellValue {
|
||||
param([object[]]$Row, [int]$Index)
|
||||
|
||||
if ($Index -lt 0 -or $Index -ge $Row.Count) {
|
||||
return ""
|
||||
}
|
||||
return ([string]$Row[$Index]).Trim()
|
||||
}
|
||||
|
||||
function Get-ServerPort {
|
||||
param([object[]]$Row, [int]$Index)
|
||||
|
||||
$value = Get-CellValue $Row $Index
|
||||
if (-not $value) {
|
||||
return 22
|
||||
}
|
||||
$value = ($value -split "[/,;,;\s]+")[0]
|
||||
$port = 0
|
||||
if (-not [int]::TryParse($value, [ref]$port)) {
|
||||
throw "服务器清单端口不是数字:$value"
|
||||
}
|
||||
return $port
|
||||
}
|
||||
|
||||
function Get-ServersFromWorkbook {
|
||||
param([string]$Path)
|
||||
|
||||
if (-not (Test-Path -LiteralPath $Path)) {
|
||||
throw "服务器清单不存在:$Path"
|
||||
}
|
||||
|
||||
$rows = @(Get-XlsxFirstSheetRows (Resolve-Path -LiteralPath $Path).Path)
|
||||
if ($rows.Count -lt 2) {
|
||||
throw "服务器清单没有数据行:$Path"
|
||||
}
|
||||
|
||||
$header = @($rows[0] | ForEach-Object { ([string]$_).Trim().ToLowerInvariant() })
|
||||
$nameIndex = Get-HeaderIndex $header @("name", "名称", "服务器名称")
|
||||
$hostIndex = Get-HeaderIndex $header @("host", "ip", "ip/域名", "ip地址", "主机", "公网ip", "内网ip")
|
||||
$portIndex = Get-HeaderIndex $header @("port", "端口", "ssh端口")
|
||||
$userIndex = Get-HeaderIndex $header @("user", "username", "用户名", "账号")
|
||||
$passwordIndex = Get-HeaderIndex $header @("password", "密码", "口令")
|
||||
$purposeIndex = Get-HeaderIndex $header @("purpose", "功能定位", "业务作用", "用途", "类型")
|
||||
$noteIndex = Get-HeaderIndex $header @("note", "备注", "说明")
|
||||
$environmentIndex = Get-HeaderIndex $header @("environment", "环境", "所属中心")
|
||||
|
||||
foreach ($row in $rows[1..($rows.Count - 1)]) {
|
||||
if ((-not (Get-CellValue $row $nameIndex)) -or (-not (Get-CellValue $row $hostIndex))) {
|
||||
continue
|
||||
}
|
||||
[pscustomobject]@{
|
||||
Name = Get-CellValue $row $nameIndex
|
||||
Host = Get-CellValue $row $hostIndex
|
||||
Port = Get-ServerPort $row $portIndex
|
||||
User = Get-CellValue $row $userIndex
|
||||
Password = Get-CellValue $row $passwordIndex
|
||||
Purpose = Get-CellValue $row $purposeIndex
|
||||
Note = Get-CellValue $row $noteIndex
|
||||
Environment = Get-CellValue $row $environmentIndex
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function Resolve-ServerInfoPath {
|
||||
param([string]$ExplicitPath)
|
||||
|
||||
if ($ExplicitPath) {
|
||||
if (-not (Test-Path -LiteralPath $ExplicitPath)) {
|
||||
throw "服务器清单不存在:$ExplicitPath"
|
||||
}
|
||||
return (Resolve-Path -LiteralPath $ExplicitPath).Path
|
||||
}
|
||||
|
||||
$codeRoot = "Y:\code"
|
||||
if (-not (Test-Path -LiteralPath $codeRoot)) {
|
||||
throw "未传入 -ServerInfoPath,且默认目录不存在:$codeRoot"
|
||||
}
|
||||
|
||||
$workbooks = @(Get-ChildItem -LiteralPath $codeRoot -Filter "*.xlsx" -File | Sort-Object LastWriteTime -Descending)
|
||||
if ($workbooks.Count -eq 0) {
|
||||
throw "默认目录下没有服务器清单 xlsx,请显式传入 -ServerInfoPath。"
|
||||
}
|
||||
|
||||
return $workbooks[0].FullName
|
||||
}
|
||||
|
||||
function Assert-ProductionTarget {
|
||||
param([object[]]$Servers)
|
||||
|
||||
$blocked = @($Servers | Where-Object { $_.Name -match "^(?i:MessageHub|mysql|nacos|redis|rabbitmq)" })
|
||||
if ($blocked.Count -gt 0) {
|
||||
throw "拒绝把应用发布到基础设施节点:$($blocked.Name -join ', ')"
|
||||
}
|
||||
|
||||
$knownNonProduction = @($Servers | Where-Object { $_.Environment -match "(?i)\b(dev|test|local|staging)\b" })
|
||||
if ($knownNonProduction.Count -gt 0) {
|
||||
throw "拒绝发布到非生产环境节点:$($knownNonProduction.Name -join ', ')"
|
||||
}
|
||||
}
|
||||
|
||||
function Get-SshTarget {
|
||||
param([object]$Server)
|
||||
|
||||
return "$($Server.User)@$($Server.Host)"
|
||||
}
|
||||
|
||||
function Invoke-RemoteShell {
|
||||
param(
|
||||
[object]$Server,
|
||||
[string]$Command,
|
||||
[switch]$Sensitive
|
||||
)
|
||||
|
||||
if ($UsePuttyPassword) {
|
||||
$plink = Get-Command plink -ErrorAction SilentlyContinue
|
||||
if ((-not $DryRun) -and (-not $plink)) {
|
||||
throw "找不到 PuTTY plink,请安装 PuTTY 工具或改用 SSH key。"
|
||||
}
|
||||
$plinkPath = if ($plink) { $plink.Source } else { "plink" }
|
||||
Invoke-Native $plinkPath @("-batch", "-ssh", "-P", [string]$Server.Port, "-l", $Server.User, "-pw", $Server.Password, $Server.Host, $Command) -Sensitive:$Sensitive -RemoteMutation
|
||||
}
|
||||
else {
|
||||
Invoke-Native "ssh" @("-o", "BatchMode=yes", "-o", "StrictHostKeyChecking=accept-new", "-p", [string]$Server.Port, (Get-SshTarget $Server), $Command) -Sensitive:$Sensitive -RemoteMutation
|
||||
}
|
||||
}
|
||||
|
||||
function Copy-FileToRemote {
|
||||
param(
|
||||
[string]$LocalPath,
|
||||
[object]$Server,
|
||||
[string]$RemotePath,
|
||||
[switch]$Sensitive
|
||||
)
|
||||
|
||||
if (-not (Test-Path -LiteralPath $LocalPath)) {
|
||||
throw "本地上传文件不存在:$LocalPath"
|
||||
}
|
||||
|
||||
if ($UsePuttyPassword) {
|
||||
$pscp = Get-Command pscp -ErrorAction SilentlyContinue
|
||||
if ((-not $DryRun) -and (-not $pscp)) {
|
||||
throw "找不到 PuTTY pscp,请安装 PuTTY 工具或改用 SSH key。"
|
||||
}
|
||||
$pscpPath = if ($pscp) { $pscp.Source } else { "pscp" }
|
||||
Invoke-Native $pscpPath @("-batch", "-P", [string]$Server.Port, "-pw", $Server.Password, $LocalPath, "$(Get-SshTarget $Server):$RemotePath") -Sensitive:$Sensitive -RemoteMutation
|
||||
}
|
||||
else {
|
||||
Invoke-Native "scp" @("-o", "BatchMode=yes", "-o", "StrictHostKeyChecking=accept-new", "-P", [string]$Server.Port, $LocalPath, "$(Get-SshTarget $Server):$RemotePath") -Sensitive:$Sensitive -RemoteMutation
|
||||
}
|
||||
}
|
||||
|
||||
function Invoke-RemoteShellMany {
|
||||
param(
|
||||
[object[]]$Servers,
|
||||
[string]$Command,
|
||||
[string]$GroupName
|
||||
)
|
||||
|
||||
foreach ($server in $Servers) {
|
||||
Write-Host "$GroupName target: $($server.Name) $($server.User)@$($server.Host):$($server.Port)"
|
||||
Invoke-RemoteShell $server $Command
|
||||
}
|
||||
}
|
||||
|
||||
function Test-GitState {
|
||||
Push-Location $resolvedRepoRoot
|
||||
try {
|
||||
$commit = (& git rev-parse HEAD).Trim()
|
||||
$branch = (& git branch --show-current).Trim()
|
||||
$status = @(& git status --porcelain)
|
||||
if ($status.Count -gt 0) {
|
||||
Write-Warning "当前工作区有 $($status.Count) 个变更路径。"
|
||||
$status | Select-Object -First 40 | ForEach-Object { Write-Warning $_ }
|
||||
if ($Deploy -and (-not $DryRun) -and (-not $AllowDirtyWorkingTree)) {
|
||||
throw "拒绝从脏工作区发布生产,请先提交/暂存,或显式传入 -AllowDirtyWorkingTree。"
|
||||
}
|
||||
}
|
||||
return [pscustomobject]@{
|
||||
Branch = $branch
|
||||
Commit = $commit
|
||||
Dirty = $status.Count -gt 0
|
||||
ChangedPathCount = $status.Count
|
||||
}
|
||||
}
|
||||
finally {
|
||||
Pop-Location
|
||||
}
|
||||
}
|
||||
|
||||
function Assert-InitSqlSafe {
|
||||
param([string]$Path)
|
||||
|
||||
if (-not (Test-Path -LiteralPath $Path)) {
|
||||
throw "初始化 SQL 不存在:$Path"
|
||||
}
|
||||
|
||||
$content = Get-Content -LiteralPath $Path -Raw
|
||||
if ($content -notmatch "CREATE DATABASE IF NOT EXISTS\s+jayucloud_salon") {
|
||||
throw "初始化 SQL 未声明目标库 jayucloud_salon:$Path"
|
||||
}
|
||||
if ($content -notmatch "(?im)^\s*use\s+jayucloud_salon\s*;") {
|
||||
throw "初始化 SQL 未切换到目标库 jayucloud_salon:$Path"
|
||||
}
|
||||
|
||||
$dangerousMatch = [regex]::Match($content, "(?im)^\s*(drop\s+(database|schema|table)|truncate\s+table)\b")
|
||||
if ($dangerousMatch.Success) {
|
||||
throw "初始化 SQL 包含危险语句:$($dangerousMatch.Value)"
|
||||
}
|
||||
}
|
||||
|
||||
function Build-ReleasePackage {
|
||||
param([object]$GitState)
|
||||
|
||||
New-Item -ItemType Directory -Force -Path $backendDir, $frontendDir, $sqlDir | Out-Null
|
||||
$maven = Resolve-Maven $MavenPath
|
||||
|
||||
if (-not $SkipBuild) {
|
||||
$mavenArgs = @("-q", "package")
|
||||
if ($SkipTests) {
|
||||
$mavenArgs += "-DskipTests"
|
||||
}
|
||||
|
||||
Write-Step "构建 JC-Salon-Core"
|
||||
Invoke-Native $maven $mavenArgs (Join-Path $resolvedRepoRoot "JC-Salon-Core")
|
||||
|
||||
Write-Step "构建 JC-Salon-Gateway"
|
||||
Invoke-Native $maven $mavenArgs (Join-Path $resolvedRepoRoot "JC-Salon-Gateway")
|
||||
|
||||
Write-Step "构建 JC-Salon-Frontend"
|
||||
$frontendRoot = Join-Path $resolvedRepoRoot "JC-Salon-Frontend"
|
||||
if (-not (Test-Path -LiteralPath (Join-Path $frontendRoot "node_modules"))) {
|
||||
Invoke-Native "npm" @("ci") $frontendRoot
|
||||
}
|
||||
Invoke-Native "npm" @("run", "build") $frontendRoot
|
||||
}
|
||||
|
||||
$coreJar = Join-Path $resolvedRepoRoot "JC-Salon-Core\target\JC-Salon-Core.jar"
|
||||
$gatewayJar = Join-Path $resolvedRepoRoot "JC-Salon-Gateway\target\JC-Salon-Gateway.jar"
|
||||
$frontendDist = Join-Path $resolvedRepoRoot "JC-Salon-Frontend\dist"
|
||||
foreach ($requiredPath in @($coreJar, $gatewayJar, $frontendDist, $InitSqlPath)) {
|
||||
if (-not (Test-Path -LiteralPath $requiredPath)) {
|
||||
throw "缺少发布产物:$requiredPath"
|
||||
}
|
||||
}
|
||||
|
||||
$coreArtifact = Join-Path $backendDir "JC-Salon-Core.jar"
|
||||
$gatewayArtifact = Join-Path $backendDir "JC-Salon-Gateway.jar"
|
||||
$frontendArtifact = Join-Path $frontendDir "jc-salon-frontend-dist.tar.gz"
|
||||
$sqlArtifact = Join-Path $sqlDir "店务独立数据库_20260825.sql"
|
||||
Copy-Item -LiteralPath $coreJar -Destination $coreArtifact -Force
|
||||
Copy-Item -LiteralPath $gatewayJar -Destination $gatewayArtifact -Force
|
||||
Copy-Item -LiteralPath $InitSqlPath -Destination $sqlArtifact -Force
|
||||
|
||||
$tar = Get-Command tar -ErrorAction SilentlyContinue
|
||||
if (-not $tar) {
|
||||
throw "缺少 tar,无法打包前端 dist。"
|
||||
}
|
||||
if (Test-Path -LiteralPath $frontendArtifact) {
|
||||
Remove-Item -LiteralPath $frontendArtifact -Force
|
||||
}
|
||||
Invoke-Native $tar.Source @("-czf", $frontendArtifact, "-C", (Join-Path $resolvedRepoRoot "JC-Salon-Frontend"), "dist")
|
||||
|
||||
$hashes = foreach ($artifact in @($coreArtifact, $gatewayArtifact, $frontendArtifact, $sqlArtifact)) {
|
||||
$hash = Get-FileHash -LiteralPath $artifact -Algorithm SHA256
|
||||
[pscustomobject]@{
|
||||
Path = $artifact.Replace($resolvedRepoRoot, "").TrimStart("\", "/")
|
||||
Sha256 = $hash.Hash
|
||||
}
|
||||
}
|
||||
|
||||
return [pscustomobject]@{
|
||||
Directory = $releaseDir
|
||||
CoreJar = $coreArtifact
|
||||
GatewayJar = $gatewayArtifact
|
||||
FrontendArchive = $frontendArtifact
|
||||
InitSql = $sqlArtifact
|
||||
Hashes = @($hashes)
|
||||
Git = $GitState
|
||||
}
|
||||
}
|
||||
|
||||
function Get-BackendDeployCommand {
|
||||
param(
|
||||
[string]$RemoteAppDir,
|
||||
[string]$ServiceName,
|
||||
[string]$ReleaseName,
|
||||
[int]$HealthPort
|
||||
)
|
||||
|
||||
$appDir = ConvertTo-BashSingleQuoted $RemoteAppDir
|
||||
$service = ConvertTo-BashSingleQuoted $ServiceName
|
||||
$releaseName = ConvertTo-BashSingleQuoted $ReleaseName
|
||||
$healthPath = ConvertTo-BashSingleQuoted $HealthPath
|
||||
$timeout = [string]$HealthTimeoutSeconds
|
||||
$healthPortText = [string]$HealthPort
|
||||
|
||||
return @"
|
||||
set -e
|
||||
APP_DIR=$appDir
|
||||
SERVICE=$service
|
||||
RELEASE_NAME=$releaseName
|
||||
HEALTH_PATH=$healthPath
|
||||
HEALTH_PORT=$healthPortText
|
||||
HEALTH_TIMEOUT=$timeout
|
||||
RELEASE="`$APP_DIR/releases/`$RELEASE_NAME"
|
||||
BACKUP_NAME="app-$releaseTimestamp.jar"
|
||||
mkdir -p "`$APP_DIR/releases" "`$APP_DIR/backups" "`$APP_DIR/logs"
|
||||
test -f "`$RELEASE"
|
||||
if command -v systemctl >/dev/null 2>&1 && systemctl list-unit-files | grep -q "^`$SERVICE.service"; then
|
||||
systemctl stop "`$SERVICE" || true
|
||||
fi
|
||||
if [ -f "`$APP_DIR/app.jar" ]; then
|
||||
cp "`$APP_DIR/app.jar" "`$APP_DIR/backups/`$BACKUP_NAME"
|
||||
fi
|
||||
cp "`$RELEASE" "`$APP_DIR/app.jar"
|
||||
if command -v systemctl >/dev/null 2>&1 && systemctl list-unit-files | grep -q "^`$SERVICE.service"; then
|
||||
systemctl start "`$SERVICE"
|
||||
else
|
||||
if [ -f "`$APP_DIR/app.pid" ]; then kill "`$(cat "`$APP_DIR/app.pid")" >/dev/null 2>&1 || true; fi
|
||||
pkill -f "java .*`$APP_DIR/app.jar" >/dev/null 2>&1 || true
|
||||
nohup java -jar "`$APP_DIR/app.jar" > "`$APP_DIR/logs/app-$releaseTimestamp.log" 2>&1 &
|
||||
echo `$! > "`$APP_DIR/app.pid"
|
||||
fi
|
||||
deadline=`$((`$(date +%s) + `$HEALTH_TIMEOUT))
|
||||
until curl -fsS "http://127.0.0.1:`$HEALTH_PORT`$HEALTH_PATH" >/tmp/jayucloud-salon-health.out 2>/tmp/jayucloud-salon-health.err; do
|
||||
if [ "`$(date +%s)" -ge "`$deadline" ]; then
|
||||
echo "Health check failed for `$SERVICE on port `$HEALTH_PORT"
|
||||
cat /tmp/jayucloud-salon-health.err || true
|
||||
if command -v systemctl >/dev/null 2>&1; then journalctl -u "`$SERVICE" -n 80 --no-pager || true; fi
|
||||
exit 43
|
||||
fi
|
||||
sleep 3
|
||||
done
|
||||
cat /tmp/jayucloud-salon-health.out
|
||||
"@
|
||||
}
|
||||
|
||||
function Publish-BackendGroup {
|
||||
param(
|
||||
[string]$GroupName,
|
||||
[object[]]$Servers,
|
||||
[string]$ArtifactPath,
|
||||
[string]$RemoteAppDir,
|
||||
[string]$ServiceName,
|
||||
[int]$HealthPort
|
||||
)
|
||||
|
||||
$artifactBaseName = [System.IO.Path]::GetFileNameWithoutExtension($ArtifactPath)
|
||||
$releaseName = "$artifactBaseName-$releaseTimestamp.jar"
|
||||
$quotedRemoteAppDir = ConvertTo-BashSingleQuoted $RemoteAppDir
|
||||
Write-Step "准备 $GroupName 目标机器"
|
||||
foreach ($server in $Servers) {
|
||||
Write-Host "$GroupName target: $($server.Name) $($server.User)@$($server.Host):$($server.Port)"
|
||||
Invoke-RemoteShell $server "mkdir -p $quotedRemoteAppDir/releases $quotedRemoteAppDir/backups $quotedRemoteAppDir/logs"
|
||||
Copy-FileToRemote $ArtifactPath $server "$RemoteAppDir/releases/$releaseName"
|
||||
}
|
||||
|
||||
Write-Step "切换 $GroupName 发布版本"
|
||||
$deployCommand = Get-BackendDeployCommand $RemoteAppDir $ServiceName $releaseName $HealthPort
|
||||
Invoke-RemoteShellMany $Servers $deployCommand $GroupName
|
||||
}
|
||||
|
||||
function Get-WebDeployCommand {
|
||||
param([string]$ArchiveName)
|
||||
|
||||
$webDir = ConvertTo-BashSingleQuoted $WebRemoteDir
|
||||
$archiveName = ConvertTo-BashSingleQuoted $ArchiveName
|
||||
return @"
|
||||
set -e
|
||||
WEB_DIR=$webDir
|
||||
ARCHIVE_NAME=$archiveName
|
||||
RELEASE_BASE="`$WEB_DIR/releases/$releaseTimestamp"
|
||||
ARCHIVE="`$WEB_DIR/releases/`$ARCHIVE_NAME"
|
||||
mkdir -p "`$RELEASE_BASE"
|
||||
if [ -L "`$WEB_DIR/current" ]; then readlink "`$WEB_DIR/current" > "`$WEB_DIR/previous-release.txt"; fi
|
||||
tar -xzf "`$ARCHIVE" -C "`$RELEASE_BASE"
|
||||
if [ -d "`$RELEASE_BASE/dist" ]; then
|
||||
TARGET="`$RELEASE_BASE/dist"
|
||||
else
|
||||
TARGET="`$RELEASE_BASE"
|
||||
fi
|
||||
ln -sfn "`$TARGET" "`$WEB_DIR/current"
|
||||
nginx -t
|
||||
if command -v systemctl >/dev/null 2>&1 && systemctl list-unit-files | grep -q "^nginx.service"; then
|
||||
systemctl reload nginx
|
||||
else
|
||||
nginx -s reload
|
||||
fi
|
||||
echo "Web current -> `$TARGET"
|
||||
"@
|
||||
}
|
||||
|
||||
function Publish-Web {
|
||||
param([object]$Server, [string]$ArchivePath)
|
||||
|
||||
$archiveName = "jc-salon-frontend-dist-$releaseTimestamp.tar.gz"
|
||||
$quotedWebRemoteDir = ConvertTo-BashSingleQuoted $WebRemoteDir
|
||||
Write-Step "准备 Web 目标机器"
|
||||
Invoke-RemoteShell $Server "mkdir -p $quotedWebRemoteDir/releases"
|
||||
Copy-FileToRemote $ArchivePath $Server "$WebRemoteDir/releases/$archiveName"
|
||||
|
||||
Write-Step "切换 Web 发布版本"
|
||||
Invoke-RemoteShell $Server (Get-WebDeployCommand $archiveName)
|
||||
}
|
||||
|
||||
function Initialize-ProductionDatabase {
|
||||
param([object]$DatabaseServer, [string]$SqlArtifact)
|
||||
|
||||
Assert-InitSqlSafe $SqlArtifact
|
||||
|
||||
$dbUserValue = if ($DatabaseUser) { $DatabaseUser } else { $DatabaseServer.User }
|
||||
$dbPasswordValue = if ($DatabasePassword) { $DatabasePassword } else { $DatabaseServer.Password }
|
||||
if (-not $dbUserValue) {
|
||||
throw "数据库用户名为空,请传入 -DatabaseUser 或在服务器清单中填写。"
|
||||
}
|
||||
|
||||
$remoteSqlPath = "/tmp/jayucloud-salon-init-$releaseTimestamp.sql"
|
||||
Write-Step "初始化生产空库"
|
||||
Write-Host "数据库目标:$($DatabaseServer.Name) $($DatabaseServer.Host):$DatabasePort/$DatabaseName"
|
||||
Invoke-RemoteShell $DatabaseServer "rm -f '$remoteSqlPath'"
|
||||
Copy-FileToRemote $SqlArtifact $DatabaseServer $remoteSqlPath -Sensitive
|
||||
|
||||
$dbName = ConvertTo-BashSingleQuoted $DatabaseName
|
||||
$dbUser = ConvertTo-BashSingleQuoted $dbUserValue
|
||||
$dbPassword = ConvertTo-BashSingleQuoted $dbPasswordValue
|
||||
$dbPort = [string]$DatabasePort
|
||||
$sqlFile = ConvertTo-BashSingleQuoted $remoteSqlPath
|
||||
$command = @'
|
||||
set -e
|
||||
DB_NAME=__DB_NAME__
|
||||
DB_PORT=__DB_PORT__
|
||||
DB_USER=__DB_USER__
|
||||
SQL_FILE=__SQL_FILE__
|
||||
export MYSQL_PWD=__DB_PASSWORD__
|
||||
if ! command -v mysql >/dev/null 2>&1; then
|
||||
echo "mysql client not found on database host"
|
||||
exit 48
|
||||
fi
|
||||
mysql -h 127.0.0.1 -P "$DB_PORT" -u"$DB_USER" --default-character-set=utf8mb4 --batch --skip-column-names -e "CREATE DATABASE IF NOT EXISTS \`$DB_NAME\` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
|
||||
TABLE_COUNT=$(mysql -h 127.0.0.1 -P "$DB_PORT" -u"$DB_USER" --default-character-set=utf8mb4 --batch --skip-column-names -e "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema='${DB_NAME}';")
|
||||
if [ "$TABLE_COUNT" != "0" ]; then
|
||||
echo "Database ${DB_NAME} is not empty: ${TABLE_COUNT} tables. Refusing initialization."
|
||||
rm -f "$SQL_FILE"
|
||||
unset MYSQL_PWD
|
||||
exit 49
|
||||
fi
|
||||
mysql -h 127.0.0.1 -P "$DB_PORT" -u"$DB_USER" --default-character-set=utf8mb4 < "$SQL_FILE"
|
||||
ADMIN_COUNT=$(mysql -h 127.0.0.1 -P "$DB_PORT" -u"$DB_USER" --default-character-set=utf8mb4 --batch --skip-column-names "$DB_NAME" -e "SELECT COUNT(*) FROM t_user WHERE account='xiaowang';")
|
||||
rm -f "$SQL_FILE"
|
||||
unset MYSQL_PWD
|
||||
echo "Database initialized. Admin account rows: ${ADMIN_COUNT}"
|
||||
'@
|
||||
$command = $command.Replace("__DB_NAME__", $dbName)
|
||||
$command = $command.Replace("__DB_PORT__", $dbPort)
|
||||
$command = $command.Replace("__DB_USER__", $dbUser)
|
||||
$command = $command.Replace("__DB_PASSWORD__", $dbPassword)
|
||||
$command = $command.Replace("__SQL_FILE__", $sqlFile)
|
||||
Invoke-RemoteShell $DatabaseServer $command -Sensitive
|
||||
}
|
||||
|
||||
function Write-ReleaseManifest {
|
||||
param(
|
||||
[object]$Package,
|
||||
[object[]]$CoreServers,
|
||||
[object[]]$GatewayServers,
|
||||
[object]$WebServer,
|
||||
[object]$DatabaseServer,
|
||||
[string]$ResolvedServerInfoPath
|
||||
)
|
||||
|
||||
$manifest = [pscustomobject]@{
|
||||
releaseTimestamp = $releaseTimestamp
|
||||
repoRoot = $resolvedRepoRoot
|
||||
git = $Package.Git
|
||||
artifacts = $Package.Hashes
|
||||
targets = [pscustomobject]@{
|
||||
core = @($CoreServers | Select-Object Name, Host, Port, User, Purpose, Environment)
|
||||
gateway = @($GatewayServers | Select-Object Name, Host, Port, User, Purpose, Environment)
|
||||
web = $WebServer | Select-Object Name, Host, Port, User, Purpose, Environment
|
||||
database = if ($DatabaseServer) { $DatabaseServer | Select-Object Name, Host, Port, User, Purpose, Environment } else { $null }
|
||||
}
|
||||
parameters = [pscustomobject]@{
|
||||
initializeDatabase = -not [bool]$SkipDatabaseInit
|
||||
databaseName = $DatabaseName
|
||||
serverInfoPath = $ResolvedServerInfoPath
|
||||
coreRemoteAppDir = $CoreRemoteAppDir
|
||||
gatewayRemoteAppDir = $GatewayRemoteAppDir
|
||||
webRemoteDir = $WebRemoteDir
|
||||
publicBaseUrl = $PublicBaseUrl
|
||||
managerMiniProgramApi = "$PublicBaseUrl/api/admin"
|
||||
nacosNamespace = "jayucloud-salon"
|
||||
dryRun = [bool]$DryRun
|
||||
deploy = [bool]$Deploy
|
||||
}
|
||||
}
|
||||
$manifest | ConvertTo-Json -Depth 8 | Set-Content -LiteralPath $manifestPath -Encoding UTF8
|
||||
Write-Host "Manifest: $manifestPath"
|
||||
}
|
||||
|
||||
function Invoke-PublicSmokeTests {
|
||||
if ($DryRun) {
|
||||
Write-Host "DryRun public smoke tests:"
|
||||
Write-Host "GET $PublicBaseUrl/health/check"
|
||||
Write-Host "GET $PublicBaseUrl/api/shop/list"
|
||||
return
|
||||
}
|
||||
|
||||
Write-Step "生产公开冒烟"
|
||||
foreach ($url in @("$PublicBaseUrl/health/check", "$PublicBaseUrl/api/shop/list")) {
|
||||
Write-Host "GET $url"
|
||||
$response = Invoke-WebRequest -Uri $url -UseBasicParsing -TimeoutSec 20
|
||||
Write-Host "Status $($response.StatusCode) Length $($response.RawContentLength)"
|
||||
}
|
||||
}
|
||||
|
||||
Write-Step "读取服务器清单"
|
||||
$resolvedServerInfoPath = Resolve-ServerInfoPath $ServerInfoPath
|
||||
$servers = @(Get-ServersFromWorkbook $resolvedServerInfoPath)
|
||||
$coreServers = @($servers | Where-Object { $_.Name -match $CorePattern })
|
||||
$gatewayServers = @($servers | Where-Object { $_.Name -match $GatewayPattern })
|
||||
$webServers = @(if ($WebTargetName) {
|
||||
$servers | Where-Object { $_.Name -eq $WebTargetName }
|
||||
}
|
||||
else {
|
||||
$servers | Where-Object { $_.Host -eq $WebTargetHost }
|
||||
})
|
||||
$databaseServers = @($servers | Where-Object { $_.Name -eq $DatabaseTargetName })
|
||||
|
||||
if ($coreServers.Count -eq 0) {
|
||||
throw "没有匹配到 Core 服务器,匹配规则:$CorePattern"
|
||||
}
|
||||
if ($gatewayServers.Count -eq 0) {
|
||||
throw "没有匹配到 Gateway 服务器,匹配规则:$GatewayPattern"
|
||||
}
|
||||
if ($webServers.Count -ne 1) {
|
||||
$webSelector = if ($WebTargetName) { "名称 $WebTargetName" } else { "主机 $WebTargetHost" }
|
||||
throw "Web 目标必须唯一,当前按 $webSelector 找到 $($webServers.Count) 个。"
|
||||
}
|
||||
if ((-not $SkipDatabaseInit) -and $databaseServers.Count -ne 1) {
|
||||
throw "数据库初始化目标必须唯一,当前按 $DatabaseTargetName 找到 $($databaseServers.Count) 个。"
|
||||
}
|
||||
|
||||
Assert-ProductionTarget (@($coreServers) + @($gatewayServers) + @($webServers))
|
||||
$databaseServer = if (-not $SkipDatabaseInit) { $databaseServers[0] } else { $null }
|
||||
|
||||
Write-Host "服务器清单:$resolvedServerInfoPath"
|
||||
@($coreServers + $gatewayServers + $webServers) | Select-Object Name, Host, Port, User, Purpose, Environment | Format-Table -AutoSize
|
||||
if ($databaseServer) {
|
||||
Write-Host "数据库初始化目标:"
|
||||
$databaseServer | Select-Object Name, Host, Port, User, Purpose, Environment | Format-Table -AutoSize
|
||||
}
|
||||
|
||||
Write-Step "检查工作区"
|
||||
$gitState = Test-GitState
|
||||
|
||||
Write-Step "构建发布包"
|
||||
$package = Build-ReleasePackage $gitState
|
||||
Write-ReleaseManifest $package $coreServers $gatewayServers $webServers[0] $databaseServer $resolvedServerInfoPath
|
||||
|
||||
if (-not $Deploy) {
|
||||
Write-Host "发布包已生成。传入 -Deploy 才会发布到生产;传入 -DryRun 可打印远程动作但不修改远端。"
|
||||
exit 0
|
||||
}
|
||||
|
||||
if (-not $SkipDatabaseInit) {
|
||||
Initialize-ProductionDatabase $databaseServer $package.InitSql
|
||||
}
|
||||
else {
|
||||
Write-Host "已跳过数据库初始化。"
|
||||
}
|
||||
|
||||
Publish-BackendGroup "Core" $coreServers $package.CoreJar $CoreRemoteAppDir $CoreServiceName $CoreHealthPort
|
||||
Publish-BackendGroup "Gateway" $gatewayServers $package.GatewayJar $GatewayRemoteAppDir $GatewayServiceName $GatewayHealthPort
|
||||
Publish-Web $webServers[0] $package.FrontendArchive
|
||||
Invoke-PublicSmokeTests
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "jayucloud_salon 生产发布流程完成。"
|
||||
@@ -0,0 +1,146 @@
|
||||
param(
|
||||
[switch]$SkipTests,
|
||||
[string]$MavenPath = ""
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
$repoRoot = Split-Path -Parent $PSScriptRoot
|
||||
$timestamp = Get-Date -Format "yyyyMMdd-HHmmss"
|
||||
$releaseRoot = Join-Path $repoRoot "release-packages"
|
||||
$releaseDir = Join-Path $releaseRoot $timestamp
|
||||
$backendDir = Join-Path $releaseDir "backend"
|
||||
$frontendDir = Join-Path $releaseDir "frontend"
|
||||
$miniProgramDir = Join-Path $releaseDir "miniprograms"
|
||||
$sqlPath = Join-Path $repoRoot "docs\scripts\sql\init\FingertipDesigner.sql"
|
||||
|
||||
function Resolve-Maven {
|
||||
param([string]$PreferredPath)
|
||||
|
||||
if ($PreferredPath -and (Test-Path -LiteralPath $PreferredPath)) {
|
||||
return (Resolve-Path -LiteralPath $PreferredPath).Path
|
||||
}
|
||||
|
||||
$fromPath = Get-Command mvn.cmd -ErrorAction SilentlyContinue
|
||||
if ($fromPath) {
|
||||
return $fromPath.Source
|
||||
}
|
||||
|
||||
$fromPath = Get-Command mvn -ErrorAction SilentlyContinue
|
||||
if ($fromPath) {
|
||||
return $fromPath.Source
|
||||
}
|
||||
|
||||
throw "找不到 Maven,请通过 -MavenPath 传入 Maven 可执行文件绝对路径。"
|
||||
}
|
||||
|
||||
function Invoke-Native {
|
||||
param(
|
||||
[string]$FilePath,
|
||||
[string[]]$Arguments,
|
||||
[string]$WorkingDirectory
|
||||
)
|
||||
|
||||
Write-Host ">> $FilePath $($Arguments -join ' ')"
|
||||
$previousLocation = Get-Location
|
||||
try {
|
||||
Set-Location -LiteralPath $WorkingDirectory
|
||||
& $FilePath @Arguments
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "命令执行失败,退出码 ${LASTEXITCODE}:$FilePath"
|
||||
}
|
||||
}
|
||||
finally {
|
||||
Set-Location $previousLocation
|
||||
}
|
||||
}
|
||||
|
||||
function Copy-Directory {
|
||||
param(
|
||||
[string]$Source,
|
||||
[string]$Destination
|
||||
)
|
||||
|
||||
if (-not (Test-Path -LiteralPath $Source)) {
|
||||
throw "缺少待打包目录:$Source"
|
||||
}
|
||||
|
||||
New-Item -ItemType Directory -Force -Path $Destination | Out-Null
|
||||
Copy-Item -LiteralPath $Source -Destination $Destination -Recurse -Force
|
||||
}
|
||||
|
||||
function Copy-RequiredFile {
|
||||
param(
|
||||
[string]$Source,
|
||||
[string]$Destination
|
||||
)
|
||||
|
||||
if (-not (Test-Path -LiteralPath $Source)) {
|
||||
throw "缺少待打包文件:$Source"
|
||||
}
|
||||
|
||||
Copy-Item -LiteralPath $Source -Destination $Destination -Force
|
||||
}
|
||||
|
||||
function Write-Step {
|
||||
param([string]$Message)
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "==> $Message"
|
||||
}
|
||||
|
||||
$maven = Resolve-Maven $MavenPath
|
||||
New-Item -ItemType Directory -Force -Path $backendDir, $frontendDir, $miniProgramDir | Out-Null
|
||||
|
||||
$mavenArgs = @("-q", "package")
|
||||
if ($SkipTests) {
|
||||
$mavenArgs += "-DskipTests"
|
||||
}
|
||||
|
||||
Write-Step "构建 JC-ArtList-Core"
|
||||
Invoke-Native $maven $mavenArgs (Join-Path $repoRoot "JC-ArtList-Core")
|
||||
|
||||
Write-Step "构建 JC-ArtList-Gateway"
|
||||
Invoke-Native $maven $mavenArgs (Join-Path $repoRoot "JC-ArtList-Gateway")
|
||||
|
||||
Write-Step "构建 JC-ArtList-Frontend"
|
||||
$frontendRoot = Join-Path $repoRoot "JC-ArtList-Frontend"
|
||||
if (-not (Test-Path -LiteralPath (Join-Path $frontendRoot "node_modules"))) {
|
||||
Invoke-Native "npm" @("ci") $frontendRoot
|
||||
}
|
||||
Invoke-Native "npm" @("run", "build") $frontendRoot
|
||||
|
||||
$coreJar = Join-Path $repoRoot "JC-ArtList-Core\target\JC-ArtList-Core.jar"
|
||||
$gatewayJar = Join-Path $repoRoot "JC-ArtList-Gateway\target\JC-ArtList-Gateway.jar"
|
||||
$frontendDist = Join-Path $frontendRoot "dist"
|
||||
|
||||
Copy-RequiredFile $coreJar (Join-Path $backendDir "JC-ArtList-Core.jar")
|
||||
Copy-RequiredFile $gatewayJar (Join-Path $backendDir "JC-ArtList-Gateway.jar")
|
||||
Copy-Directory $frontendDist (Join-Path $frontendDir "dist")
|
||||
Copy-Directory (Join-Path $repoRoot "JC-ArtList-WeChat") (Join-Path $miniProgramDir "JC-ArtList-WeChat")
|
||||
Copy-Directory (Join-Path $repoRoot "JC-Salon-WeChat") (Join-Path $miniProgramDir "JC-Salon-WeChat")
|
||||
Copy-RequiredFile $sqlPath (Join-Path $releaseDir "FingertipDesigner.sql")
|
||||
|
||||
$manifest = @(
|
||||
"# FingertipDesigner Release $timestamp",
|
||||
"",
|
||||
"- backend/JC-ArtList-Core.jar",
|
||||
"- backend/JC-ArtList-Gateway.jar",
|
||||
"- frontend/dist",
|
||||
"- miniprograms/JC-ArtList-WeChat",
|
||||
"- miniprograms/JC-Salon-WeChat",
|
||||
"- FingertipDesigner.sql",
|
||||
"",
|
||||
"Nacos namespace: FingertipDesigner",
|
||||
"Database initialized by: docs/scripts/sql/init/FingertipDesigner.sql",
|
||||
"Database name: FingertipDesigner",
|
||||
"Manager mini program API: https://yunail.art/api/admin"
|
||||
)
|
||||
$manifest | Set-Content -Encoding UTF8 (Join-Path $releaseDir "README.md")
|
||||
|
||||
$zipPath = "$releaseDir.zip"
|
||||
Compress-Archive -Path (Join-Path $releaseDir "*") -DestinationPath $zipPath -Force
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "发布目录:$releaseDir"
|
||||
Write-Host "发布压缩包:$zipPath"
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,14 @@
|
||||
-- 店务端职责裁剪:移除设计师用户侧购物车、收藏、会员和商品互动结构。
|
||||
-- 执行前必须完成 jayucloud_salon 数据库备份,并在维护窗口执行。
|
||||
SET FOREIGN_KEY_CHECKS = 0;
|
||||
DROP TABLE IF EXISTS t_wishlist;
|
||||
DROP TABLE IF EXISTS t_wishlist_group;
|
||||
DROP TABLE IF EXISTS t_product_like;
|
||||
DROP TABLE IF EXISTS t_cart;
|
||||
DROP TABLE IF EXISTS t_vip_info;
|
||||
DROP TABLE IF EXISTS t_vip_benefit;
|
||||
DROP TABLE IF EXISTS t_user_growth_record;
|
||||
DROP TABLE IF EXISTS t_user_coupon;
|
||||
DROP TABLE IF EXISTS t_coupon_tag;
|
||||
DROP TABLE IF EXISTS t_coupon;
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
||||
@@ -0,0 +1,13 @@
|
||||
-- 设计师端职责裁剪:移除仅店务管理使用的库存、营销活动和权限审计结构。
|
||||
-- 执行前必须完成 jayucloud_artlist 数据库备份,并在维护窗口执行。
|
||||
SET FOREIGN_KEY_CHECKS = 0;
|
||||
DROP TABLE IF EXISTS t_inventory_record;
|
||||
DROP TABLE IF EXISTS t_inventory_item;
|
||||
DROP TABLE IF EXISTS t_campaign;
|
||||
DROP TABLE IF EXISTS t_security_audit_log;
|
||||
DROP TABLE IF EXISTS t_user_shop_role;
|
||||
DROP TABLE IF EXISTS t_shop_role_permission;
|
||||
DROP TABLE IF EXISTS t_shop_role;
|
||||
DROP TABLE IF EXISTS t_user_permission;
|
||||
DROP TABLE IF EXISTS t_permission;
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
||||
@@ -0,0 +1,92 @@
|
||||
-- 员工排班规则和例外,保留 t_artist_schedule 作为预约校验使用的具体日期排班表。
|
||||
use fingertipdesigner;
|
||||
DROP PROCEDURE IF EXISTS sp_fd_add_index_if_not_exists;
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE sp_fd_add_index_if_not_exists(
|
||||
IN p_table_name varchar(128),
|
||||
IN p_index_name varchar(128),
|
||||
IN p_index_sql varchar(1000)
|
||||
)
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM information_schema.statistics
|
||||
WHERE table_schema = DATABASE()
|
||||
AND table_name = p_table_name
|
||||
AND index_name = p_index_name
|
||||
) THEN
|
||||
SET @fd_sql = CONCAT('ALTER TABLE ', p_table_name, ' ADD INDEX ', p_index_name, ' ', p_index_sql);
|
||||
PREPARE fd_stmt FROM @fd_sql;
|
||||
EXECUTE fd_stmt;
|
||||
DEALLOCATE PREPARE fd_stmt;
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
||||
DROP PROCEDURE IF EXISTS sp_fd_add_unique_index_if_not_exists;
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE sp_fd_add_unique_index_if_not_exists(
|
||||
IN p_table_name varchar(128),
|
||||
IN p_index_name varchar(128),
|
||||
IN p_index_sql varchar(1000)
|
||||
)
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM information_schema.statistics
|
||||
WHERE table_schema = DATABASE()
|
||||
AND table_name = p_table_name
|
||||
AND index_name = p_index_name
|
||||
) THEN
|
||||
SET @fd_sql = CONCAT('ALTER TABLE ', p_table_name, ' ADD UNIQUE INDEX ', p_index_name, ' ', p_index_sql);
|
||||
PREPARE fd_stmt FROM @fd_sql;
|
||||
EXECUTE fd_stmt;
|
||||
DEALLOCATE PREPARE fd_stmt;
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS t_artist_schedule_rule
|
||||
(
|
||||
id bigint unsigned NOT NULL COMMENT '排班规则ID',
|
||||
shop_id bigint unsigned NOT NULL COMMENT '店铺ID',
|
||||
artist_id bigint unsigned NOT NULL COMMENT '美甲师用户ID',
|
||||
preset_type varchar(32) NOT NULL COMMENT '预设类型',
|
||||
work_days varchar(32) NOT NULL COMMENT '工作星期,1-7逗号分隔',
|
||||
start_time time NOT NULL COMMENT '常规开始时间',
|
||||
end_time time NOT NULL COMMENT '常规结束时间',
|
||||
slot_minutes int NOT NULL DEFAULT 60 COMMENT '预约间隔分钟',
|
||||
capacity int NOT NULL DEFAULT 1 COMMENT '同一时间段容量',
|
||||
status tinyint NOT NULL DEFAULT 1 COMMENT '状态:1启用,0停用',
|
||||
remark varchar(255) NULL COMMENT '备注',
|
||||
create_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
update_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
is_delete tinyint NOT NULL DEFAULT 0 COMMENT '逻辑删除',
|
||||
PRIMARY KEY (id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='美甲师常规排班规则表';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS t_artist_schedule_exception
|
||||
(
|
||||
id bigint unsigned NOT NULL COMMENT '排班例外ID',
|
||||
shop_id bigint unsigned NOT NULL COMMENT '店铺ID',
|
||||
artist_id bigint unsigned NOT NULL COMMENT '美甲师用户ID',
|
||||
work_date date NOT NULL COMMENT '例外日期',
|
||||
exception_type varchar(32) NOT NULL COMMENT '例外类型:REST/EXTRA_WORK/CHANGE_SHIFT',
|
||||
start_time time NULL COMMENT '例外开始时间',
|
||||
end_time time NULL COMMENT '例外结束时间',
|
||||
slot_minutes int NOT NULL DEFAULT 60 COMMENT '预约间隔分钟',
|
||||
capacity int NOT NULL DEFAULT 1 COMMENT '同一时间段容量',
|
||||
remark varchar(255) NULL COMMENT '备注',
|
||||
create_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
update_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
is_delete tinyint NOT NULL DEFAULT 0 COMMENT '逻辑删除',
|
||||
PRIMARY KEY (id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='美甲师排班例外表';
|
||||
|
||||
CALL sp_fd_add_unique_index_if_not_exists('t_artist_schedule_rule', 'uk_artist_schedule_rule_artist', '(`shop_id`, `artist_id`, `is_delete`)');
|
||||
CALL sp_fd_add_index_if_not_exists('t_artist_schedule_rule', 'idx_artist_schedule_rule_shop_status', '(`shop_id`, `status`, `is_delete`)');
|
||||
CALL sp_fd_add_unique_index_if_not_exists('t_artist_schedule_exception', 'uk_artist_schedule_exception_date', '(`shop_id`, `artist_id`, `work_date`, `is_delete`)');
|
||||
CALL sp_fd_add_index_if_not_exists('t_artist_schedule_exception', 'idx_artist_schedule_exception_artist_date', '(`artist_id`, `work_date`, `is_delete`)');
|
||||
|
||||
DROP PROCEDURE IF EXISTS sp_fd_add_index_if_not_exists;
|
||||
DROP PROCEDURE IF EXISTS sp_fd_add_unique_index_if_not_exists;
|
||||
@@ -0,0 +1,44 @@
|
||||
# 设计师端与店务端独立部署配置说明
|
||||
|
||||
## 适用范围
|
||||
|
||||
本说明对应 2026-08-25 的双端隔离改造,当前只适配生产环境。设计师端和店务端先保留完整后端代码,分别构建、注册和连接独立资源。
|
||||
|
||||
## 端侧边界
|
||||
|
||||
| 端侧 | 后端目录 | 前端目录 | Nacos namespace | 数据库 |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| 设计师端 | `JC-ArtList-Core`、`JC-ArtList-Gateway` | `JC-ArtList-Frontend`、`JC-ArtList-WeChat` | `jayucloud-artlist` | `jayucloud_artlist` |
|
||||
| 店务端 | `JC-Salon-Core`、`JC-Salon-Gateway` | `JC-Salon-Frontend`、`JC-Salon-WeChat` | `jayucloud-salon` | `jayucloud_salon` |
|
||||
|
||||
店务端可只启动 `JC-Salon-Core` 和 `JC-Salon-Gateway`,不依赖设计师端进程或数据库。
|
||||
|
||||
## Nacos 配置源
|
||||
|
||||
生产配置位于 `nacos/namespaces/prod/<namespace>/DEFAULT_GROUP/`,包含 `core.yaml`、`gateway.yaml`、`infra.yaml`、`secret.yaml` 和 `logging.yaml`。
|
||||
|
||||
配置发布使用 `.gitea/workflows/publish-nacos.yml`,通过 Gitea Secrets 注入 `NACOS_URLS`、`NACOS_USERNAME` 和 `NACOS_PASSWORD`。发布脚本先写入第一个 Nacos 节点,再从至少两个节点读取并按 SHA-256 校验配置内容。
|
||||
|
||||
## 生产中间件入口
|
||||
|
||||
- Nacos 客户端:`192.168.10.11:8848,192.168.10.12:8848,192.168.10.13:8848`。
|
||||
- Nacos 元数据库:`192.168.10.200:3306/nacos`,不使用 ProxySQL `6033`。
|
||||
- 业务数据库:使用中心1 ProxySQL `192.168.10.200:6033`,设计师端连接 `jayucloud_artlist`,店务端连接 `jayucloud_salon`。
|
||||
- Redis:Sentinel master `mymaster`,节点列表来自《中间件服务器信息表.md》生产配置。
|
||||
- RabbitMQ:使用 `mq-prod.internal:5672`,账号、vhost 和密码通过 Gitea Secrets 或部署环境注入。
|
||||
- 对象存储:生产 bucket 统一使用 `jayucloud`,各供应商 Endpoint 和密钥通过私有配置注入。
|
||||
|
||||
## 数据库脚本
|
||||
|
||||
- `docs/scripts/sql/migrations/20260825-双端独立数据库/设计师独立数据库_20260825.sql`
|
||||
- `docs/scripts/sql/migrations/20260825-双端独立数据库/店务独立数据库_20260825.sql`
|
||||
|
||||
两份脚本均为完整可执行空库初始化脚本,不修改冻结的 `docs/scripts/sql/init/FingertipDesigner.sql`,本次不迁移既有生产数据。
|
||||
|
||||
## 发布前验证
|
||||
|
||||
1. 分别构建 `JC-ArtList-Core/JC-ArtList-Gateway/JC-ArtList-Frontend` 和 `JC-Salon-Core/JC-Salon-Gateway/JC-Salon-Frontend`。
|
||||
2. 只启动店务 Core/Gateway,确认服务注册为 `jc-salon-core` 和 `jc-salon-gateway`。
|
||||
3. 确认店务 datasource 指向 `jayucloud_salon`,设计师 datasource 指向 `jayucloud_artlist`。
|
||||
4. 发布 Nacos 配置后,从两个节点读取相同 Data ID 并校验摘要一致。
|
||||
5. 完成店务 Web、小程序登录、员工、客户、排班、规划、预约、订单和设置冒烟验证后,再进行后端裁剪。
|
||||
@@ -0,0 +1,19 @@
|
||||
# 开发环境Nacos默认地址配置说明
|
||||
|
||||
## 当前配置
|
||||
|
||||
- `JC-ArtList-Core/src/main/resources/bootstrap.yaml` 和 `JC-ArtList-Gateway/src/main/resources/bootstrap.yaml` 保留 `NACOS_SERVER_ADDR`、`NACOS_NAMESPACE`、`NACOS_GROUP`、`NACOS_USERNAME`、`NACOS_PASSWORD` 环境变量覆盖方式。
|
||||
- 未设置环境变量时,默认连接开发环境 Nacos:`192.168.5.103:8848`。
|
||||
- 未设置环境变量时,默认命名空间为开发环境:`FingertipDesigner-Dev`。
|
||||
- 默认分组为:`DEFAULT_GROUP`。
|
||||
|
||||
## 服务器信息依据
|
||||
|
||||
- `D:\doc\服务器信息.xlsx` 和 `D:\doc\prod-server-info-fd-db-switch-updated-20260623-145728.xlsx` 中记录:开发/测试使用单节点 `nacos04 192.168.5.103`。
|
||||
- 同表记录生产 Nacos 为三节点集群:`192.168.5.101:8848,192.168.5.102:8848,192.168.10.145:8848`。
|
||||
|
||||
## 部署要求
|
||||
|
||||
- 开发环境可以直接使用默认值。
|
||||
- 生产环境必须显式设置 `NACOS_SERVER_ADDR` 为生产三节点集群地址,并设置 `NACOS_NAMESPACE=FingertipDesigner`。
|
||||
- 生产环境必须通过运行环境注入 Nacos 账号和密码,不依赖开发默认值。
|
||||
@@ -0,0 +1,32 @@
|
||||
# 指尖管理师上线配置说明
|
||||
|
||||
## 生产配置约定
|
||||
|
||||
- 生产域名:`https://yunail.art`。
|
||||
- 指尖管理师小程序管理端 API:`https://yunail.art/api/admin`。
|
||||
- 网关对外管理端入口:`/api/admin/**`。
|
||||
- Core 内部管理端入口:`/admin/**`。
|
||||
- 生产数据库名:`FingertipDesigner`,Linux MySQL 环境下必须保持大小写一致。
|
||||
- 生产 Nacos namespace:`FingertipDesigner`。
|
||||
|
||||
## Nacos 必填配置
|
||||
|
||||
生产 namespace 下必须存在以下配置文件:
|
||||
|
||||
- `core.yaml`
|
||||
- `gateway.yaml`
|
||||
- `infra.yaml`
|
||||
- `secret.yaml`
|
||||
- `logging.yaml`
|
||||
|
||||
`infra.yaml` 至少需要确认 MySQL、Redis、RabbitMQ、MyBatis-Plus 相关配置。`secret.yaml` 至少需要确认 MySQL 密码、Redis 密码、RabbitMQ 密码、JWT 密钥、微信小程序配置、七牛 Kodo 密钥。对象存储使用七牛 Kodo 作为主存储时,必须填写 `QINIU_KODO_ACCESS_KEY`、`QINIU_KODO_SECRET_KEY`、`QINIU_KODO_BUCKET_NAME`、`QINIU_KODO_DOMAIN`、`QINIU_KODO_ZONE`。
|
||||
|
||||
如启用阿里云 OSS 作为备份存储,必须同时启用 `ALIYUN_OSS_ENABLED=true` 并填写 endpoint、region、bucket、access key。若暂不使用备份存储,发布前需要确认对象存储备份队列和定时补偿不会影响主链路。
|
||||
|
||||
## 发布前确认项
|
||||
|
||||
- 微信后台已配置 `https://yunail.art` 为合法请求域名。
|
||||
- 指尖管理师小程序与用户端小程序是否共用 appid 已经过产品/发布负责人确认。
|
||||
- Core 与 Gateway 的生产端口和健康检查地址已与 systemd、Nginx、部署脚本保持一致。
|
||||
- 上传大小限制已确认:当前 Servlet 单文件限制为 5MB,单请求限制为 10MB。
|
||||
- 初始化 SQL 仅用于空库首次部署;已有生产库必须使用版本变更 SQL,不允许直接执行初始化 SQL 覆盖升级。
|
||||
@@ -0,0 +1,138 @@
|
||||
# 接回 MinIO 三副本对象存储配置说明
|
||||
|
||||
## 当前结论
|
||||
|
||||
- 开发 MinIO 服务健康检查已通过:`http://192.168.5.15:9000/minio/health/live` 返回 `200 OK`。
|
||||
- 开发 MinIO Console 可访问:`http://192.168.5.15:9001`。
|
||||
- `192.168.5.15` 的 `9090`、`80`、`443` 端口未作为 MinIO 服务端口开放。
|
||||
- 开发 Nacos 地址按服务器信息表确认为:`192.168.5.103:8848`。
|
||||
- 本地 `bootstrap.yaml` 只保留开发 Nacos 地址与命名空间默认值,不再保留 Nacos 用户名和密码默认值;启动时必须通过环境变量注入。
|
||||
- 已使用有写权限的 Nacos 账号在开发 Nacos 创建 `FingertipDesigner-Dev` 命名空间,并发布 `core.yaml`、`gateway.yaml`、`infra.yaml`、`secret.yaml`、`logging.yaml` 五个配置。
|
||||
- 已只读核对 `FingertipDesigner-Dev`:`core.yaml` 包含三 Provider 顺序,`infra.yaml` 包含 `http://192.168.5.15:9000` 和 `fingertipdesigner` bucket,`secret.yaml` 未保留旧 `nailart` bucket、旧 MinIO endpoint 或 camelCase MinIO key。
|
||||
|
||||
## 代码配置约定
|
||||
|
||||
对象存储 Provider 标识固定为:
|
||||
|
||||
- `MINIO`
|
||||
- `QINIU_KODO`
|
||||
- `ALIYUN_OSS`
|
||||
|
||||
对象存储优先级固定为:
|
||||
|
||||
```yaml
|
||||
object-storage:
|
||||
provider-order:
|
||||
- MINIO
|
||||
- QINIU_KODO
|
||||
- ALIYUN_OSS
|
||||
replica-required-providers:
|
||||
- MINIO
|
||||
- QINIU_KODO
|
||||
- ALIYUN_OSS
|
||||
```
|
||||
|
||||
旧字段 `primary-provider`、`backup-provider` 仅保留兼容展示和旧数据,不再作为三副本调度的唯一事实来源。
|
||||
|
||||
## Nacos 配置归属
|
||||
|
||||
`core.yaml` 放业务策略:
|
||||
|
||||
```yaml
|
||||
object-storage:
|
||||
provider-order:
|
||||
- MINIO
|
||||
- QINIU_KODO
|
||||
- ALIYUN_OSS
|
||||
replica-required-providers:
|
||||
- MINIO
|
||||
- QINIU_KODO
|
||||
- ALIYUN_OSS
|
||||
primary-provider: MINIO
|
||||
backup-provider: QINIU_KODO,ALIYUN_OSS
|
||||
signed-url-expire-minutes: 60
|
||||
backup-queue-name: fingertip-designer.file.object-storage.backup.queue
|
||||
backup-exchange-name: fingertip-designer.file.object-storage.backup.exchange
|
||||
backup-routing-key: fingertip-designer.file.object-storage.backup
|
||||
backup-retry-batch-limit: 500
|
||||
backup-retry-cron: "0 0 2 * * ?"
|
||||
```
|
||||
|
||||
`infra.yaml` 放非敏感基础设施信息:
|
||||
|
||||
```yaml
|
||||
minio:
|
||||
enabled: true
|
||||
endpoint: http://192.168.5.15:9000
|
||||
bucket-name: fingertipdesigner
|
||||
private-bucket: true
|
||||
signed-url-expire-minutes: 60
|
||||
|
||||
qiniu:
|
||||
kodo:
|
||||
bucket-name: fingertipdesigner
|
||||
domain: 需要按实际七牛域名填写
|
||||
zone: z2
|
||||
private-bucket: true
|
||||
signed-url-expire-minutes: 60
|
||||
|
||||
aliyun:
|
||||
oss:
|
||||
enabled: true
|
||||
endpoint: 需要按实际 OSS endpoint 填写
|
||||
region: 需要按实际 region 填写
|
||||
bucket-name: fingertipdesigner
|
||||
signed-url-expire-minutes: 60
|
||||
```
|
||||
|
||||
`secret.yaml` 放敏感信息:
|
||||
|
||||
```yaml
|
||||
minio:
|
||||
access-key: 通过 Nacos 控制台填写
|
||||
secret-key: 通过 Nacos 控制台填写
|
||||
|
||||
qiniu:
|
||||
kodo:
|
||||
access-key: 通过 Nacos 控制台填写
|
||||
secret-key: 通过 Nacos 控制台填写
|
||||
|
||||
aliyun:
|
||||
oss:
|
||||
access-key-id: 通过 Nacos 控制台填写
|
||||
access-key-secret: 通过 Nacos 控制台填写
|
||||
```
|
||||
|
||||
`gateway.yaml`、`logging.yaml` 保持现有职责,不放对象存储密钥。
|
||||
|
||||
## 开发环境 Nacos 手工动作
|
||||
|
||||
1. 在 `192.168.5.103:8848` 创建命名空间 `FingertipDesigner-Dev`。
|
||||
2. 从现有 `FingertipDesigner` 命名空间复制 `core.yaml`、`gateway.yaml`、`infra.yaml`、`secret.yaml`、`logging.yaml`。
|
||||
3. 将开发环境 MySQL、Redis、RabbitMQ 保持为开发内网地址。
|
||||
4. 将 MinIO endpoint 改为 `http://192.168.5.15:9000`。
|
||||
5. 将 MinIO bucket 改为 `fingertipdesigner`,不要复用旧 bucket。
|
||||
6. 发布后启动 Core/Gateway 验证服务注册到 `FingertipDesigner-Dev`。
|
||||
7. 启动 Core/Gateway 并完成上传冒烟验证后,再停止使用或删除开发 Nacos 上旧的 `FingertipDesigner` 命名空间配置。
|
||||
|
||||
## MinIO bucket 要求
|
||||
|
||||
- bucket 名称:`fingertipdesigner`
|
||||
- bucket 权限:建议私有。
|
||||
- 必须确认 Core 服务使用的 MinIO access key 对该 bucket 具备上传、下载、删除和签名 URL 所需权限。
|
||||
- 本次不迁移旧 bucket 中的历史对象;历史文件会优先按已有七牛或阿里云副本读取,并由副本补偿任务尝试补齐 MinIO。
|
||||
|
||||
## 数据库变更
|
||||
|
||||
必须执行版本变更 SQL:
|
||||
|
||||
MinIO 三副本对象存储所需表结构已经并入 `docs/scripts/sql/init/FingertipDesigner.sql`。开发、测试和上线空库只执行该初始化 SQL。
|
||||
|
||||
该脚本会新增 `t_object_storage_file_replica`,并为历史文件生成 `MINIO`、`QINIU_KODO`、`ALIYUN_OSS` 三类副本记录。已有成功副本不会被覆盖,缺失副本会进入待上传状态,由重试任务补齐。
|
||||
|
||||
## 回滚方式
|
||||
|
||||
1. 将 `object-storage.provider-order` 改回只包含当前可用 Provider。
|
||||
2. 将 `object-storage.replica-required-providers` 改回当前需要补齐的 Provider 集合。
|
||||
3. 如需停止 MinIO,设置 `minio.enabled=false`。
|
||||
4. 不删除 `t_object_storage_file_replica` 表;保留副本事实便于后续恢复和排查。
|
||||
@@ -0,0 +1,26 @@
|
||||
# 生产对象存储与中间件配置调整说明 2026-08-25
|
||||
|
||||
## 变更范围
|
||||
|
||||
- 更新两个生产 namespace 的 `core.yaml` 与 `infra.yaml`。
|
||||
- 补齐 MinIO、七牛云 Kodo、阿里云 OSS 的非敏感默认连接参数。
|
||||
|
||||
## 生产对象存储
|
||||
|
||||
- MinIO 默认主入口为 `http://192.168.10.105:9000`,中心2 `http://192.168.20.15:9000` 仅用于灾备接管,不配置为客户端多地址。
|
||||
- 七牛云 Kodo 使用私有空间 `jayucloud`、华南区域 `z2` 和 `https://img.yunail.art`。
|
||||
- 阿里云 OSS 使用私有桶 `jayucloud`、成都区域 `cn-chengdu` 和 `https://oss-cn-chengdu.aliyuncs.com`。
|
||||
- AccessKey、SecretKey 和其他敏感凭据继续仅由环境变量或 Gitea Secrets 注入,不写入 Git。
|
||||
|
||||
## 其他中间件核对
|
||||
|
||||
- 业务 MySQL 保持中心1 ProxySQL 入口 `192.168.10.200:6033`。
|
||||
- Redis 保持 `mymaster` 和五个 Sentinel 节点。
|
||||
- RabbitMQ 保持 `mq-prod.internal:5672`。
|
||||
- Nacos 元数据库仍应仅使用 `192.168.10.200:3306/nacos`,不使用 ProxySQL。
|
||||
|
||||
## 发布与验证
|
||||
|
||||
- 本次只更新 Git 管理的生产 Nacos 配置源,未向生产 Nacos 发布。
|
||||
- 发布后需从至少两个 Nacos 节点读取 `core.yaml` 与 `infra.yaml`,确认两个 namespace 的摘要一致。
|
||||
- 发布前验证生产节点可访问中心1 MinIO `9000`、Redis Sentinel、RabbitMQ 和业务数据库入口。
|
||||
@@ -0,0 +1,10 @@
|
||||
# 管理师小程序本地接口地址配置说明
|
||||
|
||||
管理师小程序的接口域名由 `JC-Salon-WeChat/utils/config.js` 统一生成。
|
||||
|
||||
- 微信开发者工具运行时,`develop` 环境默认使用 `local`,接口地址为 `http://127.0.0.1:80/api`,管理端接口地址为 `http://127.0.0.1:80/api/admin`。
|
||||
- 真机开发版默认使用 `http://wcy111.top:18888`,避免真机把 `127.0.0.1` 识别为手机本机地址。
|
||||
- 体验版和正式版默认使用 `https://yunail.art`。
|
||||
- 如需本地临时切换到 tunnel 或远程开发地址,可复制 `JC-Salon-WeChat/utils/config.local.example.js` 为 `JC-Salon-WeChat/utils/config.local.js`,再调整 `developTarget` 或 `domains`。
|
||||
- 已登录的非安全请求默认启用请求签名,`config.local.js` 可通过 `enableRequestSigning: false` 临时关闭本地覆盖,但不要提交关闭签名的配置。
|
||||
- `config.local.js` 属于个人本地覆盖配置,已加入 `.gitignore`,不要提交到仓库。
|
||||
@@ -0,0 +1,19 @@
|
||||
# 统一数据库名为 FingertipDesigner 配置说明
|
||||
|
||||
## 变更内容
|
||||
|
||||
- 后端默认 JDBC 地址统一指向 `FingertipDesigner`。
|
||||
- 初始化 SQL 的数据库创建语句和 `USE` 语句统一使用 `FingertipDesigner`。
|
||||
- 测试说明文档中的数据库名前缀同步为 `FingertipDesigner`。
|
||||
|
||||
## 配置要求
|
||||
|
||||
- Nacos 或本地 `spring.datasource.url` 必须指向 `jdbc:mysql://<host>:<port>/FingertipDesigner`。
|
||||
- Core 与 Gateway 默认 Nacos 命名空间为 `FingertipDesigner`,如需连接其他环境必须显式设置 `NACOS_NAMESPACE`。
|
||||
- MySQL 中必须存在 `FingertipDesigner` 数据库;首次部署可执行 `docs/scripts/sql/init/FingertipDesigner.sql`。
|
||||
- 开发、测试和上线空库只执行 `docs/scripts/sql/init/FingertipDesigner.sql`;已部署生产库如需调整库名,需要单独制定生产迁移方案。
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 本次变更不迁移旧库数据。
|
||||
- 如旧环境存在历史数据库,需先确认数据不再使用后再手工清理。
|
||||
Reference in New Issue
Block a user