From 12a3bf2f3b39eaf0c6359af313891cbce563f2c7 Mon Sep 17 00:00:00 2001 From: que01 Date: Fri, 23 Oct 2026 16:59:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20runner=20=E8=BF=81?= =?UTF-8?q?=E7=A7=BB=E5=90=8E=E7=9A=84=E9=83=A8=E7=BD=B2=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/ci.yml | 1 + docs/runner-setup.md | 2 +- docs/template-management-delivery-plan.md | 2 + docs/visual-editor-next-steps.md | 2 +- scripts/deploy/status.mjs | 101 ++++++++++++++-------- scripts/deploy/status.test.mjs | 32 +++++++ 6 files changed, 102 insertions(+), 38 deletions(-) create mode 100644 scripts/deploy/status.test.mjs diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index cd5dda3..3414601 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -45,6 +45,7 @@ jobs: - run: pnpm install --frozen-lockfile - run: pnpm check - run: pnpm test:api-routes + - run: pnpm test:deploy - run: pnpm validate:templates - run: pnpm template:compatibility - run: pnpm --filter @personal-brand/api exec tsx --test test/template-preview-matrix.test.ts diff --git a/docs/runner-setup.md b/docs/runner-setup.md index 348f6ec..9476712 100644 --- a/docs/runner-setup.md +++ b/docs/runner-setup.md @@ -69,7 +69,7 @@ du -sh ~/gitea-runner/cache-data ~/gitea-runner/pnpm-store `pnpm-store` 会持续增长。确认没有 job 运行时,可以执行 `pnpm store prune` 清理未被引用的包(在任意任务容器里对 `/workspace/.pnpm-store` 执行,或直接删除旧目录后让下一次 job 重新填充)。 -仓库侧 `pnpm deploy:status` 也会打印 `ci-runner=` 一行。 +`pnpm deploy:status` 只检查 VPS 服务、备份和公网路由,不再把 CI runner 当作生产健康条件。runner 已迁到本地工作站,脚本会额外打印非阻断的 `ci-runner-local=`,也可以直接用上面的 `systemctl --user status gitea-runner.service` 检查。 ## 排障 diff --git a/docs/template-management-delivery-plan.md b/docs/template-management-delivery-plan.md index 93e5ea8..329663b 100644 --- a/docs/template-management-delivery-plan.md +++ b/docs/template-management-delivery-plan.md @@ -8,6 +8,8 @@ > > 架构决策:ADR 0029:模板管理、导入与分发边界 +> 状态校正(2026-10-23):当前 `pnpm template:doctor` 对 `acheng-campus-food`、`atelier-solopreneur`、`linjing-editorial` 均返回 `staticStatus=pass`、`completionStatus=complete`、`unresolvedIssues=0`。下方 2026-10-17/18 记录中的 `unverified` 是历史证据,不代表当前状态。该报告只证明自动化证据齐全,不替代 Phase 8 的真实品牌操作、微信外部验证和运营审阅。 + 本文档把模板从本地开发、导出、线上导入、校验、预览、安装到小程序发布的完整工作固化为一个可追踪任务。后续代码、迁移、接口、后台页面、测试证据和已知缺口都必须回到本文登记。本文描述的是目标和实施门禁;没有对应代码、测试和运行证据的条目不能标记为完成。 ## 1. 背景和目标 diff --git a/docs/visual-editor-next-steps.md b/docs/visual-editor-next-steps.md index 1a54a1b..10c89cf 100644 --- a/docs/visual-editor-next-steps.md +++ b/docs/visual-editor-next-steps.md @@ -75,4 +75,4 @@ Admin 直接复用 Taro renderer,模板原始 CSS 按 750 设计宽度转换 ## 本轮边界 -本次先制定计划,功能实施尚未开始。聚焦内容编辑,不做任意拖拽布局或 HTML 入库。保留模板视觉和 H5 回退;不重置数据库或 seed,必要结构调整先制定兼容迁移。 +截至 2026-10-23,`.codex-tasks/visual-editor-closure/SUBTASKS.csv` 中的 5 个子任务均已标记 `DONE`;本文保留为实现范围、验收标准和后续回归依据,当前状态以该 CSV 和实际验证记录为准。本轮仍聚焦内容编辑,不做任意拖拽布局或 HTML 入库。保留模板视觉和 H5 回退;不重置数据库或 seed,必要结构调整先制定兼容迁移。 diff --git a/scripts/deploy/status.mjs b/scripts/deploy/status.mjs index 5761d8a..8fa4a24 100644 --- a/scripts/deploy/status.mjs +++ b/scripts/deploy/status.mjs @@ -1,9 +1,10 @@ import path from "node:path"; import { spawnSync } from "node:child_process"; -import { fileURLToPath } from "node:url"; +import { fileURLToPath, pathToFileURL } from "node:url"; const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../.."); const target = process.env.DEPLOY_TARGET ?? "oracle_arm"; +const deployRoot = process.env.DEPLOY_ROOT ?? "/home/ubuntu/persional-brand"; const publicBaseUrl = (process.env.PUBLIC_BASE_URL ?? "https://wechat.app.que01.top").replace( /\/$/, "", @@ -21,41 +22,69 @@ function shellQuote(value) { return "'" + value.replace(/'/g, "'\\''") + "'"; } -const remoteScript = [ - "set -euo pipefail", - 'source "$HOME/.nvm/nvm.sh"', - "export DEPLOY_ROOT=/home/ubuntu/persional-brand", - 'printf "current=%s\\n" "$(readlink /home/ubuntu/persional-brand/current)"', - 'printf "api="; test "$(pm2 pid personal-brand-api)" != "0"; echo online', - 'printf "pm2-autostart="; systemctl --user is-enabled personal-brand-pm2.service', - 'printf "admin="; systemctl --user is-active personal-brand-admin-static.service', - 'printf "database="; docker inspect -f "{{.State.Status}}" personal-brand-postgres-1', - 'printf "ci-runner="; systemctl --user is-active gitea-runner.service', - 'printf "backups="; find /home/ubuntu/persional-brand/shared/backups -maxdepth 1 -name "*.dump" | wc -l', - 'printf "latest-backup="; newest=$(find /home/ubuntu/persional-brand/shared/backups -maxdepth 1 -type f -name "*.dump" -printf "%T@ %p\\n" | sort -nr | head -1 | cut -d" " -f2-); test -n "$newest"; stat -c "%y %s bytes" "$newest"; docker exec -i personal-brand-postgres-1 pg_restore -l < "$newest" >/dev/null; echo readable', - 'printf "backup-temp-files="; find /home/ubuntu/persional-brand/shared/backups -maxdepth 1 -type f -name "*.tmp" | wc -l', - 'printf "disk="; df -h / | awk \'NR==2 {print $5 " used, " $4 " free"}\'', - 'printf "release-count="; find /home/ubuntu/persional-brand/releases -mindepth 1 -maxdepth 1 -type d | wc -l', -].join("; "); +/** + * 生产状态检查只覆盖 VPS 上的服务和公网路由。 + * CI runner 已迁到本地工作站,不能再把远端 gitea-runner.service 当成生产健康条件。 + */ +export function buildRemoteStatusScript({ deployRoot: rootPath = deployRoot } = {}) { + if (!/^\/[a-zA-Z0-9_./-]+$/.test(rootPath)) throw new Error("Invalid deployment root"); -run("ssh", [target, "bash -lc " + shellQuote(remoteScript)]); + return [ + "set -euo pipefail", + 'source "$HOME/.nvm/nvm.sh"', + `export DEPLOY_ROOT=${shellQuote(rootPath)}`, + 'printf "current=%s\\n" "$(readlink "$DEPLOY_ROOT/current")"', + 'printf "api="; test "$(pm2 pid personal-brand-api)" != "0"; echo online', + 'printf "pm2-autostart="; systemctl --user is-enabled personal-brand-pm2.service', + 'printf "admin="; systemctl --user is-active personal-brand-admin-static.service', + 'printf "database="; docker inspect -f "{{.State.Status}}" personal-brand-postgres-1', + 'printf "backups="; find "$DEPLOY_ROOT/shared/backups" -maxdepth 1 -name "*.dump" | wc -l', + 'printf "latest-backup="; newest=$(find "$DEPLOY_ROOT/shared/backups" -maxdepth 1 -type f -name "*.dump" -printf "%T@ %p\\n" | sort -nr | head -1 | cut -d" " -f2-); test -n "$newest"; stat -c "%y %s bytes" "$newest"; docker exec -i personal-brand-postgres-1 pg_restore -l < "$newest" >/dev/null; echo readable', + 'printf "backup-temp-files="; find "$DEPLOY_ROOT/shared/backups" -maxdepth 1 -type f -name "*.tmp" | wc -l', + 'printf "disk="; df -h / | awk \'NR==2 {print $5 " used, " $4 " free"}\'', + 'printf "release-count="; find "$DEPLOY_ROOT/releases" -mindepth 1 -maxdepth 1 -type d | wc -l', + ].join("; "); +} -for (const route of [ - "/admin/", - "/template-preview/", - "/api/health", - "/media/seed/food-package-02.jpg", -]) { - run("curl", [ - "--fail", - "--silent", - "--show-error", - "--max-time", - "10", - "-o", - "/dev/null", - "-w", - route + " %{http_code}\\n", - publicBaseUrl + route, - ]); +/** + * CI runner 与生产状态是两件事。这里只做本地提示,runner 不活跃不应阻断部署状态检查。 + */ +function printLocalRunnerStatus() { + const result = spawnSync("systemctl", ["--user", "is-active", "gitea-runner.service"], { + encoding: "utf8", + }); + const state = (result.stdout || "").trim(); + process.stdout.write(`ci-runner-local=${state || "unknown"}\n`); +} + +function main() { + if (!/^[a-zA-Z0-9_.@:-]+$/.test(target)) throw new Error("Invalid deployment SSH target"); + if (!/^\/[a-zA-Z0-9_./-]+$/.test(deployRoot)) throw new Error("Invalid deployment root"); + + run("ssh", [target, "bash -lc " + shellQuote(buildRemoteStatusScript())]); + printLocalRunnerStatus(); + + for (const route of [ + "/admin/", + "/template-preview/", + "/api/health", + "/media/seed/food-package-02.jpg", + ]) { + run("curl", [ + "--fail", + "--silent", + "--show-error", + "--max-time", + "10", + "-o", + "/dev/null", + "-w", + route + " %{http_code}\\n", + publicBaseUrl + route, + ]); + } +} + +if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) { + main(); } diff --git a/scripts/deploy/status.test.mjs b/scripts/deploy/status.test.mjs new file mode 100644 index 0000000..d5a5b83 --- /dev/null +++ b/scripts/deploy/status.test.mjs @@ -0,0 +1,32 @@ +import assert from "node:assert/strict"; +import { spawnSync } from "node:child_process"; +import test from "node:test"; +import { buildRemoteStatusScript } from "./status.mjs"; + +test("生产状态脚本不再要求 VPS 上运行 CI runner", () => { + const script = buildRemoteStatusScript(); + + assert.doesNotMatch(script, /gitea-runner/); + assert.match(script, /pm2 pid personal-brand-api/); + assert.match(script, /pg_restore -l/); +}); + +test("生产状态脚本语法有效", () => { + const result = spawnSync("bash", ["-n"], { + input: buildRemoteStatusScript(), + encoding: "utf8", + }); + + assert.equal(result.status, 0, result.stderr); +}); + +test("生产状态脚本使用调用方指定的部署目录", () => { + const script = buildRemoteStatusScript({ deployRoot: "/srv/personal-brand" }); + + assert.match(script, /DEPLOY_ROOT='\/srv\/personal-brand'/); + assert.match(script, /"\$DEPLOY_ROOT\/current"/); +}); + +test("非法部署目录会被拒绝", () => { + assert.throws(() => buildRemoteStatusScript({ deployRoot: "/srv/personal brand" }), /Invalid/); +});