feat: 支持 GraalVM JDK25 native 镜像与三 runner 并行
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 30s
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 30s
This commit is contained in:
120
doc/devops/gitlab/multiple-runners.md
Normal file
120
doc/devops/gitlab/multiple-runners.md
Normal file
@@ -0,0 +1,120 @@
|
||||
# 部署 3 个 Act Runner 实现并行编译
|
||||
|
||||
## 一、目标与原理
|
||||
|
||||
Gitea Actions 按 **runner 标签**分发 job。三个 runner 都注册标签 `ubuntu-latest`,且每个 runner 默认 `maxParallel=1`,因此最多可同时执行 3 个 job。runner 镜像统一使用 `gitea/act_runner:0.6.1-ci`(见 `custom-runner-image.md`)。
|
||||
|
||||
> 实测同一个注册 token 可以重复用于多个 runner 注册(本次 3 个 runner 均用同一 token 成功注册),无需为新 runner 单独生成 token;若新环境 Gitea 版本限制单次使用,则在管理员页面为每个 runner 重新生成 token。
|
||||
|
||||
## 二、当前环境布局
|
||||
|
||||
| 容器名 | 部署方式 | 数据目录 | 标签 |
|
||||
|---|---|---|---|
|
||||
| `ubuntu-latest` | 1Panel 应用 `/opt/1panel/apps/act_runner/ubuntu-latest` | `./data/data` | `ubuntu-latest` |
|
||||
| `ubuntu-latest-2` | `/opt/act-runners/docker-compose.yml` | `./runner-2/data` | `ubuntu-latest` |
|
||||
| `ubuntu-latest-3` | `/opt/act-runners/docker-compose.yml` | `./runner-3/data` | `ubuntu-latest` |
|
||||
|
||||
新增两个 runner 的 compose(`/opt/act-runners/docker-compose.yml`):
|
||||
|
||||
```yaml
|
||||
networks:
|
||||
1panel-network:
|
||||
external: true
|
||||
services:
|
||||
runner-2:
|
||||
container_name: ubuntu-latest-2
|
||||
image: gitea/act_runner:0.6.1-ci
|
||||
restart: always
|
||||
networks: [1panel-network]
|
||||
environment:
|
||||
- GITEA_INSTANCE_URL=${GITEA_INSTANCE_URL}
|
||||
- GITEA_RUNNER_REGISTRATION_TOKEN=${RUNNER_REGISTRATION_TOKEN}
|
||||
- GITEA_RUNNER_NAME=ubuntu-latest-2
|
||||
- GITEA_RUNNER_LABELS=ubuntu-latest
|
||||
volumes:
|
||||
- ./runner-2/data:/data
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
runner-3:
|
||||
container_name: ubuntu-latest-3
|
||||
image: gitea/act_runner:0.6.1-ci
|
||||
restart: always
|
||||
networks: [1panel-network]
|
||||
environment:
|
||||
- GITEA_INSTANCE_URL=${GITEA_INSTANCE_URL}
|
||||
- GITEA_RUNNER_REGISTRATION_TOKEN=${RUNNER_REGISTRATION_TOKEN}
|
||||
- GITEA_RUNNER_NAME=ubuntu-latest-3
|
||||
- GITEA_RUNNER_LABELS=ubuntu-latest
|
||||
volumes:
|
||||
- ./runner-3/data:/data
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
```
|
||||
|
||||
同目录 `.env` 内容(token 用占位符):
|
||||
|
||||
```env
|
||||
GITEA_INSTANCE_URL=http://gitea:3000
|
||||
RUNNER_REGISTRATION_TOKEN=<TOKEN>
|
||||
```
|
||||
|
||||
启动:
|
||||
|
||||
```bash
|
||||
mkdir -p /opt/act-runners/runner-2/data /opt/act-runners/runner-3/data
|
||||
cd /opt/act-runners
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
## 三、全新环境一步到位(推荐写法)
|
||||
|
||||
如果不依赖 1Panel,可在新环境用同一个 compose 直接管理 3 个 runner(复制 `runner-2` 服务再写 `runner-1`/`runner-3`,仅改 `container_name`、`GITEA_RUNNER_NAME`、数据目录):
|
||||
|
||||
```bash
|
||||
mkdir -p /opt/act-runners/runner-{1,2,3}/data
|
||||
cat > /opt/act-runners/.env <<'EOF'
|
||||
GITEA_INSTANCE_URL=http://gitea:3000
|
||||
RUNNER_REGISTRATION_TOKEN=<TOKEN>
|
||||
EOF
|
||||
# 将上面的 compose 写入 /opt/act-runners/docker-compose.yml,并补齐 runner-1
|
||||
cd /opt/act-runners && docker compose up -d
|
||||
```
|
||||
|
||||
要点:
|
||||
|
||||
- 三个容器都必须挂载 `/var/run/docker.sock`,否则 workflow 的 `docker build/push` 无法执行。
|
||||
- 必须与 Gitea 容器在同一 Docker network,且用 `http://gitea:3000` 访问。
|
||||
- 每个 runner 的数据目录独立,保存各自的 `.runner` 注册文件。
|
||||
|
||||
## 四、验证
|
||||
|
||||
```bash
|
||||
docker ps --format '{{.Names}}\t{{.Status}}' | grep ubuntu-latest
|
||||
# 期望:ubuntu-latest、ubuntu-latest-2、ubuntu-latest-3 均 Up
|
||||
|
||||
for c in ubuntu-latest ubuntu-latest-2 ubuntu-latest-3; do
|
||||
docker logs --tail 10 "$c" | grep 'declare successfully'
|
||||
done
|
||||
```
|
||||
|
||||
并行触发验证(**必须用不同 ref**,原因见下):
|
||||
|
||||
```bash
|
||||
BASE=https://gitea-verify.lightjob.cn/api/v1/repos/poc/springboot-cici-demo
|
||||
for b in parallel-1 parallel-2 parallel-3; do
|
||||
curl -u "$USER:$PASS" -X POST -H 'Content-Type: application/json' \
|
||||
-d "{\"ref\":\"$b\"}" "$BASE/actions/workflows/cicd.yaml/dispatches"
|
||||
done
|
||||
```
|
||||
|
||||
本次实测:3 个分支的 job 分别被三个 runner 接走:
|
||||
|
||||
```text
|
||||
ubuntu-latest: task 9 repo is poc/springboot-cici-demo
|
||||
ubuntu-latest-2: task 10 repo is poc/springboot-cici-demo
|
||||
ubuntu-latest-3: task 11 repo is poc/springboot-cici-demo
|
||||
```
|
||||
|
||||
## 五、并行时的坑
|
||||
|
||||
- 当前 Gitea 会取消**同一 workflow 同一 ref** 上排队中的旧 run。连续对 `master` 做 3 次 dispatch,只有最后一个 run 执行,其余 `cancelled`。想验证并行,请创建不同分支/标签,或使用不同 workflow 文件。
|
||||
- 三个 runner 共享宿主机 Docker 引擎,镜像层与 Maven 依赖可复用;并发构建同一 tag 时后完成者覆盖 `latest`,稳定引用请使用 `<短SHA>-<variant>` tag。
|
||||
- 若宿主机资源有限,可在 compose 里用 `deploy.resources.limits` 限制每个 runner 的 CPU/内存。
|
||||
Reference in New Issue
Block a user