Files
persionalBrand/docs/runner-setup.md
T

66 lines
4.2 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 上。当前使用本地工作站 `Elitebook`(x86_64、12 核、30 GB,Docker 容器执行),旧的 `oracle_arm` runner 已停止并禁用。本文件记录可复现的安装步骤,避免换机器时重新摸索。
## 一次性准备
1. 在 Gitea 仓库 Settings → Actions → Runners 里创建注册 token(只对单个仓库或整个实例生效)。
2. 目标主机需要:Docker、`curl`、`xz`、systemd;Node 不需要(任务容器自带)。`ufw` 和 `sudo` 仅在需要配置防火墙或 linger 时使用。
## 安装
把仓库里的脚本拷到目标主机后执行:
```bash
GITEA_URL=https://git.example.com \
RUNNER_TOKEN=<注册 token> \
RUNNER_NAME=elitebook-local \
RUNNER_LABELS=ubuntu-latest,local-x64 \
RUNNER_CAPACITY=2 \
RUNNER_CONTAINER_OPTIONS='--cpus=4 --memory=8g' \
SKIP_LINGER=1 \
./install-runner.sh
```
加 `DRY_RUN=1` 可先看它准备执行哪些命令(token 会被替换成 `***`)。
脚本做的事:
1. 按架构下载 `gitea-runner-<version>-linux-<arch>`,校验 `.sha256` 后解压到 `~/gitea-runner`。
2. 用 `--no-interactive` 注册,写出 `.runner`(已存在则跳过,可重复执行)。
3. 生成 `config.yaml`:按 `RUNNER_CAPACITY` 设置并发,使用 `docker://node:24-bookworm` 标签,内置 cache server 监听 `172.17.0.1:8193`,并按 `RUNNER_CONTAINER_OPTIONS` 限制任务容器资源。
4. 为下载的 runner 二进制补上可执行权限,避免归档解压后出现 `Permission denied`。
5. 装 systemd user unit `gitea-runner.service`,执行 `loginctl enable-linger` 后 `enable --now`。
6. 放行任务容器到 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 突然变慢 | 缓存是否命中;宿主机负载与磁盘余量 |
| 本机开发明显变慢 | 是否同时运行 build/api job;用 `docker stats` 检查任务容器资源 |
| 重启后 runner 没起来 | `loginctl show-user "$USER" -p Linger` 应为 `Linger=yes`;否则执行 `sudo loginctl enable-linger "$USER"` |
## 约束
- 本地 runner 使用 `capacity: 2`,每个任务容器限制 `4 CPU / 8 GB`;按宿主资源调整,不要超过实际可用内存。
- 本地 runner 关机或休眠时,required checks 会保持 queued。需要开机自启时执行 `sudo loginctl enable-linger "$USER"`,否则用户会话退出后服务会停止。
- 日志级别保持 `debug`:`info` 级别不记录各 step 的结果行,排障时等于没有日志。
- 完整浏览器回归不进入定时或 main 推送 CI;PR 只运行轻量 browser smoke(见 `docs/ci.md`),完整套件仍在发布前执行。