ci: 预构建 runner 镜像并预装 Playwright 依赖
CI / Static checks (pull_request) Successful in 1m49s
CI / Browser smoke (pull_request) Has been cancelled
CI / API integration (pull_request) Has been cancelled
CI / Production build (pull_request) Successful in 2m38s

This commit is contained in:
que01 committed 2026-10-23 15:52:24 +08:00
1 parent 965dd10219
commit b43b6f2785
5 files changed
+57 -4

No files matched your search

+2 -1
View File
@@ -99,7 +99,8 @@ jobs:
path: ~/.cache/ms-playwright
key: playwright-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('pnpm-lock.yaml') }}
- name: Install Chromium
run: pnpm --filter @personal-brand/taro exec playwright install --with-deps chromium
# 系统依赖与同版本 Chromium 已预装在 personal-brand-ci:node24 中;这里只做版本兜底。
run: pnpm --filter @personal-brand/taro exec playwright install chromium
- name: Run PR browser smoke
run: pnpm test:browser:smoke
+25
View File
@@ -0,0 +1,25 @@
# 本地 CI 任务容器基础镜像:Node 24 + pnpm + Playwright 运行依赖。
# 构建(在仓库根目录执行):
# docker build -f deploy/runner/Dockerfile -t personal-brand-ci:node24 .
# Playwright 版本需与 apps/taro/package.json 保持一致;升级 Playwright 后重建本镜像。
FROM node:24-bookworm
ARG PNPM_VERSION=9.15.0
ARG PLAYWRIGHT_VERSION=1.58.2
ENV PNPM_HOME=/usr/local/share/pnpm
ENV PATH=${PNPM_HOME}:${PATH}
RUN apt-get update \
&& apt-get install -y --no-install-recommends jq unzip \
&& rm -rf /var/lib/apt/lists/*
RUN corepack enable \
&& corepack prepare pnpm@${PNPM_VERSION} --activate \
&& pnpm --version
# 预装 Chromium 的系统依赖和浏览器本体,避免每个 job 重复执行 apt 与下载。
RUN npx --yes playwright@${PLAYWRIGHT_VERSION} install --with-deps chromium \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /workspace
+8 -2
View File
@@ -15,6 +15,7 @@
# RUNNER_ROOT 默认 $HOME/gitea-runner
# RUNNER_CAPACITY 默认 1,按 runner 主机资源设置并发数
# RUNNER_CONTAINER_OPTIONS 默认 "--cpus=1.5 --memory=4g"
# RUNNER_IMAGE 任务容器镜像,默认 node:24-bookworm;本地预构建镜像可传 personal-brand-ci:node24
# CACHE_PORT 默认 8193
# RUNNER_CACHE_HOST 默认 172.17.0.1(Docker 默认 bridge 网关)
# SKIP_LINGER 默认 0;设为 1 时不尝试用 sudo 开启 linger
@@ -28,6 +29,7 @@ RUNNER_VERSION=${RUNNER_VERSION:-5.2.0}
RUNNER_ROOT=${RUNNER_ROOT:-$HOME/gitea-runner}
RUNNER_CAPACITY=${RUNNER_CAPACITY:-1}
RUNNER_CONTAINER_OPTIONS=${RUNNER_CONTAINER_OPTIONS:-"--cpus=1.5 --memory=4g"}
RUNNER_IMAGE=${RUNNER_IMAGE:-node:24-bookworm}
CACHE_PORT=${CACHE_PORT:-8193}
RUNNER_CACHE_HOST=${RUNNER_CACHE_HOST:-172.17.0.1}
CACHE_DIR=${CACHE_DIR:-$RUNNER_ROOT/cache-data}
@@ -66,13 +68,17 @@ fi
run chmod +x "$RUNNER_ROOT/gitea-runner-${RUNNER_VERSION}-linux-${ARCH}"
run ln -sf "gitea-runner-${RUNNER_VERSION}-linux-${ARCH}" "$RUNNER_ROOT/gitea-runner"
label_specs() {
printf '%s\n' "$RUNNER_LABELS" | tr ',' '\n' | sed "s|^\(.*\)$|\1:docker://${RUNNER_IMAGE}|"
}
if [ ! -f "$RUNNER_ROOT/.runner" ]; then
run env -C "$RUNNER_ROOT" ./gitea-runner register \
--no-interactive \
--instance "$GITEA_URL" \
--token "$RUNNER_TOKEN" \
--name "$RUNNER_NAME" \
--labels "$RUNNER_LABELS"
--labels "$(label_specs | paste -sd, -)"
fi
if [ -f "$RUNNER_ROOT/.runner" ]; then
run chmod 600 "$RUNNER_ROOT/.runner"
@@ -88,7 +94,7 @@ runner:
fetch_timeout: 10s
fetch_interval: 2s
labels:
$(printf '%s\n' "$RUNNER_LABELS" | tr ',' '\n' | sed 's|^\(.*\)$| - "\1:docker://node:24-bookworm"|')
$(label_specs | sed 's|^| - "|; s|$|"|')
cache:
enabled: true
dir: ${CACHE_DIR}
+1
View File
@@ -10,6 +10,7 @@
- 服务:systemd user unit `gitea-runner.service`
- 标签:`ubuntu-latest`、`local-x64`
- 执行模式:Docker,双并发,任务容器限制 `--cpus=4 --memory=8g`
- 任务镜像:`personal-brand-ci:node24`(预装 pnpm 与 Playwright 依赖,见 `deploy/runner/Dockerfile`)
- 作用域:仅 `que01/persionalBrand` 仓库
查看状态:
+21 -1
View File
@@ -18,6 +18,7 @@ RUNNER_NAME=elitebook-local \
RUNNER_LABELS=ubuntu-latest,local-x64 \
RUNNER_CAPACITY=2 \
RUNNER_CONTAINER_OPTIONS='--cpus=4 --memory=8g' \
RUNNER_IMAGE=personal-brand-ci:node24 \
SKIP_LINGER=1 \
./install-runner.sh
```
@@ -28,11 +29,30 @@ SKIP_LINGER=1 \
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` 限制任务容器资源。
3. 生成 `config.yaml`:按 `RUNNER_CAPACITY` 设置并发,使用 `RUNNER_IMAGE`(默认 `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 规则。
## 专用 CI 镜像
`browser-smoke` 需要 Chromium 及其系统库。为避免每个 job 重复执行 `playwright install --with-deps`,本机使用预构建镜像:
```bash
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。
`apps/taro/package.json` 升级 Playwright 后,同步修改 `deploy/runner/Dockerfile` 的 `PLAYWRIGHT_VERSION`,重建镜像并重启 runner:
```bash
docker build -f deploy/runner/Dockerfile -t personal-brand-ci:node24 .
systemctl --user restart gitea-runner.service
```
镜像只在当前主机存在;换 runner 主机时需要重新构建。若在 ARM 主机构建,镜像会按该主机架构原生构建,不需要额外参数。
## 为什么 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` 三条规则。只放行其中一条的后果是缓存恢复/保存各空等数分钟并最终超时。