Files
persionalBrand/docs/runner-setup.md
T
que01 1001c43af6
CI / Production build (push) Has been cancelled
CI / API integration (push) Has been cancelled
CI / Static checks (push) Has been cancelled
chore: 提供可复现的 CI runner 安装脚本
2026-10-21 14:41:47 +08:00

61 lines
3.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# CI Runner 安装与运维
CI 跑在自托管 Gitea Actions runner 上(当前主机 `oracle_arm`,与生产 API 共用 2 核)。本文件记录可复现的安装步骤,避免换机器时重新摸索。
## 一次性准备
1. 在 Gitea 仓库 Settings → Actions → Runners 里创建注册 token(只对单个仓库或整个实例生效)。
2. 目标主机需要:Docker、`curl`、`xz`、`ufw`、systemd、可用 sudo、Node 不需要(任务容器自带)。
## 安装
把仓库里的脚本拷到目标主机后执行:
```bash
GITEA_URL=https://git.example.com \
RUNNER_TOKEN=<注册 token> \
RUNNER_NAME=oracle-arm \
RUNNER_LABELS=ubuntu-latest,oracle-arm \
./install-runner.sh
```
加 `DRY_RUN=1` 可先看它准备执行哪些命令(token 会被替换成 `***`)。
脚本做的事:
1. 按架构下载 `gitea-runner-<version>-linux-<arch>`,校验 `.sha256` 后解压到 `~/gitea-runner`。
2. 用 `--no-interactive` 注册,写出 `.runner`(已存在则跳过,可重复执行)。
3. 生成 `config.yaml`:单并发、`docker://node:24-bookworm` 标签、内置 cache server 监听 `172.17.0.1:8193`、任务容器限制 `--cpus=1.5 --memory=4g`。
4. 装 systemd user unit `gitea-runner.service`,执行 `loginctl enable-linger` 后 `enable --now`。
5. 放行任务容器到 cache 端口的 ufw 规则。
## 为什么 ufw 要放行三个网段
任务容器访问宿主机的 cache server 走 Docker bridge,`ufw` 默认 `INPUT DROP` 会直接丢包。Gitea Actions 每个 job 会新建独立 bridge(实测 `192.168.x`),默认 `docker0` 又是 `172.17.x`,所以需要 `172.16.0.0/12`、`192.168.0.0/16`、`10.0.0.0/8` 三条规则。只放行其中一条的后果是缓存恢复/保存各空等数分钟并最终超时。
## 日常检查
```bash
systemctl --user status gitea-runner.service
journalctl --user -u gitea-runner -n 100 --no-pager
du -sh ~/gitea-runner/cache-data
```
仓库侧 `pnpm deploy:status` 也会打印 `ci-runner=` 一行。
## 排障
| 现象 | 先查什么 |
| ----------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
| push 后 CI 一直 queued 不启动 | runner 服务是否 active;Gitea 仓库 Runners 页面是否显示 online |
| 日志出现 `Failed to GetCacheEntryDownloadURL ... ETIMEDOUT` | ufw 是否放行三个私网段;`docker exec <job-container> node -e 'fetch("http://172.17.0.1:8193/")'` 应返回 404 |
| 一轮 CI 突然变慢 | 缓存是否命中;宿主机负载与磁盘余量 |
| 生产 API 变慢 | CI 与生产共用主机,检查是否在跑 build/api job;必要时暂停 runner |
| 重启后 runner 没起来 | `loginctl show-user "$USER" -p Linger` 应为 `Linger=yes`;否则执行 `sudo loginctl enable-linger "$USER"` |
## 约束
- `capacity: 1`:不要提高并发,2 核主机上并发只会让生产和 CI 一起变慢。
- 日志级别保持 `debug`:`info` 级别不记录各 step 的结果行,排障时等于没有日志。
- 浏览器回归不进 CI(见 `docs/ci.md`),因为 Playwright 会长期占用 CPU。