Compare commits

..
Author SHA1 Message Date
que01 447c224fce ci: 预热 Prisma 并移除运行时 Node 下载
CI / Static checks (pull_request) Successful in 1m1s
CI / API integration (pull_request) Successful in 1m26s
CI / Production build (pull_request) Successful in 1m45s
CI / Browser smoke (pull_request) Successful in 50s
2026-10-23 17:37:48 +08:00
que01 12a3bf2f3b fix: 修复 runner 迁移后的部署状态检查
CI / Static checks (pull_request) Successful in 1m34s
CI / Browser smoke (pull_request) Successful in 1m43s
CI / API integration (pull_request) Successful in 2m21s
CI / Production build (pull_request) Successful in 4m1s
2026-10-23 16:59:26 +08:00
que01 ca6d1712bd Merge pull request 'ci: 迁移本地 runner 并优化并行检查' (#5) from ci/local-runner-parallel into main
CI / Browser smoke (push) Has been skipped
CI / Static checks (push) Successful in 1m26s
CI / API integration (push) Successful in 2m1s
CI / Production build (push) Successful in 2m21s
2026-10-23 08:34:58 +00:00
8 changed files with 174 additions and 60 deletions

No files matched your search

+53 -20
View File
@@ -28,12 +28,20 @@ jobs:
timeout-minutes: 40 timeout-minutes: 40
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: pnpm/action-setup@v4 - name: Verify preinstalled toolchain
# 任务镜像已内置 Node 与 pnpm;不在这里下载 Node,避免 nodejs.org 慢连接拖死整个 job。
run: |
actual_node="$(node -p 'process.versions.node')"
actual_pnpm="$(pnpm --version)"
test "${actual_node%%.*}" = "$NODE_VERSION" || { echo "expected Node $NODE_VERSION.x, got $actual_node" >&2; exit 1; }
test "$actual_pnpm" = "$PNPM_VERSION" || { echo "expected pnpm $PNPM_VERSION, got $actual_pnpm" >&2; exit 1; }
- name: Restore Prisma engine cache
uses: actions/cache@v4
with: with:
version: ${{ env.PNPM_VERSION }} path: ~/.cache/prisma
- uses: actions/setup-node@v4 key: prisma-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('pnpm-lock.yaml') }}
with: restore-keys: |
node-version: ${{ env.NODE_VERSION }} prisma-${{ runner.os }}-${{ runner.arch }}-
- name: Restore Turbo cache - name: Restore Turbo cache
uses: actions/cache@v4 uses: actions/cache@v4
with: with:
@@ -45,6 +53,7 @@ jobs:
- run: pnpm install --frozen-lockfile - run: pnpm install --frozen-lockfile
- run: pnpm check - run: pnpm check
- run: pnpm test:api-routes - run: pnpm test:api-routes
- run: pnpm test:deploy
- run: pnpm validate:templates - run: pnpm validate:templates
- run: pnpm template:compatibility - run: pnpm template:compatibility
- run: pnpm --filter @personal-brand/api exec tsx --test test/template-preview-matrix.test.ts - run: pnpm --filter @personal-brand/api exec tsx --test test/template-preview-matrix.test.ts
@@ -58,12 +67,20 @@ jobs:
needs: [static] needs: [static]
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: pnpm/action-setup@v4 - name: Verify preinstalled toolchain
# 任务镜像已内置 Node 与 pnpm;不在这里下载 Node,避免 nodejs.org 慢连接拖死整个 job。
run: |
actual_node="$(node -p 'process.versions.node')"
actual_pnpm="$(pnpm --version)"
test "${actual_node%%.*}" = "$NODE_VERSION" || { echo "expected Node $NODE_VERSION.x, got $actual_node" >&2; exit 1; }
test "$actual_pnpm" = "$PNPM_VERSION" || { echo "expected pnpm $PNPM_VERSION, got $actual_pnpm" >&2; exit 1; }
- name: Restore Prisma engine cache
uses: actions/cache@v4
with: with:
version: ${{ env.PNPM_VERSION }} path: ~/.cache/prisma
- uses: actions/setup-node@v4 key: prisma-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('pnpm-lock.yaml') }}
with: restore-keys: |
node-version: ${{ env.NODE_VERSION }} prisma-${{ runner.os }}-${{ runner.arch }}-
- name: Restore Turbo cache - name: Restore Turbo cache
uses: actions/cache@v4 uses: actions/cache@v4
with: with:
@@ -85,12 +102,20 @@ jobs:
timeout-minutes: 30 timeout-minutes: 30
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: pnpm/action-setup@v4 - name: Verify preinstalled toolchain
# 任务镜像已内置 Node 与 pnpm;不在这里下载 Node,避免 nodejs.org 慢连接拖死整个 job。
run: |
actual_node="$(node -p 'process.versions.node')"
actual_pnpm="$(pnpm --version)"
test "${actual_node%%.*}" = "$NODE_VERSION" || { echo "expected Node $NODE_VERSION.x, got $actual_node" >&2; exit 1; }
test "$actual_pnpm" = "$PNPM_VERSION" || { echo "expected pnpm $PNPM_VERSION, got $actual_pnpm" >&2; exit 1; }
- name: Restore Prisma engine cache
uses: actions/cache@v4
with: with:
version: ${{ env.PNPM_VERSION }} path: ~/.cache/prisma
- uses: actions/setup-node@v4 key: prisma-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('pnpm-lock.yaml') }}
with: restore-keys: |
node-version: ${{ env.NODE_VERSION }} prisma-${{ runner.os }}-${{ runner.arch }}-
- run: pnpm install --frozen-lockfile - run: pnpm install --frozen-lockfile
- name: Cache Playwright browsers - name: Cache Playwright browsers
uses: actions/cache@v4 uses: actions/cache@v4
@@ -126,12 +151,20 @@ jobs:
SEED_ADMIN_PASSWORD: ci-integration-admin-password SEED_ADMIN_PASSWORD: ci-integration-admin-password
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: pnpm/action-setup@v4 - name: Verify preinstalled toolchain
# 任务镜像已内置 Node 与 pnpm;不在这里下载 Node,避免 nodejs.org 慢连接拖死整个 job。
run: |
actual_node="$(node -p 'process.versions.node')"
actual_pnpm="$(pnpm --version)"
test "${actual_node%%.*}" = "$NODE_VERSION" || { echo "expected Node $NODE_VERSION.x, got $actual_node" >&2; exit 1; }
test "$actual_pnpm" = "$PNPM_VERSION" || { echo "expected pnpm $PNPM_VERSION, got $actual_pnpm" >&2; exit 1; }
- name: Restore Prisma engine cache
uses: actions/cache@v4
with: with:
version: ${{ env.PNPM_VERSION }} path: ~/.cache/prisma
- uses: actions/setup-node@v4 key: prisma-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('pnpm-lock.yaml') }}
with: restore-keys: |
node-version: ${{ env.NODE_VERSION }} prisma-${{ runner.os }}-${{ runner.arch }}-
- run: pnpm install --frozen-lockfile - run: pnpm install --frozen-lockfile
- name: Prepare API test env - name: Prepare API test env
working-directory: apps/api working-directory: apps/api
+10
View File
@@ -6,6 +6,8 @@ FROM node:24-bookworm
ARG PNPM_VERSION=9.15.0 ARG PNPM_VERSION=9.15.0
ARG PLAYWRIGHT_VERSION=1.58.2 ARG PLAYWRIGHT_VERSION=1.58.2
# 必须与 pnpm-lock.yaml 中解析出的 Prisma 版本一致;升级 Prisma 后同步修改并重建镜像。
ARG PRISMA_VERSION=6.19.3
ENV PNPM_HOME=/usr/local/share/pnpm ENV PNPM_HOME=/usr/local/share/pnpm
ENV PATH=${PNPM_HOME}:${PATH} ENV PATH=${PNPM_HOME}:${PATH}
@@ -22,4 +24,12 @@ RUN corepack enable \
RUN npx --yes playwright@${PLAYWRIGHT_VERSION} install --with-deps chromium \ RUN npx --yes playwright@${PLAYWRIGHT_VERSION} install --with-deps chromium \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
# 预热 Prisma engines 到 /root/.cache/prisma。CI job 每次都是新容器,若不预热,
# 每个 job 的 prisma generate 都会重新访问 binaries.prisma.sh,网络抖动会直接拖垮 CI。
COPY apps/api/prisma/schema.prisma /tmp/prisma-warmup/schema.prisma
RUN printf '%s\n' '{"name":"prisma-warmup","private":true}' > /tmp/prisma-warmup/package.json \
&& cd /tmp/prisma-warmup \
&& DATABASE_URL=postgresql://warmup:warmup@127.0.0.1:5432/warmup npx --yes prisma@${PRISMA_VERSION} generate --schema schema.prisma \
&& rm -rf /tmp/prisma-warmup /root/.npm
WORKDIR /workspace WORKDIR /workspace
+6
View File
@@ -33,6 +33,12 @@ journalctl --user -u gitea-runner -n 100 --no-pager
Runner 与本地开发工作共用 `Elitebook` 主机,不再与生产 API 共用资源。任务容器限制 4 CPU / 8 GB、并发 2;本地机器关机或休眠时 CI 会排队,required checks 不会自动完成。 Runner 与本地开发工作共用 `Elitebook` 主机,不再与生产 API 共用资源。任务容器限制 4 CPU / 8 GB、并发 2;本地机器关机或休眠时 CI 会排队,required checks 不会自动完成。
## 工具链与外部下载
任务镜像 `personal-brand-ci:node24` 已内置 Node 24 和 pnpm 9.15.0;workflow 不再调用 `actions/setup-node` 或 `pnpm/action-setup`,而是在每个 job 开头执行 `Verify preinstalled toolchain`。这样不会因为 nodejs.org 下载缓慢或中断而把 job 卡到超时。
Prisma engines 在构建镜像时预热到 `/root/.cache/prisma`,job 内 `pnpm install` 触发的 `prisma generate` 直接命中缓存,不再访问 `binaries.prisma.sh`。workflow 仍用 `actions/cache` 缓存该目录,作为更换镜像或镜像未预热时的兜底。升级 Prisma 后必须同步 `deploy/runner/Dockerfile` 的 `PRISMA_VERSION` 并重建镜像。
## 缓存 ## 缓存
Runner 内置 cache server(`cache.host=172.17.0.1`、`cache.port=8193`、`cache.dir=~/gitea-runner/cache-data`),供 `actions/cache` 使用(Turbo 缓存等)。 Runner 内置 cache server(`cache.host=172.17.0.1`、`cache.port=8193`、`cache.dir=~/gitea-runner/cache-data`),供 `actions/cache` 使用(Turbo 缓存等)。
+5 -3
View File
@@ -44,9 +44,11 @@ SKIP_LINGER=1 \
docker build -f deploy/runner/Dockerfile -t personal-brand-ci:node24 . docker build -f deploy/runner/Dockerfile -t personal-brand-ci:node24 .
``` ```
镜像包含 Node 24、pnpm 9.15.0、git/curl/jq/unzip,以及 Playwright 1.58.2 的 Chromium、headless shell、FFmpeg 和系统依赖。构建产物是本机 amd64 镜像(约 3 GB),不推送到 registry。 镜像包含 Node 24、pnpm 9.15.0、git/curl/jq/unzip,以及 Playwright 1.58.2 的 Chromium、headless shell、FFmpeg 和系统依赖;构建时还会预热 Prisma engines 到 `/root/.cache/prisma`。构建产物是本机 amd64 镜像(约 3 GB),不推送到 registry。
`apps/taro/package.json` 升级 Playwright 后,同步修改 `deploy/runner/Dockerfile` 的 `PLAYWRIGHT_VERSION`,重建镜像并重启 runner: workflow 不再使用 `actions/setup-node` 或 `pnpm/action-setup`,而是直接校验镜像内置的 Node/pnpm 版本。因此替换 `RUNNER_IMAGE` 时必须保证镜像内已有 Node 24 和 pnpm 9.15.0,否则 job 会在 `Verify preinstalled toolchain` 步骤失败。
`apps/taro/package.json` 升级 Playwright 后,同步修改 `deploy/runner/Dockerfile` 的 `PLAYWRIGHT_VERSION`;升级 Prisma 后,同步修改 `PRISMA_VERSION`。然后重建镜像并重启 runner:
```bash ```bash
docker build -f deploy/runner/Dockerfile -t personal-brand-ci:node24 . docker build -f deploy/runner/Dockerfile -t personal-brand-ci:node24 .
@@ -69,7 +71,7 @@ du -sh ~/gitea-runner/cache-data ~/gitea-runner/pnpm-store
`pnpm-store` 会持续增长。确认没有 job 运行时,可以执行 `pnpm store prune` 清理未被引用的包(在任意任务容器里对 `/workspace/.pnpm-store` 执行,或直接删除旧目录后让下一次 job 重新填充)。 `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` 检查。
## 排障 ## 排障
@@ -8,6 +8,8 @@
> >
> 架构决策:ADR 0029:模板管理、导入与分发边界 > 架构决策: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. 背景和目标 ## 1. 背景和目标
+1 -1
View File
@@ -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,必要结构调整先制定兼容迁移。
+65 -36
View File
@@ -1,9 +1,10 @@
import path from "node:path"; import path from "node:path";
import { spawnSync } from "node:child_process"; 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 root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
const target = process.env.DEPLOY_TARGET ?? "oracle_arm"; 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( const publicBaseUrl = (process.env.PUBLIC_BASE_URL ?? "https://wechat.app.que01.top").replace(
/\/$/, /\/$/,
"", "",
@@ -21,41 +22,69 @@ function shellQuote(value) {
return "'" + value.replace(/'/g, "'\\''") + "'"; return "'" + value.replace(/'/g, "'\\''") + "'";
} }
const remoteScript = [ /**
"set -euo pipefail", * 生产状态检查只覆盖 VPS 上的服务和公网路由。
'source "$HOME/.nvm/nvm.sh"', * CI runner 已迁到本地工作站,不能再把远端 gitea-runner.service 当成生产健康条件。
"export DEPLOY_ROOT=/home/ubuntu/persional-brand", */
'printf "current=%s\\n" "$(readlink /home/ubuntu/persional-brand/current)"', export function buildRemoteStatusScript({ deployRoot: rootPath = deployRoot } = {}) {
'printf "api="; test "$(pm2 pid personal-brand-api)" != "0"; echo online', if (!/^\/[a-zA-Z0-9_./-]+$/.test(rootPath)) throw new Error("Invalid deployment root");
'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("; ");
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/", * CI runner 与生产状态是两件事。这里只做本地提示,runner 不活跃不应阻断部署状态检查。
"/template-preview/", */
"/api/health", function printLocalRunnerStatus() {
"/media/seed/food-package-02.jpg", const result = spawnSync("systemctl", ["--user", "is-active", "gitea-runner.service"], {
]) { encoding: "utf8",
run("curl", [ });
"--fail", const state = (result.stdout || "").trim();
"--silent", process.stdout.write(`ci-runner-local=${state || "unknown"}\n`);
"--show-error", }
"--max-time",
"10", function main() {
"-o", if (!/^[a-zA-Z0-9_.@:-]+$/.test(target)) throw new Error("Invalid deployment SSH target");
"/dev/null", if (!/^\/[a-zA-Z0-9_./-]+$/.test(deployRoot)) throw new Error("Invalid deployment root");
"-w",
route + " %{http_code}\\n", run("ssh", [target, "bash -lc " + shellQuote(buildRemoteStatusScript())]);
publicBaseUrl + route, 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();
} }
+32
View File
@@ -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/);
});