# Gitea Runner Node.js Gitea Action Runner Node.js 构建环境,基于 `gitea_runner_base` 添加多版本 Node.js 和包管理器。 ## 基础镜像 - `timi/gitea_runner_base:latest` ## 包含环境 | 组件 | 版本 | |------|------| | Node.js | 20.20.0 / 22.23.4 / 24.22.2(musl 构建) | | npm | 随 Node.js | | pnpm | 10.6.0(构建时通过 `PNPM_VERSION` 固定) | | yarn | 未预装,需要时用 `corepack enable` | ## Node.js 版本说明 | 版本 | 状态 | 说明 | |------|------|------| | Node.js 20 | 已 EOL | 仅供旧项目兜底,vite 8 要求 `^20.19.0` | | Node.js 22 | 维护期 | 满足 vite 8 的 `>=22.12.0` | | Node.js 24 | 活跃 LTS | **默认版本** | 默认使用 Node.js 24。 ## 镜像内固定项与原因 | 项 | 值 | 原因 | |------|------|------| | `PNPM_VERSION` | 10.6.0 | 与开发机一致,避免重建镜像后 lockfile 解析行为漂移 | | `NODE_OPTIONS` | `--max-old-space-size=4096` | `vue-tsc --noEmit` 检查大项目在默认堆下会 OOM | | `store-dir` | `/data/pnpm-store` | 落在 compose 挂载的宿主机目录,跨 job 复用依赖缓存 | Alpine 使用 musl,Node 与原生模块都必须使用 musl 平台包。已确认依赖链中的 `@rolldown/binding-linux-x64-musl`、`lightningcss-linux-x64-musl`、`@rollup/rollup-linux-x64-musl` 均存在。 ## 构建 ```bash # 先构建基础镜像 ./rebuild.sh gitea_runner_base # 再构建 Node.js 镜像 ./rebuild.sh gitea_runner_node ``` ## 切换 Node.js 版本 ```bash source use-node 20 source use-node 22 source use-node 24 ``` `use-node` 是 bash 脚本。CI 中调用时必须声明 shell,act_runner 默认使用 `sh -e`: ```yaml - name: Use Node.js 22 shell: bash run: | source use-node 22 node -v ``` ## 包管理器选择 ```bash npm install pnpm install ``` 依赖链项目统一使用 pnpm,`pnpm-lock.yaml` 为 `lockfileVersion: 9.0`。 ## Gitea Action 示例 ```yaml name: Release on: pull_request: branches: [master] types: [closed] jobs: release: runs-on: act_runner_node if: ${{ github.event.pull_request.merged == true }} steps: - uses: actions/checkout@v4 - name: Install dependencies run: pnpm install --frozen-lockfile - name: Build run: pnpm run build ``` ## 环境变量 | 变量 | 默认值 | |------|--------| | `NODE_BASE` | `/usr/local/node` | | `NODE_OPTIONS` | `--max-old-space-size=4096` | ## 常见问题 ### 如何查看已安装的 Node.js 版本? ```bash ls /usr/local/node/versions node -v ``` ### pnpm 报 postinstall 被跳过怎么办? pnpm 10 默认不执行依赖的构建脚本。依赖链项目当前没有需要构建脚本的包(`requiresBuild` 为 0),如后续出现,在项目的 `pnpm-workspace.yaml` 或 `package.json` 中声明 `onlyBuiltDependencies`。