Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
12a3bf2f3b | ||
|
|
ca6d1712bd | ||
|
|
e7ef0b3ce5 | ||
|
|
b82aa12875 |
No files matched your search
@@ -18,6 +18,8 @@ concurrency:
|
|||||||
env:
|
env:
|
||||||
NODE_VERSION: "24"
|
NODE_VERSION: "24"
|
||||||
PNPM_VERSION: "9.15.0"
|
PNPM_VERSION: "9.15.0"
|
||||||
|
# runner 任务容器把该路径 bind mount 到宿主机共享 store,避免每个 job 重复下载依赖。
|
||||||
|
npm_config_store_dir: /workspace/.pnpm-store
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
static:
|
static:
|
||||||
@@ -32,7 +34,6 @@ jobs:
|
|||||||
- uses: actions/setup-node@v4
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: ${{ env.NODE_VERSION }}
|
node-version: ${{ env.NODE_VERSION }}
|
||||||
cache: pnpm
|
|
||||||
- name: Restore Turbo cache
|
- name: Restore Turbo cache
|
||||||
uses: actions/cache@v4
|
uses: actions/cache@v4
|
||||||
with:
|
with:
|
||||||
@@ -44,6 +45,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
|
||||||
@@ -63,7 +65,6 @@ jobs:
|
|||||||
- uses: actions/setup-node@v4
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: ${{ env.NODE_VERSION }}
|
node-version: ${{ env.NODE_VERSION }}
|
||||||
cache: pnpm
|
|
||||||
- name: Restore Turbo cache
|
- name: Restore Turbo cache
|
||||||
uses: actions/cache@v4
|
uses: actions/cache@v4
|
||||||
with:
|
with:
|
||||||
@@ -91,7 +92,6 @@ jobs:
|
|||||||
- uses: actions/setup-node@v4
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: ${{ env.NODE_VERSION }}
|
node-version: ${{ env.NODE_VERSION }}
|
||||||
cache: pnpm
|
|
||||||
- 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
|
||||||
@@ -133,7 +133,6 @@ jobs:
|
|||||||
- uses: actions/setup-node@v4
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: ${{ env.NODE_VERSION }}
|
node-version: ${{ env.NODE_VERSION }}
|
||||||
cache: pnpm
|
|
||||||
- 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
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
# RUNNER_ROOT 默认 $HOME/gitea-runner
|
# RUNNER_ROOT 默认 $HOME/gitea-runner
|
||||||
# RUNNER_CAPACITY 默认 1,按 runner 主机资源设置并发数
|
# RUNNER_CAPACITY 默认 1,按 runner 主机资源设置并发数
|
||||||
# RUNNER_CONTAINER_OPTIONS 默认 "--cpus=1.5 --memory=4g"
|
# RUNNER_CONTAINER_OPTIONS 默认 "--cpus=1.5 --memory=4g"
|
||||||
|
# RUNNER_PNPM_STORE 宿主机 pnpm store 目录,默认 $RUNNER_ROOT/pnpm-store
|
||||||
# RUNNER_IMAGE 任务容器镜像,默认 node:24-bookworm;本地预构建镜像可传 personal-brand-ci:node24
|
# RUNNER_IMAGE 任务容器镜像,默认 node:24-bookworm;本地预构建镜像可传 personal-brand-ci:node24
|
||||||
# CACHE_PORT 默认 8193
|
# CACHE_PORT 默认 8193
|
||||||
# RUNNER_CACHE_HOST 默认 172.17.0.1(Docker 默认 bridge 网关)
|
# RUNNER_CACHE_HOST 默认 172.17.0.1(Docker 默认 bridge 网关)
|
||||||
@@ -29,6 +30,7 @@ RUNNER_VERSION=${RUNNER_VERSION:-5.2.0}
|
|||||||
RUNNER_ROOT=${RUNNER_ROOT:-$HOME/gitea-runner}
|
RUNNER_ROOT=${RUNNER_ROOT:-$HOME/gitea-runner}
|
||||||
RUNNER_CAPACITY=${RUNNER_CAPACITY:-1}
|
RUNNER_CAPACITY=${RUNNER_CAPACITY:-1}
|
||||||
RUNNER_CONTAINER_OPTIONS=${RUNNER_CONTAINER_OPTIONS:-"--cpus=1.5 --memory=4g"}
|
RUNNER_CONTAINER_OPTIONS=${RUNNER_CONTAINER_OPTIONS:-"--cpus=1.5 --memory=4g"}
|
||||||
|
RUNNER_PNPM_STORE=${RUNNER_PNPM_STORE:-$RUNNER_ROOT/pnpm-store}
|
||||||
RUNNER_IMAGE=${RUNNER_IMAGE:-node:24-bookworm}
|
RUNNER_IMAGE=${RUNNER_IMAGE:-node:24-bookworm}
|
||||||
CACHE_PORT=${CACHE_PORT:-8193}
|
CACHE_PORT=${CACHE_PORT:-8193}
|
||||||
RUNNER_CACHE_HOST=${RUNNER_CACHE_HOST:-172.17.0.1}
|
RUNNER_CACHE_HOST=${RUNNER_CACHE_HOST:-172.17.0.1}
|
||||||
@@ -58,7 +60,7 @@ run() {
|
|||||||
archive="gitea-runner-${RUNNER_VERSION}-linux-${ARCH}.xz"
|
archive="gitea-runner-${RUNNER_VERSION}-linux-${ARCH}.xz"
|
||||||
base="https://dl.gitea.com/gitea-runner/${RUNNER_VERSION}"
|
base="https://dl.gitea.com/gitea-runner/${RUNNER_VERSION}"
|
||||||
|
|
||||||
run mkdir -p "$RUNNER_ROOT" "$CACHE_DIR"
|
run mkdir -p "$RUNNER_ROOT" "$CACHE_DIR" "$RUNNER_PNPM_STORE"
|
||||||
if [ ! -x "$RUNNER_ROOT/gitea-runner-${RUNNER_VERSION}-linux-${ARCH}" ]; then
|
if [ ! -x "$RUNNER_ROOT/gitea-runner-${RUNNER_VERSION}-linux-${ARCH}" ]; then
|
||||||
run curl -fsSL -o "$RUNNER_ROOT/$archive" "$base/$archive"
|
run curl -fsSL -o "$RUNNER_ROOT/$archive" "$base/$archive"
|
||||||
run curl -fsSL -o "$RUNNER_ROOT/$archive.sha256" "$base/$archive.sha256"
|
run curl -fsSL -o "$RUNNER_ROOT/$archive.sha256" "$base/$archive.sha256"
|
||||||
@@ -66,6 +68,12 @@ if [ ! -x "$RUNNER_ROOT/gitea-runner-${RUNNER_VERSION}-linux-${ARCH}" ]; then
|
|||||||
run xz -d -f "$RUNNER_ROOT/$archive"
|
run xz -d -f "$RUNNER_ROOT/$archive"
|
||||||
fi
|
fi
|
||||||
run chmod +x "$RUNNER_ROOT/gitea-runner-${RUNNER_VERSION}-linux-${ARCH}"
|
run chmod +x "$RUNNER_ROOT/gitea-runner-${RUNNER_VERSION}-linux-${ARCH}"
|
||||||
|
|
||||||
|
# 把 pnpm store 挂到所有任务容器的固定路径;workflow 通过 npm_config_store_dir 指向它。
|
||||||
|
case " $RUNNER_CONTAINER_OPTIONS " in
|
||||||
|
*"/workspace/.pnpm-store"*) ;;
|
||||||
|
*) RUNNER_CONTAINER_OPTIONS="$RUNNER_CONTAINER_OPTIONS --volume=${RUNNER_PNPM_STORE}:/workspace/.pnpm-store" ;;
|
||||||
|
esac
|
||||||
run ln -sf "gitea-runner-${RUNNER_VERSION}-linux-${ARCH}" "$RUNNER_ROOT/gitea-runner"
|
run ln -sf "gitea-runner-${RUNNER_VERSION}-linux-${ARCH}" "$RUNNER_ROOT/gitea-runner"
|
||||||
|
|
||||||
label_specs() {
|
label_specs() {
|
||||||
@@ -102,7 +110,8 @@ cache:
|
|||||||
port: ${CACHE_PORT}
|
port: ${CACHE_PORT}
|
||||||
container:
|
container:
|
||||||
options: "${RUNNER_CONTAINER_OPTIONS}"
|
options: "${RUNNER_CONTAINER_OPTIONS}"
|
||||||
valid_volumes: []
|
valid_volumes:
|
||||||
|
- ${RUNNER_PNPM_STORE}
|
||||||
docker_host: "-"
|
docker_host: "-"
|
||||||
CONFIG
|
CONFIG
|
||||||
|
|
||||||
|
|||||||
+4
-2
@@ -35,7 +35,9 @@ Runner 与本地开发工作共用 `Elitebook` 主机,不再与生产 API 共
|
|||||||
|
|
||||||
## 缓存
|
## 缓存
|
||||||
|
|
||||||
Runner 内置 cache server(`cache.host=172.17.0.1`、`cache.port=8193`、`cache.dir=~/gitea-runner/cache-data`),供 `actions/setup-node` 的 pnpm 缓存使用。
|
Runner 内置 cache server(`cache.host=172.17.0.1`、`cache.port=8193`、`cache.dir=~/gitea-runner/cache-data`),供 `actions/cache` 使用(Turbo 缓存等)。
|
||||||
|
|
||||||
|
pnpm 依赖不再走 actions/cache:宿主机 `~/gitea-runner/pnpm-store` 被 bind mount 到任务容器的 `/workspace/.pnpm-store`,workflow 的 `npm_config_store_dir` 指向该路径。同一轮 CI 里的 static、build、api、browser-smoke 共享一份 store,`pnpm install` 只做链接/校验,不再重复下载 1600+ 个包。
|
||||||
|
|
||||||
如果 runner 主机启用了 `ufw`,任务容器到 cache server 的流量会被 `INPUT DROP` 拦截,需要显式放行 Docker 使用的三个私网网段;本地工作站未启用 `ufw`,无需配置:
|
如果 runner 主机启用了 `ufw`,任务容器到 cache server 的流量会被 `INPUT DROP` 拦截,需要显式放行 Docker 使用的三个私网网段;本地工作站未启用 `ufw`,无需配置:
|
||||||
|
|
||||||
@@ -79,7 +81,7 @@ Runner 日志级别保持 `debug`:`info` 级别不会记录各 step 的 `Succe
|
|||||||
| Production build | 11.7 min | 7.6 min |
|
| Production build | 11.7 min | 7.6 min |
|
||||||
| API integration | 9.7 min | 3.8 min |
|
| API integration | 9.7 min | 3.8 min |
|
||||||
|
|
||||||
缓存内容为 pnpm store,首次落盘约 268 MB,位于 `~/gitea-runner/cache-data`。
|
缓存内容为 pnpm store,首次落盘约 1.1 GB,位于 `~/gitea-runner/pnpm-store`(共享 bind mount)。
|
||||||
|
|
||||||
## 触发范围
|
## 触发范围
|
||||||
|
|
||||||
|
|||||||
+10
-5
@@ -19,6 +19,7 @@ RUNNER_LABELS=ubuntu-latest,local-x64 \
|
|||||||
RUNNER_CAPACITY=2 \
|
RUNNER_CAPACITY=2 \
|
||||||
RUNNER_CONTAINER_OPTIONS='--cpus=4 --memory=8g' \
|
RUNNER_CONTAINER_OPTIONS='--cpus=4 --memory=8g' \
|
||||||
RUNNER_IMAGE=personal-brand-ci:node24 \
|
RUNNER_IMAGE=personal-brand-ci:node24 \
|
||||||
|
RUNNER_PNPM_STORE=$HOME/gitea-runner/pnpm-store \
|
||||||
SKIP_LINGER=1 \
|
SKIP_LINGER=1 \
|
||||||
./install-runner.sh
|
./install-runner.sh
|
||||||
```
|
```
|
||||||
@@ -30,9 +31,10 @@ SKIP_LINGER=1 \
|
|||||||
1. 按架构下载 `gitea-runner-<version>-linux-<arch>`,校验 `.sha256` 后解压到 `~/gitea-runner`。
|
1. 按架构下载 `gitea-runner-<version>-linux-<arch>`,校验 `.sha256` 后解压到 `~/gitea-runner`。
|
||||||
2. 用 `--no-interactive` 注册,写出 `.runner`(已存在则跳过,可重复执行)。
|
2. 用 `--no-interactive` 注册,写出 `.runner`(已存在则跳过,可重复执行)。
|
||||||
3. 生成 `config.yaml`:按 `RUNNER_CAPACITY` 设置并发,使用 `RUNNER_IMAGE`(默认 `node:24-bookworm`)作为任务容器镜像,内置 cache server 监听 `172.17.0.1:8193`,并按 `RUNNER_CONTAINER_OPTIONS` 限制任务容器资源。
|
3. 生成 `config.yaml`:按 `RUNNER_CAPACITY` 设置并发,使用 `RUNNER_IMAGE`(默认 `node:24-bookworm`)作为任务容器镜像,内置 cache server 监听 `172.17.0.1:8193`,并按 `RUNNER_CONTAINER_OPTIONS` 限制任务容器资源。
|
||||||
4. 为下载的 runner 二进制补上可执行权限,避免归档解压后出现 `Permission denied`。
|
4. 把 `RUNNER_PNPM_STORE`(默认 `~/gitea-runner/pnpm-store`)bind mount 到任务容器的 `/workspace/.pnpm-store`;workflow 通过 `npm_config_store_dir` 指向同一路径,所有 job 复用这份 pnpm store,避免重复下载依赖。
|
||||||
5. 装 systemd user unit `gitea-runner.service`,执行 `loginctl enable-linger` 后 `enable --now`。
|
5. 为下载的 runner 二进制补上可执行权限,避免归档解压后出现 `Permission denied`。
|
||||||
6. 放行任务容器到 cache 端口的 ufw 规则。
|
6. 装 systemd user unit `gitea-runner.service`,执行 `loginctl enable-linger` 后 `enable --now`。
|
||||||
|
7. 放行任务容器到 cache 端口的 ufw 规则。
|
||||||
|
|
||||||
## 专用 CI 镜像
|
## 专用 CI 镜像
|
||||||
|
|
||||||
@@ -62,10 +64,12 @@ systemctl --user restart gitea-runner.service
|
|||||||
```bash
|
```bash
|
||||||
systemctl --user status gitea-runner.service
|
systemctl --user status gitea-runner.service
|
||||||
journalctl --user -u gitea-runner -n 100 --no-pager
|
journalctl --user -u gitea-runner -n 100 --no-pager
|
||||||
du -sh ~/gitea-runner/cache-data
|
du -sh ~/gitea-runner/cache-data ~/gitea-runner/pnpm-store
|
||||||
```
|
```
|
||||||
|
|
||||||
仓库侧 `pnpm deploy:status` 也会打印 `ci-runner=` 一行。
|
`pnpm-store` 会持续增长。确认没有 job 运行时,可以执行 `pnpm store prune` 清理未被引用的包(在任意任务容器里对 `/workspace/.pnpm-store` 执行,或直接删除旧目录后让下一次 job 重新填充)。
|
||||||
|
|
||||||
|
`pnpm deploy:status` 只检查 VPS 服务、备份和公网路由,不再把 CI runner 当作生产健康条件。runner 已迁到本地工作站,脚本会额外打印非阻断的 `ci-runner-local=`,也可以直接用上面的 `systemctl --user status gitea-runner.service` 检查。
|
||||||
|
|
||||||
## 排障
|
## 排障
|
||||||
|
|
||||||
@@ -80,6 +84,7 @@ du -sh ~/gitea-runner/cache-data
|
|||||||
## 约束
|
## 约束
|
||||||
|
|
||||||
- 本地 runner 使用 `capacity: 2`,每个任务容器限制 `4 CPU / 8 GB`;按宿主资源调整,不要超过实际可用内存。
|
- 本地 runner 使用 `capacity: 2`,每个任务容器限制 `4 CPU / 8 GB`;按宿主资源调整,不要超过实际可用内存。
|
||||||
|
- `~/gitea-runner/pnpm-store` 是所有 job 共享的 pnpm store。不要删除正在被 job 使用的 store;换 runner 主机时整目录拷贝或重新预热即可。
|
||||||
- 本地 runner 关机或休眠时,required checks 会保持 queued。需要开机自启时执行 `sudo loginctl enable-linger "$USER"`,否则用户会话退出后服务会停止。
|
- 本地 runner 关机或休眠时,required checks 会保持 queued。需要开机自启时执行 `sudo loginctl enable-linger "$USER"`,否则用户会话退出后服务会停止。
|
||||||
- 日志级别保持 `debug`:`info` 级别不记录各 step 的结果行,排障时等于没有日志。
|
- 日志级别保持 `debug`:`info` 级别不记录各 step 的结果行,排障时等于没有日志。
|
||||||
- 完整浏览器回归不进入定时或 main 推送 CI;PR 只运行轻量 browser smoke(见 `docs/ci.md`),完整套件仍在发布前执行。
|
- 完整浏览器回归不进入定时或 main 推送 CI;PR 只运行轻量 browser smoke(见 `docs/ci.md`),完整套件仍在发布前执行。
|
||||||
@@ -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. 背景和目标
|
||||||
|
|||||||
@@ -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
@@ -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();
|
||||||
}
|
}
|
||||||
@@ -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/);
|
||||||
|
});
|
||||||
Reference in new issue
Block a user