diff --git a/.gitea/workflows/salon-prod-deploy.yml b/.gitea/workflows/salon-prod-deploy.yml index edf960ac..57cfddb4 100644 --- a/.gitea/workflows/salon-prod-deploy.yml +++ b/.gitea/workflows/salon-prod-deploy.yml @@ -42,45 +42,22 @@ jobs: java -version 2>&1 | grep -q '17\.' node --version | grep -q '^v20\.' pwsh --version - - name: 下载已审核发布包 + - name: 读取已审核发布包 shell: bash env: - GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }} - PREPARE_RUN_ID: ${{ inputs.prepare_run_id }} - ARTIFACT_NAME: salon-prod-${{ inputs.release_sha }} + RELEASE_SHA: ${{ inputs.release_sha }} run: | set -euo pipefail - test -n "$GITEA_TOKEN" - test -n "$PREPARE_RUN_ID" - test -n "$ARTIFACT_NAME" - api_base="$GITHUB_SERVER_URL/api/actions_pipeline/_apis/pipelines/workflows/$PREPARE_RUN_ID/artifacts?api-version=6.0-preview" - response_file="$RUNNER_TEMP/salon-prod-artifacts.json" - curl --fail-with-body --silent --show-error --retry 3 --retry-all-errors \ - -H "Authorization: Bearer $GITEA_TOKEN" "$api_base" > "$response_file" - artifact_id=$(node -e 'const fs=require("fs"); const name=process.argv[1]; const data=JSON.parse(fs.readFileSync(process.argv[2],"utf8")); const item=(data.value||[]).find(v=>v.name===name); if(!item||!item.fileContainerResourceUrl) process.exit(2); const m=item.fileContainerResourceUrl.match(/\\/(\\d+)\\/path$/); if(!m) process.exit(3); process.stdout.write(m[1]);' "$ARTIFACT_NAME" "$response_file") - path_url="$GITHUB_SERVER_URL/api/actions_pipeline/_apis/pipelines/workflows/$PREPARE_RUN_ID/artifacts/$artifact_id/path?api-version=6.0-preview" - curl --fail-with-body --silent --show-error --retry 3 --retry-all-errors \ - -H "Authorization: Bearer $GITEA_TOKEN" "$path_url" > "$RUNNER_TEMP/salon-prod-artifact-path.json" + test -n "$RELEASE_SHA" + shared_dir="/salon-release/$RELEASE_SHA" + test -d "$shared_dir" + test -f "$shared_dir/.manifest.sha256" + (cd "$shared_dir" && sha256sum -c .manifest.sha256) mkdir -p artifacts/release - node - "$RUNNER_TEMP/salon-prod-artifact-path.json" "$GITHUB_SERVER_URL" "$PREPARE_RUN_ID" "$artifact_id" "$GITEA_TOKEN" <<'NODE' - const fs = require('fs'); - const { execFileSync } = require('child_process'); - const [pathFile, server, runId, artifactId, token] = process.argv.slice(2); - const data = JSON.parse(fs.readFileSync(pathFile, 'utf8')); - const files = data.value || []; - if (files.length === 0) throw new Error('Artifact 未返回任何文件'); - for (const file of files) { - if (!file.contentLocation || !file.path) throw new Error('Artifact 文件项缺少下载地址或路径'); - const relativePath = file.path.split('/').slice(1).join('/'); - if (!relativePath || relativePath.includes('..')) throw new Error(`非法 Artifact 路径: ${file.path}`); - const output = `artifacts/release/${relativePath}`; - fs.mkdirSync(require('path').dirname(output), { recursive: true }); - execFileSync('curl', ['--fail-with-body', '--silent', '--show-error', '--retry', '3', '--retry-all-errors', '-H', `Authorization: Bearer ${token}`, `${server}${file.contentLocation}?itemPath=${encodeURIComponent(file.path)}`, '-o', output], { stdio: 'inherit' }); - } - NODE + cp -a "$shared_dir/." artifacts/release/ test -f artifacts/release/manifest.json - test -f artifacts/release/backend/JC-Salon-Core.jar || find artifacts/release -name 'JC-Salon-Core.jar' -exec cp {} artifacts/release/backend/JC-Salon-Core.jar \; - test -f artifacts/release/backend/JC-Salon-Gateway.jar || find artifacts/release -name 'JC-Salon-Gateway.jar' -exec cp {} artifacts/release/backend/JC-Salon-Gateway.jar \; + test -f artifacts/release/backend/JC-Salon-Core.jar + test -f artifacts/release/backend/JC-Salon-Gateway.jar - name: 发布并校验 Salon 生产 Nacos shell: bash env: diff --git a/.gitea/workflows/salon-prod-prepare.yml b/.gitea/workflows/salon-prod-prepare.yml index 27f91778..450169cb 100644 --- a/.gitea/workflows/salon-prod-prepare.yml +++ b/.gitea/workflows/salon-prod-prepare.yml @@ -47,13 +47,19 @@ jobs: -PackageOnly -SkipTests -SkipDatabaseInit - - name: 上传发布包 - uses: actions/upload-artifact@v3 - with: - name: salon-prod-${{ github.event.pull_request.merge_commit_sha }} - path: artifacts/release/* - if-no-files-found: error - retention-days: 30 + - name: 保存发布包到共享目录 + shell: bash + env: + RELEASE_SHA: ${{ github.event.pull_request.merge_commit_sha }} + run: | + set -euo pipefail + test -n "$RELEASE_SHA" + shared_dir="/salon-release/$RELEASE_SHA" + rm -rf "$shared_dir" + mkdir -p "$shared_dir" + cp -a artifacts/release/. "$shared_dir/" + test -f "$shared_dir/manifest.json" + (cd "$shared_dir" && sha256sum manifest.json > .manifest.sha256) - name: 输出部署参数 shell: bash env: @@ -66,7 +72,7 @@ jobs: echo "" echo "**release_sha**: \`$RELEASE_SHA\`" echo "" - echo "**Artifact**: \`salon-prod-$RELEASE_SHA\`" + echo "**共享目录**: \`/salon-release/$RELEASE_SHA\`" } >> "$GITHUB_STEP_SUMMARY" echo "prepare_run_id=${{ github.run_id }}" diff --git a/.gitea/workflows/salon-sit-deploy.yml b/.gitea/workflows/salon-sit-deploy.yml new file mode 100644 index 00000000..e46c55f5 --- /dev/null +++ b/.gitea/workflows/salon-sit-deploy.yml @@ -0,0 +1,91 @@ +name: Salon SIT 自动发布 + +on: + push: + branches: + - sit + workflow_dispatch: + +jobs: + deploy: + runs-on: jayucloud + env: + GITHUB_SERVER_URL: http://192.168.5.15:3000 + WEB_TARGET_HOST: ${{ secrets.SALON_PROD_WEB_HOST }} + WEB_TARGET_PORT: ${{ secrets.SALON_PROD_WEB_PORT }} + WEB_TARGET_USER: ${{ secrets.SALON_PROD_WEB_USER }} + WEB_REMOTE_DIR: /opt/jc-salon-frontend-sit + steps: + - name: 从内网 Gitea 检出代码 + shell: bash + env: + GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + set -euo pipefail + test -n "$GITEA_TOKEN" + git init . + git remote add origin "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY.git" + git -c http.extraheader="Authorization: token $GITEA_TOKEN" fetch --no-tags --depth=1 origin "$GITHUB_SHA" + git checkout --detach "$GITHUB_SHA" + - name: 检查发布工具链 + shell: bash + run: | + set -euo pipefail + java -version 2>&1 | grep -q '17\.' + node --version | grep -q '^v20\.' + mvn --version | grep -q 'Java version: 17\.' + pwsh --version + - name: 构建 Salon SIT 发布包 + shell: pwsh + run: >- + ./docs/scripts/deploy-jayucloud-salon-production.ps1 + -PackageOnly + -SkipTests + -SkipDatabaseInit + - name: 写入 SIT SSH 配置和目标清单 + shell: bash + env: + SALON_PROD_SSH_PRIVATE_KEY: ${{ secrets.SALON_PROD_SSH_PRIVATE_KEY }} + SALON_PROD_KNOWN_HOSTS: ${{ secrets.SALON_PROD_KNOWN_HOSTS }} + run: | + set -euo pipefail + test -n "$SALON_PROD_SSH_PRIVATE_KEY" + test -n "$SALON_PROD_KNOWN_HOSTS" + test -n "$WEB_TARGET_HOST" + test -n "$WEB_TARGET_PORT" + test -n "$WEB_TARGET_USER" + mkdir -p "$RUNNER_TEMP/salon-sit" + printf '%s\n' "$SALON_PROD_SSH_PRIVATE_KEY" > "$RUNNER_TEMP/salon-sit/id_ed25519" + printf '%s\n' "$SALON_PROD_KNOWN_HOSTS" > "$RUNNER_TEMP/salon-sit/known_hosts" + chmod 600 "$RUNNER_TEMP/salon-sit/id_ed25519" "$RUNNER_TEMP/salon-sit/known_hosts" + cat > "$RUNNER_TEMP/salon-sit/servers.json" <- + ./docs/scripts/deploy-jayucloud-salon-production.ps1 + -Deploy + -SkipDatabaseInit + -AllowSitTarget + -RequireSystemd + -PackageDirectory "artifacts/release" + -ServerInfoJsonPath "$env:SERVER_INFO_JSON" + -SshKeyPath "$env:SSH_KEY_PATH" + -KnownHostsPath "$env:KNOWN_HOSTS_PATH" + -CoreRemoteAppDir "/opt/jc-salon-core-sit" + -GatewayRemoteAppDir "/opt/jc-salon-gateway-sit" + -CoreServiceName "jc-salon-core-sit" + -GatewayServiceName "jc-salon-gateway-sit" + -CoreHealthPort 181 + -GatewayHealthPort 180 + -WebTargetName "salon-web-sit" + -WebRemoteDir "$env:WEB_REMOTE_DIR" + -PublicBaseUrl "https://sit.yunail.art" diff --git a/docs/scripts/Salon SIT自动发布配置说明_20260901.md b/docs/scripts/Salon SIT自动发布配置说明_20260901.md new file mode 100644 index 00000000..d4af9aa7 --- /dev/null +++ b/docs/scripts/Salon SIT自动发布配置说明_20260901.md @@ -0,0 +1,23 @@ +# Salon SIT 自动发布配置 + +推送到 `sit` 分支后,`.gitea/workflows/salon-sit-deploy.yml` 自动构建并部署 Salon Core、Gateway 和前端;数据库 SQL 只随发布包归档,不自动执行。 + +## 部署目标 + +- Core/Gateway:`192.168.10.106:22`,独立目录 `/opt/jc-salon-core-sit`、`/opt/jc-salon-gateway-sit`,服务名 `jc-salon-core-sit`、`jc-salon-gateway-sit`。 +- 前端:与生产共用阿里云入口服务器,独立目录 `/opt/jc-salon-frontend-sit`,域名 `sit.yunail.art`。 +- SIT 中间件:Nacos `192.168.10.103:8848`、MySQL `192.168.10.102:3306`、Redis `192.168.10.101:6379`、RabbitMQ `192.168.10.104:5672`,由 SIT Nacos 配置注入。 +- 工作流显式传入 `-AllowSitTarget`,仅允许 `Environment=sit` 的目标;生产工作流不传入该开关,仍拒绝非生产节点。 + +## 前置配置 + +1. Gitea Secrets 中已有的 `SALON_PROD_SSH_PRIVATE_KEY`、`SALON_PROD_KNOWN_HOSTS` 和 `SALON_PROD_WEB_*` 用于连接同一阿里云前端服务器;`known_hosts` 必须包含 `192.168.10.106`。 +2. 阿里云 Nginx 新增 `sit.yunail.art` server 配置,将站点根目录指向 `/opt/jc-salon-frontend-sit`,并按现有生产规则代理 `/api`。 +3. Nginx 修改后执行 `nginx -t`,通过后再 reload。 +4. 首次部署前确认 `192.168.10.106` 已安装 Java 17、systemd 可用,且网络可访问 SIT Nacos、MySQL、Redis 和 RabbitMQ。 + +## 验证 + +- 推送 `sit` 后确认工作流完成 Core/Gateway 健康检查和前端文件发布。 +- 检查 `https://sit.yunail.art/`、`/health/check` 及前端静态资源均返回 200。 +- 检查 Nacos `jayucloud-salon` namespace 中服务注册状态和 SIT 配置读取。 diff --git a/docs/scripts/Salon生产发布共享目录配置说明_20260901.md b/docs/scripts/Salon生产发布共享目录配置说明_20260901.md new file mode 100644 index 00000000..fe38107e --- /dev/null +++ b/docs/scripts/Salon生产发布共享目录配置说明_20260901.md @@ -0,0 +1,25 @@ +# Salon 生产发布共享目录配置 + +Prepare 和 Deploy 工作流通过 Runner 宿主机共享目录传递发布包,不再跨运行读取 Gitea Artifact。 + +## Runner 配置 + +在 Runner 宿主机创建目录并设置为 Runner 用户可读写: + +```text +/opt/software/panel/apps/gitea/salon-release +``` + +在 `act_runner/config.yaml` 的 `container.options` 增加目录挂载: + +```yaml +- "--volume=/opt/software/panel/apps/gitea/salon-release:/salon-release:rw" +``` + +修改后重启 `jayucloud-runner`。Prepare 会将包写入 `/salon-release/`,Deploy 使用相同 `release_sha` 读取并校验 `manifest.json`。 + +## 验证 + +1. 在 Runner 任务容器中确认 `/salon-release` 可读写。 +2. 重新运行 Prepare,确认共享目录生成对应 SHA 子目录和 `manifest.json`。 +3. Deploy 输入同一 `release_sha`,确认“读取已审核发布包”步骤通过。 diff --git a/docs/scripts/deploy-jayucloud-salon-production.ps1 b/docs/scripts/deploy-jayucloud-salon-production.ps1 index 8cf0dc40..90028dcb 100644 --- a/docs/scripts/deploy-jayucloud-salon-production.ps1 +++ b/docs/scripts/deploy-jayucloud-salon-production.ps1 @@ -9,6 +9,7 @@ param( [switch]$AllowDirtyWorkingTree, [switch]$SkipDatabaseInit, [switch]$PackageOnly, + [switch]$AllowSitTarget, [switch]$RequireSystemd, [string]$PackageDirectory = "", [string]$ServerInfoJsonPath = "", @@ -379,14 +380,18 @@ function Resolve-ServerInfoPath { } function Assert-ProductionTarget { - param([object[]]$Servers) + param( + [object[]]$Servers, + [switch]$AllowSit + ) $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" }) + $blockedEnvironments = if ($AllowSit) { "(?i)\b(dev|test|local|staging)\b" } else { "(?i)\b(dev|test|local|staging|sit)\b" } + $knownNonProduction = @($Servers | Where-Object { $_.Environment -match $blockedEnvironments }) if ($knownNonProduction.Count -gt 0) { throw "拒绝发布到非生产环境节点:$($knownNonProduction.Name -join ', ')" } @@ -919,7 +924,7 @@ if ((-not $SkipDatabaseInit) -and $databaseServers.Count -ne 1) { throw "数据库初始化目标必须唯一,当前按 $DatabaseTargetName 找到 $($databaseServers.Count) 个。" } -Assert-ProductionTarget (@($coreServers) + @($gatewayServers) + @($webServers)) +Assert-ProductionTarget (@($coreServers) + @($gatewayServers) + @($webServers)) -AllowSit:$AllowSitTarget $databaseServer = if (-not $SkipDatabaseInit) { $databaseServers[0] } else { $null } Write-Host "服务器清单:$resolvedServerInfoPath" diff --git a/docs/业务服务器清单.md b/docs/业务服务器清单.md index e39d156d..bcdaea94 100644 --- a/docs/业务服务器清单.md +++ b/docs/业务服务器清单.md @@ -13,9 +13,22 @@ | gateway01-02 | 生产 | Salon Gateway | `192.168.10.27` | 22 | Rocky Linux 9.8 | 17.0.20.1 | `/opt/jc-salon-gateway` | 已创建发布、备份、日志目录;服务单元待首次部署创建 | | gateway01-03 | 生产 | Salon Gateway | `192.168.20.18` | 22 | Rocky Linux 9.8 | 17.0.20.1 | `/opt/jc-salon-gateway` | 已创建发布、备份、日志目录;服务单元待首次部署创建 | +## SIT 后端服务器 + +| 名称 | 环境 | 角色 | IP 地址 | SSH 端口 | 操作系统 | Java | 应用目录 | systemd 服务名 | 当前状态 | +| ---------- | ---- | ---------------- | ---------------- | ------: | -------------- | ---- | -------------------------------- | ------------------------------- | -------------------- | +| sit-app01 | SIT | Salon Core/Gateway | `192.168.10.106` | 22 | Rocky Linux 9.8 | 17 | `/opt/jc-salon-core-sit`、`/opt/jc-salon-gateway-sit` | `jc-salon-core-sit`、`jc-salon-gateway-sit` | 待首次自动部署创建 | + +## SIT 前端入口 + +| 名称 | 环境 | 角色 | 入口域名 | 部署目录 | 说明 | +| ------------- | ---- | ---------- | ----------------- | -------------------------------- | ----------------------------------------- | +| aliyun01-web | SIT | Salon Nginx | `sit.yunail.art` | `/opt/jc-salon-frontend-sit` | 与生产前端共用阿里云服务器,通过域名区分 | + ## 统一基线 - 6 台服务器 SSH 端口均为 `22`,账号密码均为root,122503wcy....,防火墙由 firewalld 管理并处于运行状态。 - 应用目录及其 `releases`、`backups`、`logs` 子目录权限均为 `755 root:root`。 - 当前未创建或启动 `jc-salon-core`、`jc-salon-gateway` systemd 服务,80/81 业务端口未监听。 - 生产 SSH 凭据、Nacos 凭据和部署私钥由私有凭据管理,不写入本清单。 +- SIT 应用 SSH 端口、账号和凭据沿用生产部署凭据;SIT 使用独立 systemd 服务、应用目录和 Nginx 站点目录,不得复用生产目录。