feat: update gitea & gitea config

This commit is contained in:
Sun-ZhenXing
2026-07-22 15:44:52 +08:00
parent 3432c9da65
commit 87a58d8d04
15 changed files with 1162 additions and 928 deletions
+28 -10
View File
@@ -1,14 +1,32 @@
# Gitea Runner version
GITEA_RUNNER_VERSION=0.2.13
# Optional registry prefix. Include the trailing slash, for example registry.example.com/
GLOBAL_REGISTRY=
# Gitea instance URL
INSTANCE_URL=http://localhost:3000
# Gitea Runner image version.
GITEA_RUNNER_VERSION=2.1.0
# Registration token (get from Gitea settings -> Actions -> Runners)
REGISTRATION_TOKEN=
# Container time zone.
TZ=UTC
# Runner name
RUNNER_NAME=Gitea-Runner
# Gitea URL. It must be reachable from both the runner and job containers.
GITEA_INSTANCE_URL=http://host.docker.internal:3000
# Runner labels
RUNNER_LABELS=DockerRunner
# Required registration token from Gitea Settings -> Actions -> Runners.
GITEA_RUNNER_REGISTRATION_TOKEN=
# Name shown for this runner in Gitea.
GITEA_RUNNER_NAME=Gitea-Runner
# Comma-separated runner labels.
GITEA_RUNNER_LABELS=ubuntu-latest:docker://docker.io/gitea/runner-images:ubuntu-latest,ubuntu-24.04:docker://docker.io/gitea/runner-images:ubuntu-24.04,ubuntu-22.04:docker://docker.io/gitea/runner-images:ubuntu-22.04
# Maximum CPU allocation.
GITEA_RUNNER_CPU_LIMIT=1.0
# Maximum memory allocation.
GITEA_RUNNER_MEMORY_LIMIT=2G
# Reserved CPU allocation.
GITEA_RUNNER_CPU_RESERVATION=0.1
# Reserved memory allocation.
GITEA_RUNNER_MEMORY_RESERVATION=1G
+48 -44
View File
@@ -2,56 +2,60 @@
[English](./README.md) | [中文](./README.zh.md)
This service sets up a Gitea Runner.
## Prerequisites
1. Generate the `config.yaml` file:
```bash
docker run --entrypoint="" --rm -it gitea/act_runner:0.2.13 act_runner generate-config > config.yaml
```
2. Configure `config.yaml`, for example:
```yaml
cache:
enabled: true
dir: ''
host: 192.168.8.17
port: 8088
```
3. Configure environment variables:
```properties
INSTANCE_URL=http://xxx:3000
REGISTRATION_TOKEN=xxxxxx
RUNNER_NAME=runner-1
RUNNER_LABELS=xxxxxx
```
## Start the Runner
```bash
docker compose up -d
```
This stack runs Gitea Runner 2.1.0 for Gitea Actions. The Compose service is `gitea_runner`; it executes jobs in Docker containers through the host Docker daemon.
## Services
- `runner`: The Gitea Runner service.
- `gitea_runner`: Registers with Gitea and creates Docker containers for Actions jobs.
## Prerequisite
Create a runner registration token in Gitea under **Settings -> Actions -> Runners**. The token is required.
## Quick Start
```bash
cp .env.example .env
# Set GITEA_RUNNER_REGISTRATION_TOKEN in .env and, when needed, GITEA_INSTANCE_URL.
docker compose up -d
```
The default `http://host.docker.internal:3000` targets a Gitea server published on port 3000 of the Docker host. Compose maps that hostname to the host gateway for the runner, and `config.yaml` does the same for job containers. Change the URL for a remote Gitea server, another port, or a deployment not reachable through the host; the selected URL must be reachable from both the runner and job containers.
## Configuration
### Environment Variables
| Variable | Default | Description |
| --------------------------------------------------------------- | ------------------------------------------------------------- | ----------------------------------------------------------------------------- |
| `GLOBAL_REGISTRY` | empty | Optional registry prefix, including its trailing `/`. |
| `GITEA_RUNNER_VERSION` | `2.1.0` | Runner image version. |
| `TZ` | `UTC` | Container time zone. |
| `GITEA_INSTANCE_URL` | `http://host.docker.internal:3000` | Gitea URL reachable by the runner and jobs. |
| `GITEA_RUNNER_REGISTRATION_TOKEN` | empty | Required registration token. |
| `GITEA_RUNNER_NAME` | `Gitea-Runner` | Runner name shown in Gitea. |
| `GITEA_RUNNER_LABELS` | `ubuntu-latest`, `ubuntu-24.04`, `ubuntu-22.04` Docker labels | Comma-separated labels using job images from `docker.io/gitea/runner-images`. |
| `GITEA_RUNNER_CPU_LIMIT` / `GITEA_RUNNER_CPU_RESERVATION` | `1.0` / `0.1` | CPU limit and reservation. |
| `GITEA_RUNNER_MEMORY_LIMIT` / `GITEA_RUNNER_MEMORY_RESERVATION` | `2G` / `1G` | Memory limit and reservation. |
- `INSTANCE_URL`: The URL of the Gitea instance.
- `REGISTRATION_TOKEN`: The registration token for the Gitea Runner.
- `RUNNER_NAME`: The name of the runner.
- `RUNNER_LABELS`: The labels for the runner.
The repository includes a ready-to-use `config.yaml`. To inspect a fresh upstream 2.1.0 configuration instead, run:
## Volumes
```bash
docker run --entrypoint="" --rm gitea/runner:2.1.0 gitea-runner generate-config > config.yaml
```
- `config.yaml`: The configuration file for the Gitea Runner.
- `data`: A volume for storing runner data.
- `/var/run/docker.sock`: For communicating with the Docker daemon.
## Storage and Health
- `gitea_runner_data` stores registration and runner state.
- `./config.yaml` is mounted read-only at `/config.yaml`.
- `/var/run/docker.sock` lets the runner create job containers.
- The healthcheck queries the internal metrics endpoint at `http://127.0.0.1:9101/healthz`.
## Security
Docker socket access is effectively host-level privilege. Do not run untrusted workflows on this runner. For stronger isolation, use a dedicated host or VM, or evaluate a rootless Docker-in-Docker setup.
## Migrating from act_runner
- The image and binary changed from `gitea/act_runner` and `act_runner` to `gitea/runner` and `gitea-runner`.
- Rename `INSTANCE_URL`, `REGISTRATION_TOKEN`, `RUNNER_NAME`, and `RUNNER_LABELS` to the corresponding official `GITEA_*` variables above.
- The default labels now include Ubuntu 24.04 and 22.04 images, and `container.force_pull` now defaults to `false`.
- Runner v2.0 introduced a breaking change for private-image credentials; review and reconfigure those credentials before running private images.
+48 -44
View File
@@ -2,56 +2,60 @@
[English](./README.md) | [中文](./README.zh.md)
服务用于搭建一个 Gitea Runner。
## 前提条件
1. 生成 `config.yaml` 文件:
```bash
docker run --entrypoint="" --rm -it gitea/act_runner:0.2.13 act_runner generate-config > config.yaml
```
2. 配置 `config.yaml`,例如:
```yaml
cache:
enabled: true
dir: ''
host: 192.168.8.17
port: 8088
```
3. 配置环境变量:
```properties
INSTANCE_URL=http://xxx:3000
REGISTRATION_TOKEN=xxxxxx
RUNNER_NAME=runner-1
RUNNER_LABELS=xxxxxx
```
## 启动 Runner
```bash
docker compose up -d
```
配置使用 Gitea Runner 2.1.0 运行 Gitea Actions。Compose 服务名为 `gitea_runner`,它通过宿主机的 Docker 守护进程在 Docker 容器中执行任务
## 服务
- `runner`: Gitea Runner 服务
- `gitea_runner`:注册到 Gitea,并为 Actions 任务创建 Docker 容器
## 前提条件
在 Gitea 的“设置 -> Actions -> Runners”中创建 Runner 注册令牌。此令牌为必填项。
## 快速开始
```bash
cp .env.example .env
# 在 .env 中设置 GITEA_RUNNER_REGISTRATION_TOKEN,并在需要时修改 GITEA_INSTANCE_URL。
docker compose up -d
```
默认地址 `http://host.docker.internal:3000` 指向 Docker 宿主机上发布到 3000 端口的 Gitea。Compose 会为 Runner 将该主机名映射到宿主机网关,`config.yaml` 也会为任务容器添加同一映射。如果 Gitea 位于远程主机、使用其他端口,或无法通过宿主机访问,请修改此地址;所选地址必须同时可被 Runner 和任务容器访问。
## 配置
### 环境变量
| 变量 | 默认值 | 说明 |
| --------------------------------------------------------------- | ------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| `GLOBAL_REGISTRY` | 空 | 可选镜像仓库前缀,必须包含末尾的 `/`。 |
| `GITEA_RUNNER_VERSION` | `2.1.0` | Runner 镜像版本。 |
| `TZ` | `UTC` | 容器时区。 |
| `GITEA_INSTANCE_URL` | `http://host.docker.internal:3000` | Runner 和任务容器均可访问的 Gitea 地址。 |
| `GITEA_RUNNER_REGISTRATION_TOKEN` | 空 | 必填的注册令牌。 |
| `GITEA_RUNNER_NAME` | `Gitea-Runner` | Gitea 中显示的 Runner 名称。 |
| `GITEA_RUNNER_LABELS` | `ubuntu-latest``ubuntu-24.04``ubuntu-22.04` Docker labels | 以逗号分隔的 labels,默认 job image repository 为 `docker.io/gitea/runner-images`。 |
| `GITEA_RUNNER_CPU_LIMIT` / `GITEA_RUNNER_CPU_RESERVATION` | `1.0` / `0.1` | CPU 限制和预留。 |
| `GITEA_RUNNER_MEMORY_LIMIT` / `GITEA_RUNNER_MEMORY_RESERVATION` | `2G` / `1G` | 内存限制和预留。 |
- `INSTANCE_URL`: Gitea 实例的 URL。
- `REGISTRATION_TOKEN`: Gitea Runner 的注册令牌。
- `RUNNER_NAME`: Runner 的名称。
- `RUNNER_LABELS`: Runner 的标签。
仓库已经提供可直接使用的 `config.yaml`,无需在启动前生成。如需查看上游 2.1.0 的新配置,可运行:
## 卷
```bash
docker run --entrypoint="" --rm gitea/runner:2.1.0 gitea-runner generate-config > config.yaml
```
- `config.yaml`: Gitea Runner 的配置文件。
- `data`: 用于存储 Runner 数据的卷。
- `/var/run/docker.sock`: 用于与 Docker守护进程通信
## 存储与健康检查
- `gitea_runner_data` 保存注册信息和 Runner 状态
- `./config.yaml` 以只读方式挂载到 `/config.yaml`
- `/var/run/docker.sock` 让 Runner 能够创建任务容器。
- 健康检查访问内部指标端点 `http://127.0.0.1:9101/healthz`
## 安全
访问 Docker 套接字等同于拥有宿主机级别的高权限。不要在此 Runner 上运行不可信 workflow。如需更强隔离,请使用专用宿主机或 VM,或评估 rootless Docker-in-Docker 方案。
## 从 act_runner 迁移
- 镜像和二进制名称已从 `gitea/act_runner``act_runner` 改为 `gitea/runner``gitea-runner`
-`INSTANCE_URL``REGISTRATION_TOKEN``RUNNER_NAME``RUNNER_LABELS` 改为上表对应的官方 `GITEA_*` 变量。
- 默认 labels 现在包含 Ubuntu 24.04 和 22.04 镜像,`container.force_pull` 的默认值改为 `false`
- Runner v2.0 对私有镜像凭据引入了 breaking change;运行私有镜像前,请检查并重新配置相关凭据。
+78 -75
View File
@@ -1,110 +1,113 @@
# Example configuration file, it's safe to copy this as the default config file without any modification.
# You don't have to copy this file to your instance,
# just run `./act_runner generate-config > config.yaml` to generate a config file.
# Ready-to-use configuration for Gitea Runner 2.1.0.
log:
# The level of logging, can be trace, debug, info, warn, error, fatal
# Logging level: trace, debug, info, warn, error, or fatal.
level: info
runner:
# Where to store the registration result.
# Registration state file.
file: .runner
# Execute how many tasks concurrently at the same time.
# Maximum number of concurrent tasks.
capacity: 1
# Extra environment variables to run jobs.
envs:
A_TEST_ENV_NAME_1: a_test_env_value_1
A_TEST_ENV_NAME_2: a_test_env_value_2
# Extra environment variables to run jobs from a file.
# It will be ignored if it's empty or the file doesn't exist.
# Extra environment variables passed to jobs.
envs: {}
# Optional file containing extra job environment variables.
env_file: .env
# The timeout for a job to be finished.
# Please note that the Gitea instance also has a timeout (3h by default) for the job.
# So the job could be stopped by the Gitea instance if it's timeout is shorter than this.
# Maximum job runtime.
timeout: 3h
# The timeout for the runner to wait for running jobs to finish when shutting down.
# Any running jobs that haven't finished after this timeout will be cancelled.
# Time to wait for running jobs during shutdown; 0s waits indefinitely.
shutdown_timeout: 0s
# Whether skip verifying the TLS certificate of the Gitea instance.
# Skip TLS certificate verification for the Gitea instance.
insecure: false
# The timeout for fetching the job from the Gitea instance.
# Long-poll timeout when fetching jobs.
fetch_timeout: 5s
# The interval for fetching the job from the Gitea instance.
# Initial interval between job fetches.
fetch_interval: 2s
# The github_mirror of a runner is used to specify the mirror address of the github that pulls the action repository.
# It works when something like `uses: actions/checkout@v4` is used and DEFAULT_ACTIONS_URL is set to github,
# and github_mirror is not empty. In this case,
# it replaces https://github.com with the value here, which is useful for some special network environments.
# Maximum interval between job fetches while idle.
fetch_interval_max: 5s
# Remove working directories older than this age.
workdir_cleanup_age: 24h
# Interval for cleaning up idle working directories.
idle_cleanup_interval: 10m
# Interval for reporting job logs.
log_report_interval: 5s
# Maximum latency before pending logs are reported.
log_report_max_latency: 3s
# Maximum number of log lines sent in one batch.
log_report_batch_size: 100
# Interval for reporting job state.
state_report_interval: 5s
# Timeout for closing job reports.
report_close_timeout: 10s
# Optional GitHub mirror used for action repositories.
github_mirror: ''
# The labels of a runner are used to determine which jobs the runner can run, and how to run them.
# Like: "macos-arm64:host" or "ubuntu-latest:docker://docker.gitea.com/runner-images:ubuntu-latest"
# Find more images provided by Gitea at https://gitea.com/docker.gitea.com/runner-images .
# If it's empty when registering, it will ask for inputting labels.
# If it's empty when execute `daemon`, will use labels in `.runner` file.
# Use shallow clones for action repositories.
action_shallow_clone: true
# Set act compatibility environment variables in jobs.
set_act_env: true
# Allocate a pseudo-TTY for jobs.
allocate_pty: false
# Optional shell script run after each task.
post_task_script: ''
# Maximum runtime for the post-task script.
post_task_script_timeout: 5m
# Labels determine which jobs this runner accepts and their execution images.
labels:
- 'ubuntu-latest:docker://docker.gitea.com/runner-images:ubuntu-latest'
- 'ubuntu-22.04:docker://docker.gitea.com/runner-images:ubuntu-22.04'
- 'ubuntu-20.04:docker://docker.gitea.com/runner-images:ubuntu-20.04'
- 'ubuntu-latest:docker://docker.io/gitea/runner-images:ubuntu-latest'
- 'ubuntu-24.04:docker://docker.io/gitea/runner-images:ubuntu-24.04'
- 'ubuntu-22.04:docker://docker.io/gitea/runner-images:ubuntu-22.04'
cache:
# Enable cache server to use actions/cache.
# Enable the actions/cache-compatible cache server.
enabled: true
# The directory to store the cache data.
# If it's empty, the cache data will be stored in $HOME/.cache/actcache.
# Cache directory; empty uses the runner default.
dir: ''
# The host of the cache server.
# It's not for the address to listen, but the address to connect from job containers.
# So 0.0.0.0 is a bad choice, leave it empty to detect automatically.
# Address job containers use to reach the cache server; empty enables detection.
host: ''
# The port of the cache server.
# 0 means to use a random available port.
# Cache server port; 0 selects an available port.
port: 0
# The external cache server URL. Valid only when enable is true.
# If it's specified, act_runner will use this URL as the ACTIONS_CACHE_URL rather than start a server by itself.
# The URL should generally end with "/".
# Optional external cache server URL.
external_server: ''
# Optional secret for the external cache server.
external_secret: ''
# Disable cache network access.
offline_mode: false
container:
# Specifies the network to which the container will connect.
# Could be host, bridge or the name of a custom network.
# If it's empty, act_runner will create a network automatically.
# Existing Docker network to use; empty creates a network per job.
network: ''
# Whether to use privileged mode or not when launching task containers (privileged mode is required for Docker-in-Docker).
# Options applied when the runner creates a job network.
network_create_options:
enable_ipv4: true
enable_ipv6: false
# Run job containers in privileged mode.
privileged: false
# And other options to be used when the container is started (eg, --add-host=my.gitea.url:host-gateway).
options:
# The parent directory of a job's working directory.
# NOTE: There is no need to add the first '/' of the path as act_runner will add it automatically.
# If the path starts with '/', the '/' will be trimmed.
# For example, if the parent directory is /path/to/my/dir, workdir_parent should be path/to/my/dir
# If it's empty, /workspace will be used.
# Make the host-published Gitea URL resolvable from job containers.
options: >-
--add-host=host.docker.internal:host-gateway
# Parent directory for job workspaces; empty uses /workspace.
workdir_parent:
# Volumes (including bind mounts) can be mounted to containers. Glob syntax is supported, see https://github.com/gobwas/glob
# You can specify multiple volumes. If the sequence is empty, no volumes can be mounted.
# For example, if you only allow containers to mount the `data` volume and all the json files in `/src`, you should change the config to:
# valid_volumes:
# - data
# - /src/*.json
# If you want to allow any volume, please use the following configuration:
# valid_volumes:
# - '**'
# Bind the runner workspace directly into job containers.
bind_workdir: false
# Allowed job volume mounts.
valid_volumes: []
# overrides the docker client host with the specified one.
# If it's empty, act_runner will find an available docker host automatically.
# If it's "-", act_runner will find an available docker host automatically, but the docker host won't be mounted to the job containers and service containers.
# If it's not empty or "-", the specified docker host will be used. An error will be returned if it doesn't work.
# Docker daemon endpoint; empty enables automatic detection.
docker_host: ''
# Pull docker image(s) even if already present
force_pull: true
# Rebuild docker image(s) even if already present
# Pull images only when they are not already available.
force_pull: false
# Rebuild job images even when already available.
force_rebuild: false
# Always require a reachable docker daemon, even if not required by act_runner
# Require Docker even for jobs that otherwise do not need it.
require_docker: false
# Timeout to wait for the docker daemon to be reachable, if docker is required by require_docker or act_runner
# Time to wait for Docker; 0s uses the runner default.
docker_timeout: 0s
host:
# The parent directory of a job's working directory.
# If it's empty, $HOME/.cache/act/ will be used.
# Parent directory for host-mode job workspaces; empty uses the runner default.
workdir_parent:
metrics:
# Enabled so the Compose healthcheck can query /healthz.
enabled: true
# Metrics and health endpoint listen address.
addr: '127.0.0.1:9101'
+13 -5
View File
@@ -9,18 +9,26 @@ x-defaults: &defaults
services:
gitea_runner:
<<: *defaults
image: ${GLOBAL_REGISTRY:-}gitea/act_runner:${GITEA_RUNNER_VERSION:-0.2.13}
image: ${GLOBAL_REGISTRY:-}gitea/runner:${GITEA_RUNNER_VERSION:-2.1.0}
environment:
TZ: ${TZ:-UTC}
CONFIG_FILE: /config.yaml
GITEA_INSTANCE_URL: ${INSTANCE_URL:-http://localhost:3000}
GITEA_RUNNER_REGISTRATION_TOKEN: ${REGISTRATION_TOKEN}
GITEA_RUNNER_NAME: ${RUNNER_NAME:-Gitea-Runner}
GITEA_RUNNER_LABELS: ${RUNNER_LABELS:-DockerRunner}
GITEA_INSTANCE_URL: ${GITEA_INSTANCE_URL:-http://host.docker.internal:3000}
GITEA_RUNNER_REGISTRATION_TOKEN: ${GITEA_RUNNER_REGISTRATION_TOKEN}
GITEA_RUNNER_NAME: ${GITEA_RUNNER_NAME:-Gitea-Runner}
GITEA_RUNNER_LABELS: ${GITEA_RUNNER_LABELS:-ubuntu-latest:docker://docker.io/gitea/runner-images:ubuntu-latest,ubuntu-24.04:docker://docker.io/gitea/runner-images:ubuntu-24.04,ubuntu-22.04:docker://docker.io/gitea/runner-images:ubuntu-22.04}
extra_hosts:
- host.docker.internal:host-gateway
volumes:
- ./config.yaml:/config.yaml:ro
- gitea_runner_data:/data
- /var/run/docker.sock:/var/run/docker.sock
healthcheck:
test: [CMD-SHELL, '/bin/busybox wget -q -O /dev/null http://127.0.0.1:9101/healthz || exit 1']
interval: 30s
timeout: 5s
retries: 3
start_period: 30s
deploy:
resources:
limits: