Remove duplicated runner docs (#479)

The `usage/actions/runner` has duplicated runner documentations as `/runner`. This PR remove the duplicated content and leave obtain registry token in `usage/actions/runner` and runner install/configurations in `/runner`.

Reviewed-on: https://gitea.com/gitea/docs/pulls/479
Reviewed-by: silverwind <[email protected]>
This commit is contained in:
Lunny Xiao
2026-08-02 21:53:31 +00:00
parent 8bcba04001
commit a1ef3a26ef
8 changed files with 44 additions and 1772 deletions
+6 -412
View File
@@ -6,39 +6,13 @@ sidebar_position: 20
# Gitea Runner
This page will introduce the [Gitea Runner](https://gitea.com/gitea/runner) in detail, which is the runner for Gitea Actions.
This page will introduce the [Gitea Runner](https://gitea.com/gitea/runner), which is the runner for Gitea Actions.
## Requirements
:::tip
For detailed installation, configuration, and usage instructions, see the [Gitea Runner documentation](/runner/).
:::
Currently the runner supports three modes in which it can be run.
1. Host: runner will run as an application on the host. This provides no encapsulation.
2. Docker (recommended): Runs jobs in a [Docker](https://docker.com) container. If you choose this mode, you need to [install Docker](https://docs.docker.com/engine/install/) first and make sure that the Docker daemon is running.
3. Docker-in-Docker (DinD): Puts the runner into rootless mode. It then runs in a Docker container with its own Docker daemon that has fewer privileges. It will spawn job containers from there. Best security but more complex setup.
Other OCI container engines which are compatible with Docker's API should also work, but are untested.
However, if you are sure that you want to run jobs directly on the host only, then Docker is not required.
There are multiple ways to install the runner.
## Installation with binary
### Download the binary
You can download the binary from the [release page](https://gitea.com/gitea/runner/releases).
However, if you want to use the latest nightly build, you can download it from the [download page](https://dl.gitea.com/gitea-runner/).
When you download the binary, please make sure that you have downloaded the correct one for your platform.
You can check it by running the following command if you are in a Unix-style OS.
```bash
chmod +x runner
./runner --version
```
If you see the version information, it means that you have downloaded the correct binary.
### Obtain a registration token
## Obtain a registration token
You can register a runner at different levels. It can be:
@@ -48,7 +22,6 @@ You can register a runner at different levels. It can be:
Note that the repository may still use instance-level or organization-level runners even if it has its own repository-level runners. A future release may provide an option to allow more control over this.
Before registering the runner and running it, you need a registration token. The level of the runner determines where to obtain the registration token.
- Instance level: The admin settings page, like `<your_gitea.com>/-/admin/actions/runners`.
@@ -77,383 +50,4 @@ The token from the environment is valid until you reset the token (re-create a n
Tokens are valid for registering multiple runners, until they are revoked and replaced by a new token using the token reset link in the web interface.
### Configuration
Configuration is done via a configuration file. It is optional, and the default configuration will be used when no configuration file is specified. You can generate a configuration file by running the following command:
```bash
./runner generate-config
```
The default configuration is safe to use without any modification, so you can just use it directly.
```bash
./runner generate-config > config.yaml
./runner --config config.yaml [command]
```
### Register the runner
Registration is required before running Gitea Runner, because the runner needs to know where to get jobs from. It is also important for the Gitea instance to identify the runner.
If this has been installed using the binary package, the runner can be registered by running the following command.
```bash
./runner register
```
Alternatively, you can use the `--config` option to specify the configuration file mentioned in the previous section.
```bash
./runner --config config.yaml register
```
You will be asked to input the registration information step by step. This includes:
- The Gitea instance URL, like `https://gitea.com/` or `http://192.168.8.8:3000/`.
- The registration token.
- The runner name, which is optional. If you leave it blank, the hostname will be used.
- The runner labels, which is optional. If you leave it blank, the default labels will be used.
You may be confused about the runner labels, which will be explained later.
If you want to register the runner in a non-interactive way, you can use arguments to do it.
```bash
./runner register --no-interactive --instance <instance_url> --token <registration_token> --name <runner_name> --labels <runner_labels>
```
When you have registered the runner, you can find a new file named `.runner` in the current directory.
This file stores the registration information.
Please do not edit it manually.
If this file is missing or corrupted, you can simply remove it and register again.
If you want to store the registration information in another place, you can specify it in the configuration file,
and don't forget to specify the `--config` option.
#### Ephemeral Runners
Ephemeral runners provide a security hardening mechanism for enabling organization- or instance-wide runners without requiring full user trust. Once a job is assigned within a spot VM or container, the runner's exposed credentials are automatically revoked—blocking it from polling further jobs before any untrusted code runs, while still allowing it to report progress until completion by either Gitea or the runner.
Gitea Runner **0.2.12+** is required.
The updated commands for registering the runner as ephemeral are listed below. Refer to the previous section for detailed information on registering the runner.
```bash
./runner register --ephemeral
```
```bash
./runner --config config.yaml register --ephemeral
```
```bash
./runner register --no-interactive --ephemeral --instance <instance_url> --token <registration_token> --name <runner_name> --labels <runner_labels>
```
The runner must be registered each time it is intended to receive a job. After completing the single job it is designed to execute, the runner terminates.
To automate the registration and startup of new runners when a job is queued, use the `workflow_job` webhook.
### Start the runner from the command line
After you have registered the runner, you can run it with the following command:
```shell
./runner daemon
```
or
```bash
./runner daemon --config config.yaml
```
The runner will fetch jobs from the Gitea instance and run them automatically.
### Start the runner with Systemd
It is also possible to run Gitea Runner as a [systemd](https://en.wikipedia.org/wiki/Systemd) service. Create an unprivileged `runner` user on your system, and create the following file in `/etc/systemd/system/runner.service`. The paths in `ExecStart` and `WorkingDirectory` may need to be adjusted depending on where you installed the `runner` binary, its configuration file, and the home directory of the `runner` user.
```ini
[Unit]
Description=Gitea Actions runner
Documentation=https://gitea.com/gitea/runner
After=docker.service
[Service]
ExecStart=/usr/local/bin/runner daemon --config /etc/runner/config.yaml
ExecReload=/bin/kill -s HUP $MAINPID
WorkingDirectory=/var/lib/runner
TimeoutSec=0
RestartSec=10
Restart=always
User=runner
[Install]
WantedBy=multi-user.target
```
Then:
```bash
# load the new systemd unit file
sudo systemctl daemon-reload
# start the service and enable it at boot
sudo systemctl enable runner --now
```
If using Docker, the `runner` user should also be added to the `docker` group before starting the service. Keep in mind that this effectively gives `runner` root access to the system [[1]](https://docs.docker.com/engine/security/#docker-daemon-attack-surface).
### Start the runner with LaunchDaemon (macOS)
Mac uses `launchd` in place of systemd for registering daemon processes. By default, daemons run as the root user, so if desired an unprivileged `_runner` user can be created via the `dscl` tool. The following file should then be created in the directory `/Library/LaunchDaemon/com.gitea.runner.plist`. The paths for `WorkingDirectory`, `ProgramArguments`, `StandardOutPath`, `StandardErrPath`, and the `HOME` environment variable may need to be updated to reflect your installation. Also note that any executables outside of the example `PATH` shown will need to be explicitly included and will not be inherited from existing configurations.
```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.gitea.runner</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/runner</string>
<string>daemon</string>
<string>--config</string>
<string>/etc/runner/config.yaml</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>WorkingDirectory</key>
<string>/var/lib/runner</string>
<key>StandardOutPath</key>
<string>/var/lib/runner/runner.log</string>
<key>StandardErrorPath</key>
<string>/var/lib/runner/runner.err</string>
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
<key>HOME</key>
<string>/var/lib/runner</string>
</dict>
<key>UserName</key>
<string>_runner</string>
</dict>
</plist>
```
Then:
```bash
sudo launchctl load /Library/LaunchDaemon/com.gitea.runner.plist
```
You can also set up a Linux or Windows service to let the runner run automatically.
## Install with the docker image
### Pull the image
You can use the docker image from [Docker Hub](https://hub.docker.com/r/gitea/runner/tags).
Just like the binary, you can use the latest nightly build by using the `nightly` tag, while the `latest` tag is the latest stable release.
```bash
docker pull docker.io/gitea/runner:latest # for the latest stable release
```
If you want to use the newest or experimental features, you can also use the nightly image.
```bash
docker pull docker.io/gitea/runner:nightly # for the latest nightly build
```
### Configuration
Configuration is optional, but you can also generate a config file with docker:
```bash
docker run --entrypoint="" --rm -it docker.io/gitea/runner:latest runner generate-config > config.yaml
```
When you are using the docker image, you can specify the configuration file by using the `CONFIG_FILE` environment variable. Make sure that the file is mounted into the container as a volume:
```bash
docker run -v $PWD/config.yaml:/config.yaml -e CONFIG_FILE=/config.yaml ...
```
You may notice the commands above are incomplete because it is not time to run the runner yet.
Before running the runner, we need to register it to your Gitea instance first.
### Start the runner with docker
If you are using the docker image, behavior will be slightly different. Registration and running are combined into one step in this case, so you need to specify the registration information when running the runner.
A quick start with docker run along with a minimal parameter set is shown below. You need to get the `<registration_token>` from the above step, and set a unique name for `<gitea_runner_name>` and for `<container_name>`.
```bash
docker run \
-e GITEA_INSTANCE_URL=<instance_url> \
-e GITEA_RUNNER_REGISTRATION_TOKEN=<registration_token> \
-e GITEA_RUNNER_NAME=<gitea_runner_name> \
--name <container_name> \
-v /var/run/docker.sock:/var/run/docker.sock \
-d docker.io/gitea/runner:latest
```
You can add more parameters to use a custom config, add a `data` directory for non-volatile file storage, etc.
```bash
docker run \
-v $PWD/config.yaml:/config.yaml \
-v $PWD/data:/data \
-v /var/run/docker.sock:/var/run/docker.sock \
-e CONFIG_FILE=/config.yaml \
-e GITEA_INSTANCE_URL=<instance_url> \
-e GITEA_RUNNER_REGISTRATION_TOKEN=<registration_token> \
-e GITEA_RUNNER_NAME=<gitea_runner_name> \
-e GITEA_RUNNER_LABELS=<runner_labels> \
--name <container_name> \
-d docker.io/gitea/runner:latest
```
You may notice that we have mounted `/var/run/docker.sock` into the container.
This is because with this setup, the runner will execute jobs in temporary Docker containers, so it needs to communicate with the Docker daemon.
As mentioned, you can remove it if you want to run jobs on the host directly.
To be clear, the "host" actually means the container that is running the runner now, instead of the host machine.
---
To enable ephemeral runners, set the environment variable `GITEA_RUNNER_EPHEMERAL=1` in the runner image. This setup doesn't use a `/data` volume because the credentials are single-use and not intended to be reused. You can find more details about this mode under [Ephemeral runners](#ephemeral-runners).
```bash
docker run \
-e GITEA_INSTANCE_URL=<instance_url> \
-e GITEA_RUNNER_REGISTRATION_TOKEN=<registration_token> \
-e GITEA_RUNNER_EPHEMERAL=1 \
-e GITEA_RUNNER_NAME=<runner_name> \
--name my_runner \
-d docker.io/gitea/runner:nightly
```
```bash
docker run \
-v $PWD/config.yaml:/config.yaml \
-v /var/run/docker.sock:/var/run/docker.sock \
-e CONFIG_FILE=/config.yaml \
-e GITEA_INSTANCE_URL=<instance_url> \
-e GITEA_RUNNER_REGISTRATION_TOKEN=<registration_token> \
-e GITEA_RUNNER_EPHEMERAL=1 \
-e GITEA_RUNNER_NAME=<runner_name> \
-e GITEA_RUNNER_LABELS=<runner_labels> \
--name my_runner \
-d docker.io/gitea/runner:nightly
```
Mounting the host's Docker socket using `/var/run/docker.sock:/var/run/docker.sock` introduces a potential security vulnerability. If a job can access this socket, the reusable `GITEA_RUNNER_REGISTRATION_TOKEN` could be exposed through Docker inspect data.
### Start the runner using docker compose
You could also set up the runner using the following `docker-compose.yml`:
```yml
version: "3.8"
services:
runner:
image: docker.io/gitea/runner:nightly
environment:
CONFIG_FILE: /config.yaml
GITEA_INSTANCE_URL: "${INSTANCE_URL}"
GITEA_RUNNER_REGISTRATION_TOKEN: "${REGISTRATION_TOKEN}"
GITEA_RUNNER_NAME: "${RUNNER_NAME}"
GITEA_RUNNER_LABELS: "${RUNNER_LABELS}"
volumes:
- ./config.yaml:/config.yaml
- ./data:/data
- /var/run/docker.sock:/var/run/docker.sock
```
When using docker, there is no requirement to enter the container and manually run `./runner daemon` command as shown below. Once the container has been started successfully, it will show up as an active runner in your Gitea instance.
---
To enable ephemeral runners, set the environment variable `GITEA_RUNNER_EPHEMERAL=1` in the runner image. This setup doesn't use a `/data` volume because the credentials are single-use and not intended to be reused. You can find more details about this mode under [Ephemeral runners](#ephemeral-runners).
```yml
version: "3.8"
services:
runner:
image: docker.io/gitea/runner:nightly
environment:
CONFIG_FILE: /config.yaml
GITEA_INSTANCE_URL: "${INSTANCE_URL}"
GITEA_RUNNER_REGISTRATION_TOKEN: "${REGISTRATION_TOKEN}"
GITEA_RUNNER_NAME: "${RUNNER_NAME}"
GITEA_RUNNER_LABELS: "${RUNNER_LABELS}"
GITEA_RUNNER_EPHEMERAL: "1"
volumes:
- ./config.yaml:/config.yaml
- /var/run/docker.sock:/var/run/docker.sock
```
Mounting the host's Docker socket using `/var/run/docker.sock:/var/run/docker.sock` introduces a potential security vulnerability. If a job can access this socket, the reusable `GITEA_RUNNER_REGISTRATION_TOKEN` could be exposed through Docker inspect data.
### More start examples
A couple more usage examples can be found in the [runner](https://gitea.com/gitea/runner/src/branch/main/examples) repository.
## Advanced Configurations
### Configuring cache when starting a runner using the docker image
If you do not intend to use `actions/cache` in your workflow, you can ignore this section.
If you use `actions/cache` without any additional configuration, it will return the following error:
> Failed to restore: getCacheEntry failed: connect ETIMEDOUT IP:PORT
The error occurs because the runner container and job container are on different networks, so the job container cannot access the runner container.
Therefore, it is essential to configure the cache action to ensure its proper functioning. Follow these steps:
- 1. Obtain the LAN IP address of the host machine where the runner container is running.
- 2. Find an available port number on the host machine where the runner container is running.
- 3. Configure the following settings in the configuration file:
```yaml
cache:
enabled: true
dir: ""
# Use the LAN IP obtained in step 1
host: "192.168.8.17"
# Use the port number obtained in step 2
port: 8088
```
- 4. When starting the container, map the cache port to the host machine:
```bash
docker run \
--name gitea-docker-runner \
-p 8088:8088 \
-d docker.io/gitea/runner:nightly
```
### Labels
The labels of a runner are used to determine which jobs the runner can run, and how to run them.
The default labels are `ubuntu-latest:docker://node:16-bullseye,ubuntu-22.04:docker://node:16-bullseye,ubuntu-20.04:docker://node:16-bullseye,ubuntu-18.04:docker://node:16-buster`.
It is a comma-separated list, and each item is a label.
Let's take `ubuntu-22.04:docker://node:16-bullseye` as an example.
It means that the runner can run jobs with `runs-on: ubuntu-22.04`, and the job will be run in a docker container with the image `node:16-bullseye`.
If the default image is insufficient for your needs, and you have enough disk space to use a better and bigger one, you can change it to `ubuntu-22.04:docker://<the image you like>`.
You can find more useful images on [act images](https://github.com/nektos/act/blob/master/IMAGES.md).
If you want to run jobs on the host directly, you can change it to `ubuntu-22.04:host` or just `ubuntu-22.04`; `:host` is optional.
However, we suggest you use a special name like `linux_amd64:host` or `windows:host` to avoid misusing it.
Starting with Gitea 1.21, you can change labels by modifying `runners.labels` in the runner configuration file (if you don't have a configuration file, please refer to [configuration tutorials](#configuration)).
The runner will use these new labels as soon as you restart it, i.e., by calling `./runner daemon --config config.yaml`.
Once you have a registration token, follow the [Gitea Runner documentation](/runner/) to install, configure, and run your runner.
@@ -8,81 +8,13 @@ aliases:
# Runner
本页面将详细介绍[Gitea Runner](https://gitea.com/gitea/runner),这是Gitea Actions的Runner。
本页面将介绍[Gitea Runner](https://gitea.com/gitea/runner),这是Gitea Actions的Runner。
## 要求
:::tip
详细的安装、配置和使用说明,请参阅 [Gitea Runner 文档](/runner/)。
:::
建议在Docker容器中运行Job,因此您需要首先安装Docker。
并确保Docker守护进程正在运行。
其他与Docker API兼容的OCI容器引擎也应该可以正常工作,但尚未经过测试。
但是,如果您确定要直接在主机上运行Job,则不需要Docker。
## 安装
有多种安装 Runner 的方法。
### 下载二进制文件
您可以从[发布页面](https://gitea.com/gitea/runner/releases)下载二进制文件。
然而,如果您想使用最新的夜间构建版本,可以从[下载页面](https://dl.gitea.com/gitea-runner/)下载。
下载二进制文件时,请确保您已经下载了适用于您的平台的正确版本。
您可以通过运行以下命令进行检查:
```bash
chmod +x runner
./runner --version
```
如果看到版本信息,则表示您已经下载了正确的二进制文件。
### 使用 Docker 镜像
您可以使用[docker hub](https://hub.docker.com/r/gitea/runner/tags)上的Docker镜像。
与二进制文件类似,您可以使用`nightly`标签使用最新的夜间构建版本,而`latest`标签是最新的稳定版本。
```bash
docker pull docker.io/gitea/runner:latest # for the latest stable release
docker pull docker.io/gitea/runner:nightly # for the latest nightly build
```
## 配置
配置通过配置文件进行。它是可选的,当没有指定配置文件时,将使用默认配置。
您可以通过运行以下命令生成配置文件:
```bash
./runner generate-config
```
默认配置是安全的,可以直接使用。
```bash
./runner generate-config > config.yaml
./runner --config config.yaml [command]
```
您亦可以如下使用 docker 创建配置文件:
```bash
docker run --entrypoint="" --rm -it docker.io/gitea/runner:latest runner generate-config > config.yaml
```
当使用Docker镜像时,可以使用`CONFIG_FILE`环境变量指定配置文件。确保将文件作为卷挂载到容器中:
```bash
docker run -v $(pwd)/config.yaml:/config.yaml -e CONFIG_FILE=/config.yaml ...
```
您可能注意到上面的命令都是不完整的,因为现在还不是运行 Runner 的时候。
在运行 Runner 之前,我们需要首先将其注册到您的Gitea实例中。
## 注册
在运行 Runner 之前,需要进行注册,因为Runner需要知道从哪里获取Job,并且对于Gitea实例来说,识别Runner也很重要。
## 获取注册令牌
### Runner级别
@@ -94,8 +26,6 @@ docker run -v $(pwd)/config.yaml:/config.yaml -e CONFIG_FILE=/config.yaml ...
请注意,即使存储库具有自己的存储库级别Runner,它仍然可以使用实例级别或组织级别Runner。未来的版本可能提供更多对此进行更好控制的选项。
### 获取注册令牌
Runner级别决定了从哪里获取注册令牌。
- 实例级别:管理员设置页面,例如 `<your_gitea.com>/admin/actions/runners`
@@ -124,153 +54,4 @@ export GITEA_RUNNER_REGISTRATION_TOKEN_FILE=/some-dir/runner-token
令牌可用于注册多个 Runner,直到使用 Web 界面中的令牌重置链接将其撤销并替换为新令牌。
### 注册Runner
可以通过运行以下命令来注册 Runner:
```bash
./runner register
```
或者,您可以使用 `--config` 选项来指定前面部分提到的配置文件。
```bash
./runner --config config.yaml register
```
您将逐步输入注册信息,包括:
- Gitea 实例的 URL,例如 `https://gitea.com/``http://192.168.8.8:3000/`
- 注册令牌。
- Runner名称(可选)。如果留空,将使用主机名。
- Runner标签(可选)。如果留空,将使用默认标签。
您可能对Runner标签感到困惑,稍后将对其进行解释。
如果您想以非交互方式注册Runner,可以使用参数执行以下操作。
```bash
./runner register --no-interactive --instance <instance_url> --token <registration_token> --name <runner_name> --labels <runner_labels>
```
注册Runner后,您可以在当前目录中找到一个名为 `.runner` 的新文件。该文件存储注册信息。
请不要手动编辑该文件。
如果此文件丢失或损坏,可以直接删除它并重新注册。
如果您想将注册信息存储在其他位置,请在配置文件中指定,并不要忘记指定 `--config` 选项。
### 使用Docker注册Runner
如果您使用的是Docker镜像,注册行为会略有不同。在这种情况下,注册和运行合并为一步,因此您需要在运行 Runner 时指定注册信息。
```bash
docker run \
-v $(pwd)/config.yaml:/config.yaml \
-v $(pwd)/data:/data \
-v /var/run/docker.sock:/var/run/docker.sock \
-e CONFIG_FILE=/config.yaml \
-e GITEA_INSTANCE_URL=<instance_url> \
-e GITEA_RUNNER_REGISTRATION_TOKEN=<registration_token> \
-e GITEA_RUNNER_NAME=<runner_name> \
-e GITEA_RUNNER_LABELS=<runner_labels> \
--name my_runner \
-d gitea/runner:nightly
```
您可能注意到我们已将`/var/run/docker.sock`挂载到容器中。
这是因为 Runner 将在Docker容器中运行Job,因此它需要与Docker守护进程进行通信。
如前所述,如果要在主机上直接运行Job,可以将其移除。
需要明确的是,这里的 "主机" 实际上指的是当前运行 Runner 的容器,而不是主机机器本身。
### 使用 Docker compose 运行 Runner
您亦可使用如下的 `docker-compose.yml`:
```yml
version: "3.8"
services:
runner:
image: gitea/runner:nightly
environment:
CONFIG_FILE: /config.yaml
GITEA_INSTANCE_URL: "${INSTANCE_URL}"
GITEA_RUNNER_REGISTRATION_TOKEN: "${REGISTRATION_TOKEN}"
GITEA_RUNNER_NAME: "${RUNNER_NAME}"
GITEA_RUNNER_LABELS: "${RUNNER_LABELS}"
volumes:
- ./config.yaml:/config.yaml
- ./data:/data
- /var/run/docker.sock:/var/run/docker.sock
```
### 当您使用 Docker 镜像启动 Runner,如何配置 Cache
如果你不打算在工作流中使用 `actions/cache`,你可以忽略本段。
如果您在使用 `actions/cache` 时没有进行额外的配置,将会返回以下错误信息:
> Failed to restore: getCacheEntry failed: connect ETIMEDOUT IP:PORT
这个错误的原因是 runner 容器和作业容器位于不同的网络中,因此作业容器无法访问 runner 容器。
因此,配置 cache 动作以确保其正常运行是非常重要的。请按照以下步骤操作:
- 1.获取 Runner 容器所在主机的 LAN(本地局域网) IP 地址。
- 2.获取一个 Runner 容器所在主机的空闲端口号。
- 3.在配置文件中如下配置:
```yaml
cache:
enabled: true
dir: ""
# 使用步骤 1. 获取的 LAN IP
host: "192.168.8.17"
# 使用步骤 2. 获取的端口号
port: 8088
```
- 4.启动容器时, 将 Cache 端口映射至主机。
```bash
docker run \
--name gitea-docker-runner \
-p 8088:8088 \
-d gitea/runner:nightly
```
### 标签
```mermaid
flowchart TD
A[Workflow: runs-on: ubuntu-22.04] --> B[Runner 收到 Job 请求]
B --> C[匹配标签: ubuntu-22.04:docker://node:16-bullseye]
C --> D[启动 Docker 容器: node:16-bullseye]
D --> E[在容器中运行 Job 步骤]
E --> F[返回执行结果给 Gitea]
```
Runner的标签用于确定Runner可以运行哪些Job以及如何运行它们。
默认标签为`ubuntu-latest:docker://node:16-bullseye,ubuntu-22.04:docker://node:16-bullseye,ubuntu-20.04:docker://node:16-bullseye,ubuntu-18.04:docker://node:16-buster`
它们是逗号分隔的列表,每个项目都是一个标签。
让我们以 `ubuntu-22.04:docker://node:16-bullseye` 为例。
它意味着Runner可以运行带有`runs-on: ubuntu-22.04`的Job,并且该Job将在使用`node:16-bullseye`镜像的Docker容器中运行。
如果默认镜像无法满足您的需求,并且您有足够的磁盘空间可以使用更好、更大的镜像,您可以将其更改为`ubuntu-22.04:docker://<您喜欢的镜像>`
您可以在[act 镜像](https://github.com/nektos/act/blob/master/IMAGES.md)上找到更多有用的镜像。
如果您想直接在主机上运行Job,您可以将其更改为`ubuntu-22.04:host`或仅`ubuntu-22.04``:host`是可选的。
然而,我们建议您使用类似`linux_amd64:host``windows:host`的特殊名称,以避免误用。
从 Gitea 1.21 开始,您可以通过修改 runner 的配置文件中的 `container.labels` 来更改标签(如果没有配置文件,请参考 [配置教程](#配置)),通过执行 `./runner daemon --config config.yaml` 命令重启 runner 之后,这些新定义的标签就会生效。
## 运行
注册完Runner后,您可以通过运行以下命令来运行它:
```bash
./runner daemon
# or
./runner daemon --config config.yaml
```
Runner将从Gitea实例获取Job并自动运行它们。
获取注册令牌后,请参阅 [Gitea Runner 文档](/runner/) 了解如何安装、配置和运行您的 Runner。
@@ -8,81 +8,13 @@ aliases:
# Runner
本页面将详细介绍[Gitea Runner](https://gitea.com/gitea/runner),这是Gitea Actions的Runner。
本页面将介绍[Gitea Runner](https://gitea.com/gitea/runner),这是Gitea Actions的Runner。
## 要求
:::tip
详细的安装、配置和使用说明,请参阅 [Gitea Runner 文档](/runner/)。
:::
建议在Docker容器中运行Job,因此您需要首先安装Docker。
并确保Docker守护进程正在运行。
其他与Docker API兼容的OCI容器引擎也应该可以正常工作,但尚未经过测试。
但是,如果您确定要直接在主机上运行Job,则不需要Docker。
## 安装
有多种安装 Runner 的方法。
### 下载二进制文件
您可以从[发布页面](https://gitea.com/gitea/runner/releases)下载二进制文件。
然而,如果您想使用最新的夜间构建版本,可以从[下载页面](https://dl.gitea.com/gitea-runner/)下载。
下载二进制文件时,请确保您已经下载了适用于您的平台的正确版本。
您可以通过运行以下命令进行检查:
```bash
chmod +x runner
./runner --version
```
如果看到版本信息,则表示您已经下载了正确的二进制文件。
### 使用 Docker 镜像
您可以使用[docker hub](https://hub.docker.com/r/gitea/runner/tags)上的Docker镜像。
与二进制文件类似,您可以使用`nightly`标签使用最新的夜间构建版本,而`latest`标签是最新的稳定版本。
```bash
docker pull docker.io/gitea/runner:latest # for the latest stable release
docker pull docker.io/gitea/runner:nightly # for the latest nightly build
```
## 配置
配置通过配置文件进行。它是可选的,当没有指定配置文件时,将使用默认配置。
您可以通过运行以下命令生成配置文件:
```bash
./runner generate-config
```
默认配置是安全的,可以直接使用。
```bash
./runner generate-config > config.yaml
./runner --config config.yaml [command]
```
您亦可以如下使用 docker 创建配置文件:
```bash
docker run --entrypoint="" --rm -it docker.io/gitea/runner:latest runner generate-config > config.yaml
```
当使用Docker镜像时,可以使用`CONFIG_FILE`环境变量指定配置文件。确保将文件作为卷挂载到容器中:
```bash
docker run -v $(pwd)/config.yaml:/config.yaml -e CONFIG_FILE=/config.yaml ...
```
您可能注意到上面的命令都是不完整的,因为现在还不是运行 Runner 的时候。
在运行 Runner 之前,我们需要首先将其注册到您的Gitea实例中。
## 注册
在运行 Runner 之前,需要进行注册,因为Runner需要知道从哪里获取Job,并且对于Gitea实例来说,识别Runner也很重要。
## 获取注册令牌
### Runner级别
@@ -94,8 +26,6 @@ docker run -v $(pwd)/config.yaml:/config.yaml -e CONFIG_FILE=/config.yaml ...
请注意,即使存储库具有自己的存储库级别Runner,它仍然可以使用实例级别或组织级别Runner。未来的版本可能提供更多对此进行更好控制的选项。
### 获取注册令牌
Runner级别决定了从哪里获取注册令牌。
- 实例级别:管理员设置页面,例如 `<your_gitea.com>/admin/actions/runners`
@@ -124,153 +54,4 @@ export GITEA_RUNNER_REGISTRATION_TOKEN_FILE=/some-dir/runner-token
令牌可用于注册多个 Runner,直到使用 Web 界面中的令牌重置链接将其撤销并替换为新令牌。
### 注册Runner
可以通过运行以下命令来注册 Runner:
```bash
./runner register
```
或者,您可以使用 `--config` 选项来指定前面部分提到的配置文件。
```bash
./runner --config config.yaml register
```
您将逐步输入注册信息,包括:
- Gitea 实例的 URL,例如 `https://gitea.com/``http://192.168.8.8:3000/`
- 注册令牌。
- Runner名称(可选)。如果留空,将使用主机名。
- Runner标签(可选)。如果留空,将使用默认标签。
您可能对Runner标签感到困惑,稍后将对其进行解释。
如果您想以非交互方式注册Runner,可以使用参数执行以下操作。
```bash
./runner register --no-interactive --instance <instance_url> --token <registration_token> --name <runner_name> --labels <runner_labels>
```
注册Runner后,您可以在当前目录中找到一个名为 `.runner` 的新文件。该文件存储注册信息。
请不要手动编辑该文件。
如果此文件丢失或损坏,可以直接删除它并重新注册。
如果您想将注册信息存储在其他位置,请在配置文件中指定,并不要忘记指定 `--config` 选项。
### 使用Docker注册Runner
如果您使用的是Docker镜像,注册行为会略有不同。在这种情况下,注册和运行合并为一步,因此您需要在运行 Runner 时指定注册信息。
```bash
docker run \
-v $(pwd)/config.yaml:/config.yaml \
-v $(pwd)/data:/data \
-v /var/run/docker.sock:/var/run/docker.sock \
-e CONFIG_FILE=/config.yaml \
-e GITEA_INSTANCE_URL=<instance_url> \
-e GITEA_RUNNER_REGISTRATION_TOKEN=<registration_token> \
-e GITEA_RUNNER_NAME=<runner_name> \
-e GITEA_RUNNER_LABELS=<runner_labels> \
--name my_runner \
-d gitea/runner:nightly
```
您可能注意到我们已将`/var/run/docker.sock`挂载到容器中。
这是因为 Runner 将在Docker容器中运行Job,因此它需要与Docker守护进程进行通信。
如前所述,如果要在主机上直接运行Job,可以将其移除。
需要明确的是,这里的 "主机" 实际上指的是当前运行 Runner 的容器,而不是主机机器本身。
### 使用 Docker compose 运行 Runner
您亦可使用如下的 `docker-compose.yml`:
```yml
version: "3.8"
services:
runner:
image: gitea/runner:nightly
environment:
CONFIG_FILE: /config.yaml
GITEA_INSTANCE_URL: "${INSTANCE_URL}"
GITEA_RUNNER_REGISTRATION_TOKEN: "${REGISTRATION_TOKEN}"
GITEA_RUNNER_NAME: "${RUNNER_NAME}"
GITEA_RUNNER_LABELS: "${RUNNER_LABELS}"
volumes:
- ./config.yaml:/config.yaml
- ./data:/data
- /var/run/docker.sock:/var/run/docker.sock
```
### 当您使用 Docker 镜像启动 Runner,如何配置 Cache
如果你不打算在工作流中使用 `actions/cache`,你可以忽略本段。
如果您在使用 `actions/cache` 时没有进行额外的配置,将会返回以下错误信息:
> Failed to restore: getCacheEntry failed: connect ETIMEDOUT IP:PORT
这个错误的原因是 runner 容器和作业容器位于不同的网络中,因此作业容器无法访问 runner 容器。
因此,配置 cache 动作以确保其正常运行是非常重要的。请按照以下步骤操作:
- 1.获取 Runner 容器所在主机的 LAN(本地局域网) IP 地址。
- 2.获取一个 Runner 容器所在主机的空闲端口号。
- 3.在配置文件中如下配置:
```yaml
cache:
enabled: true
dir: ""
# 使用步骤 1. 获取的 LAN IP
host: "192.168.8.17"
# 使用步骤 2. 获取的端口号
port: 8088
```
- 4.启动容器时, 将 Cache 端口映射至主机。
```bash
docker run \
--name gitea-docker-runner \
-p 8088:8088 \
-d gitea/runner:nightly
```
### 标签
```mermaid
flowchart TD
A[Workflow: runs-on: ubuntu-22.04] --> B[Runner 收到 Job 请求]
B --> C[匹配标签: ubuntu-22.04:docker://node:16-bullseye]
C --> D[启动 Docker 容器: node:16-bullseye]
D --> E[在容器中运行 Job 步骤]
E --> F[返回执行结果给 Gitea]
```
Runner的标签用于确定Runner可以运行哪些Job以及如何运行它们。
默认标签为`ubuntu-latest:docker://node:16-bullseye,ubuntu-22.04:docker://node:16-bullseye,ubuntu-20.04:docker://node:16-bullseye,ubuntu-18.04:docker://node:16-buster`
它们是逗号分隔的列表,每个项目都是一个标签。
让我们以 `ubuntu-22.04:docker://node:16-bullseye` 为例。
它意味着Runner可以运行带有`runs-on: ubuntu-22.04`的Job,并且该Job将在使用`node:16-bullseye`镜像的Docker容器中运行。
如果默认镜像无法满足您的需求,并且您有足够的磁盘空间可以使用更好、更大的镜像,您可以将其更改为`ubuntu-22.04:docker://<您喜欢的镜像>`
您可以在[act 镜像](https://github.com/nektos/act/blob/master/IMAGES.md)上找到更多有用的镜像。
如果您想直接在主机上运行Job,您可以将其更改为`ubuntu-22.04:host`或仅`ubuntu-22.04``:host`是可选的。
然而,我们建议您使用类似`linux_amd64:host``windows:host`的特殊名称,以避免误用。
从 Gitea 1.21 开始,您可以通过修改 runner 的配置文件中的 `container.labels` 来更改标签(如果没有配置文件,请参考 [配置教程](#配置)),通过执行 `./runner daemon --config config.yaml` 命令重启 runner 之后,这些新定义的标签就会生效。
## 运行
注册完Runner后,您可以通过运行以下命令来运行它:
```bash
./runner daemon
# or
./runner daemon --config config.yaml
```
Runner将从Gitea实例获取Job并自动运行它们。
获取注册令牌后,请参阅 [Gitea Runner 文档](/runner/) 了解如何安装、配置和运行您的 Runner。
@@ -8,81 +8,13 @@ aliases:
# Gitea Runner
本頁面將詳細介紹[Gitea Runner](https://gitea.com/gitea/runner),這是Gitea Actions的Runner。
本頁面將介紹[Gitea Runner](https://gitea.com/gitea/runner),這是Gitea Actions的Runner。
## 要求
:::tip
詳細的安裝、設定和使用說明,請參閱 [Gitea Runner 文件](/runner/)。
:::
建議在Docker容器中運行Job,因此您需要首先安裝Docker。
並確保Docker守護進程正在運行。
其他與Docker API相容的OCI容器引擎也應該可以正常工作,但尚未經過測試。
但是,如果您確定要直接在主機上運行Job,則不需要Docker。
## 安裝
有多種安裝Gitea Runner的方法。
### 下載二進制文件
您可以從[發佈頁面](https://gitea.com/gitea/runner/releases)下載二進制文件。
然而,如果您想使用最新的夜間構建版本,可以從[下載頁面](https://dl.gitea.com/gitea-runner/)下載。
下載二進制文件時,請確保您已經下載了適用於您的平台的正確版本。
您可以透過運行以下命令進行檢查:
```bash
chmod +x runner
./runner --version
```
如果看到版本資訊,則表示您已經下載了正確的二進制文件。
### 使用 Docker 鏡像
您可以使用[docker hub](https://hub.docker.com/r/gitea/runner/tags)上的Docker鏡像。
與二進制文件類似,您可以使用`nightly`標籤使用最新的夜間構建版本,而`latest`標籤是最新的穩定版本。
```bash
docker pull docker.io/gitea/runner:latest # for the latest stable release
docker pull docker.io/gitea/runner:nightly # for the latest nightly build
```
## 設定
設定通過設定文件進行。它是可選的,當沒有指定設定文件時,將使用預設設定。
您可以透過運行以下命令生成設定文件:
```bash
./runner generate-config
```
預設設定是安全的,可以直接使用。
```bash
./runner generate-config > config.yaml
./runner --config config.yaml [command]
```
您亦可以如下使用 docker 建立設定文件:
```bash
docker run --entrypoint="" --rm -it docker.io/gitea/runner:latest runner generate-config > config.yaml
```
當使用Docker鏡像時,可以使用`CONFIG_FILE`環境變量指定設定文件。確保將文件作為卷掛載到容器中:
```bash
docker run -v $(pwd)/config.yaml:/config.yaml -e CONFIG_FILE=/config.yaml ...
```
您可能注意到上面的命令都是不完整的,因為現在還不是運行 Runner 的時候。
在運行 Runner 之前,我們需要首先將其註冊到您的Gitea實例中。
## 註冊
在運行 Runner 之前,需要進行註冊,因為 Runner 需要知道從哪裡獲取Job,並且對於Gitea實例來說,識別Runner也很重要。
## 獲取註冊令牌
### Runner級別
@@ -94,8 +26,6 @@ docker run -v $(pwd)/config.yaml:/config.yaml -e CONFIG_FILE=/config.yaml ...
請注意,即使儲存庫具有自己的儲存庫級別Runner,它仍然可以使用實例級別或組織級別Runner。未來的版本可能提供更多對此進行更好控制的選項。
### 獲取註冊令牌
Runner級別決定了從哪裡獲取註冊令牌。
- 實例級別:管理員設定頁面,例如 `<your_gitea.com>/admin/actions/runners`
@@ -106,7 +36,7 @@ Runner級別決定了從哪裡獲取註冊令牌。
註冊令牌的格式是一個隨機字符串 `D0gvfu2iHfUjNqCYVljVyRV14fISpJxxxxxxxxxx`
註冊令牌也可以透過 Gitea 的 [命令](../../administration/command-line.md#actions-generate-runner-token) 獲得:
註冊令牌也可以透過 Gitea 的 [命令](../../administration/command-line.md#actions-generate-runner-token) 獲得:
```
gitea --config /etc/gitea/app.ini actions generate-runner-token
@@ -124,155 +54,4 @@ export GITEA_RUNNER_REGISTRATION_TOKEN_FILE=/some-dir/runner-token
令牌可用於註冊多個 Runner,直到使用 Web 介面中的令牌重置鏈接將其撤銷並替換為新令牌。
### 註冊 Runner
可以透過運行以下命令來註冊 Runner:
```bash
./runner register
```
或者,您可以使用 `--config` 選項來指定前面部分提到的設定文件。
```bash
./runner --config config.yaml register
```
您將逐步輸入註冊資訊,包括:
- Gitea 實例的 URL,例如 `https://gitea.com/``http://192.168.8.8:3000/`
- 註冊令牌。
- Runner名稱(可選)。如果留空,將使用主機名。
- Runner標籤(可選)。如果留空,將使用預設標籤。
您可能對Runner標籤感到困惑,稍後將對其進行解釋。
如果您想以非交互方式註冊Runner,可以使用參數執行以下操作。
```bash
./runner register --no-interactive --instance <instance_url> --token <registration_token> --name <runner_name> --labels <runner_labels>
```
註冊Runner後,您可以在當前目錄中找到一個名為 `.runner` 的新文件。該文件儲存註冊資訊。
請不要手動編輯該文件。
如果此文件丟失或損壞,可以直接刪除它並重新註冊。
如果您想將註冊資訊儲存在其他位置,請在設定文件中指定,並不要忘記指定 `--config` 選項。
### 使用Docker註冊Runner
如果您使用的是Docker鏡像,註冊行為會略有不同。在這種情況下,註冊和運行合併為一步,因此您需要在運行 Runner 時指定註冊資訊。
```bash
docker run \
-v $(pwd)/config.yaml:/config.yaml \
-v $(pwd)/data:/data \
-v /var/run/docker.sock:/var/run/docker.sock \
-e CONFIG_FILE=/config.yaml \
-e GITEA_INSTANCE_URL=<instance_url> \
-e GITEA_RUNNER_REGISTRATION_TOKEN=<registration_token> \
-e GITEA_RUNNER_NAME=<runner_name> \
-e GITEA_RUNNER_LABELS=<runner_labels> \
--name my_runner \
-d gitea/runner:nightly
```
您可能注意到我們已將`/var/run/docker.sock`掛載到容器中。
這是因為 Runner 將在Docker容器中運行Job,因此它需要與Docker守護進程進行通信。
如前所述,如果要在主機上直接運行Job,可以將其移除。
需要明確的是,這裡的 "主機" 實際上指的是當前運行 Runner的容器,而不是主機機器本身。
### 使用 Docker compose 運行 Runner
您亦可使用如下的 `docker-compose.yml`:
```yml
version: "3.8"
services:
runner:
image: gitea/runner:nightly
environment:
CONFIG_FILE: /config.yaml
GITEA_INSTANCE_URL: "${INSTANCE_URL}"
GITEA_RUNNER_REGISTRATION_TOKEN: "${REGISTRATION_TOKEN}"
GITEA_RUNNER_NAME: "${RUNNER_NAME}"
GITEA_RUNNER_LABELS: "${RUNNER_LABELS}"
volumes:
- ./config.yaml:/config.yaml
- ./data:/data
- /var/run/docker.sock:/var/run/docker.sock
```
### 當您使用 Docker 鏡像啟動 Runner,如何設定 Cache
如果你不打算在工作流中使用 `actions/cache`,你可以忽略本段。
如果您在使用 `actions/cache` 時沒有進行額外的設定,將會返回以下錯誤資訊:
> Failed to restore: getCacheEntry failed: connect ETIMEDOUT IP:PORT
這個錯誤的原因是 runner 容器和作業容器位於不同的網路中,因此作業容器無法訪問 runner 容器。
因此,設定 cache 動作以確保其正常運行是非常重要的。請按照以下步驟操作:
- 1.獲取 Runner 容器所在主機的 LAN(本地局域網) IP 地址。
- 2.獲取一個 Runner 容器所在主機的空閒端口號。
- 3.在設定文件中如下設定:
```yaml
cache:
enabled: true
dir: ""
# 使用步驟 1. 獲取的 LAN IP
host: "192.168.8.17"
# 使用步驟 2. 獲取的端口號
port: 8088
```
- 4.啟動容器時, 將 Cache 端口映射至主機。
```bash
docker run \
--name gitea-docker-runner \
-p 8088:8088 \
-d gitea/runner:nightly
```
### 標籤
```mermaid
flowchart TD
A[Workflow: runs-on: ubuntu-22.04] --> B[Runner 收到 Job 請求]
B --> C[匹配標籤: ubuntu-22.04:docker://node:16-bullseye]
C --> D[啟動 Docker 容器: node:16-bullseye]
D --> E[在容器中執行 Job 步驟]
E --> F[返回執行結果給 Gitea]
```
Runner的標籤用於確定Runner可以運行哪些Job以及如何運行它們。
預設標籤為`ubuntu-latest:docker://node:16-bullseye,ubuntu-22.04:docker://node:16-bullseye,ubuntu-20.04:docker://node:16-bullseye,ubuntu-18.04:docker://node:16-buster`
它們是逗號分隔的列表,每個專案都是一個標籤。
讓我們以 `ubuntu-22.04:docker://node:16-bullseye` 為例。
它意味著Runner可以運行帶有`runs-on: ubuntu-22.04`的Job,並且該Job將在使用`node:16-bullseye`鏡像的Docker容器中運行。
如果預設鏡像無法滿足您的需求,並且您有足夠的磁盤空間可以使用更好、更大的鏡像,您可以將其更改為`ubuntu-22.04:docker://<您喜歡的鏡像>`
您可以在[act 鏡像](https://github.com/nektos/act/blob/master/IMAGES.md)上找到更多有用的鏡像。
如果您想直接在主機上運行Job,您可以將其更改為`ubuntu-22.04:host`或僅`ubuntu-22.04``:host`是可選的。
然而,我們建議您使用類似`linux_amd64:host``windows:host`的特殊名稱,以避免誤用。
從 Gitea 1.21 開始,您可以透過修改 runner 的設定文件中的 `container.labels` 來更改標籤(如果沒有設定文件,請參考 [設定教學](#設定)),透過執行 `./runner daemon --config config.yaml` 命令重啟 runner 之後,這些新定義的標籤就會生效。
## 運行
註冊完Runner後,您可以透過運行以下命令來運行它:
```bash
./runner daemon
# or
./runner daemon --config config.yaml
```
Runner將從Gitea實例獲取Job並自動運行它們。
由於Gitea Runner仍在不斷升級中,建議定期檢查最新版本並進行升級。
獲取註冊令牌後,請參閱 [Gitea Runner 文件](/runner/) 了解如何安裝、設定和運行您的 Runner。
@@ -8,81 +8,13 @@ aliases:
# Gitea Runner
本頁面將詳細介紹[Gitea Runner](https://gitea.com/gitea/runner),這是Gitea Actions的Runner。
本頁面將介紹[Gitea Runner](https://gitea.com/gitea/runner),這是Gitea Actions的Runner。
## 要求
:::tip
詳細的安裝、設定和使用說明,請參閱 [Gitea Runner 文件](/runner/)。
:::
建議在Docker容器中運行Job,因此您需要首先安裝Docker。
並確保Docker守護進程正在運行。
其他與Docker API相容的OCI容器引擎也應該可以正常工作,但尚未經過測試。
但是,如果您確定要直接在主機上運行Job,則不需要Docker。
## 安裝
有多種安裝Gitea Runner的方法。
### 下載二進制文件
您可以從[發佈頁面](https://gitea.com/gitea/runner/releases)下載二進制文件。
然而,如果您想使用最新的夜間構建版本,可以從[下載頁面](https://dl.gitea.com/gitea-runner/)下載。
下載二進制文件時,請確保您已經下載了適用於您的平台的正確版本。
您可以透過運行以下命令進行檢查:
```bash
chmod +x runner
./runner --version
```
如果看到版本資訊,則表示您已經下載了正確的二進制文件。
### 使用 Docker 鏡像
您可以使用[docker hub](https://hub.docker.com/r/gitea/runner/tags)上的Docker鏡像。
與二進制文件類似,您可以使用`nightly`標籤使用最新的夜間構建版本,而`latest`標籤是最新的穩定版本。
```bash
docker pull docker.io/gitea/runner:latest # for the latest stable release
docker pull docker.io/gitea/runner:nightly # for the latest nightly build
```
## 設定
設定通過設定文件進行。它是可選的,當沒有指定設定文件時,將使用預設設定。
您可以透過運行以下命令生成設定文件:
```bash
./runner generate-config
```
預設設定是安全的,可以直接使用。
```bash
./runner generate-config > config.yaml
./runner --config config.yaml [command]
```
您亦可以如下使用 docker 建立設定文件:
```bash
docker run --entrypoint="" --rm -it docker.io/gitea/runner:latest runner generate-config > config.yaml
```
當使用Docker鏡像時,可以使用`CONFIG_FILE`環境變量指定設定文件。確保將文件作為卷掛載到容器中:
```bash
docker run -v $(pwd)/config.yaml:/config.yaml -e CONFIG_FILE=/config.yaml ...
```
您可能注意到上面的命令都是不完整的,因為現在還不是運行 Runner 的時候。
在運行 Runner 之前,我們需要首先將其註冊到您的Gitea實例中。
## 註冊
在運行 Runner 之前,需要進行註冊,因為 Runner 需要知道從哪裡獲取Job,並且對於Gitea實例來說,識別Runner也很重要。
## 獲取註冊令牌
### Runner級別
@@ -94,8 +26,6 @@ docker run -v $(pwd)/config.yaml:/config.yaml -e CONFIG_FILE=/config.yaml ...
請注意,即使儲存庫具有自己的儲存庫級別Runner,它仍然可以使用實例級別或組織級別Runner。未來的版本可能提供更多對此進行更好控制的選項。
### 獲取註冊令牌
Runner級別決定了從哪裡獲取註冊令牌。
- 實例級別:管理員設定頁面,例如 `<your_gitea.com>/admin/actions/runners`
@@ -106,7 +36,7 @@ Runner級別決定了從哪裡獲取註冊令牌。
註冊令牌的格式是一個隨機字符串 `D0gvfu2iHfUjNqCYVljVyRV14fISpJxxxxxxxxxx`
註冊令牌也可以透過 Gitea 的 [命令](../../administration/command-line.md#actions-generate-runner-token) 獲得:
註冊令牌也可以透過 Gitea 的 [命令](../../administration/command-line.md#actions-generate-runner-token) 獲得:
```
gitea --config /etc/gitea/app.ini actions generate-runner-token
@@ -124,155 +54,4 @@ export GITEA_RUNNER_REGISTRATION_TOKEN_FILE=/some-dir/runner-token
令牌可用於註冊多個 Runner,直到使用 Web 介面中的令牌重置鏈接將其撤銷並替換為新令牌。
### 註冊 Runner
可以透過運行以下命令來註冊 Runner:
```bash
./runner register
```
或者,您可以使用 `--config` 選項來指定前面部分提到的設定文件。
```bash
./runner --config config.yaml register
```
您將逐步輸入註冊資訊,包括:
- Gitea 實例的 URL,例如 `https://gitea.com/``http://192.168.8.8:3000/`
- 註冊令牌。
- Runner名稱(可選)。如果留空,將使用主機名。
- Runner標籤(可選)。如果留空,將使用預設標籤。
您可能對Runner標籤感到困惑,稍後將對其進行解釋。
如果您想以非交互方式註冊Runner,可以使用參數執行以下操作。
```bash
./runner register --no-interactive --instance <instance_url> --token <registration_token> --name <runner_name> --labels <runner_labels>
```
註冊Runner後,您可以在當前目錄中找到一個名為 `.runner` 的新文件。該文件儲存註冊資訊。
請不要手動編輯該文件。
如果此文件丟失或損壞,可以直接刪除它並重新註冊。
如果您想將註冊資訊儲存在其他位置,請在設定文件中指定,並不要忘記指定 `--config` 選項。
### 使用Docker註冊Runner
如果您使用的是Docker鏡像,註冊行為會略有不同。在這種情況下,註冊和運行合併為一步,因此您需要在運行 Runner 時指定註冊資訊。
```bash
docker run \
-v $(pwd)/config.yaml:/config.yaml \
-v $(pwd)/data:/data \
-v /var/run/docker.sock:/var/run/docker.sock \
-e CONFIG_FILE=/config.yaml \
-e GITEA_INSTANCE_URL=<instance_url> \
-e GITEA_RUNNER_REGISTRATION_TOKEN=<registration_token> \
-e GITEA_RUNNER_NAME=<runner_name> \
-e GITEA_RUNNER_LABELS=<runner_labels> \
--name my_runner \
-d gitea/runner:nightly
```
您可能注意到我們已將`/var/run/docker.sock`掛載到容器中。
這是因為 Runner 將在Docker容器中運行Job,因此它需要與Docker守護進程進行通信。
如前所述,如果要在主機上直接運行Job,可以將其移除。
需要明確的是,這裡的 "主機" 實際上指的是當前運行 Runner的容器,而不是主機機器本身。
### 使用 Docker compose 運行 Runner
您亦可使用如下的 `docker-compose.yml`:
```yml
version: "3.8"
services:
runner:
image: gitea/runner:nightly
environment:
CONFIG_FILE: /config.yaml
GITEA_INSTANCE_URL: "${INSTANCE_URL}"
GITEA_RUNNER_REGISTRATION_TOKEN: "${REGISTRATION_TOKEN}"
GITEA_RUNNER_NAME: "${RUNNER_NAME}"
GITEA_RUNNER_LABELS: "${RUNNER_LABELS}"
volumes:
- ./config.yaml:/config.yaml
- ./data:/data
- /var/run/docker.sock:/var/run/docker.sock
```
### 當您使用 Docker 鏡像啟動 Runner,如何設定 Cache
如果你不打算在工作流中使用 `actions/cache`,你可以忽略本段。
如果您在使用 `actions/cache` 時沒有進行額外的設定,將會返回以下錯誤資訊:
> Failed to restore: getCacheEntry failed: connect ETIMEDOUT IP:PORT
這個錯誤的原因是 runner 容器和作業容器位於不同的網路中,因此作業容器無法訪問 runner 容器。
因此,設定 cache 動作以確保其正常運行是非常重要的。請按照以下步驟操作:
- 1.獲取 Runner 容器所在主機的 LAN(本地局域網) IP 地址。
- 2.獲取一個 Runner 容器所在主機的空閒端口號。
- 3.在設定文件中如下設定:
```yaml
cache:
enabled: true
dir: ""
# 使用步驟 1. 獲取的 LAN IP
host: "192.168.8.17"
# 使用步驟 2. 獲取的端口號
port: 8088
```
- 4.啟動容器時, 將 Cache 端口映射至主機。
```bash
docker run \
--name gitea-docker-runner \
-p 8088:8088 \
-d gitea/runner:nightly
```
### 標籤
```mermaid
flowchart TD
A[Workflow: runs-on: ubuntu-22.04] --> B[Runner 收到 Job 請求]
B --> C[匹配標籤: ubuntu-22.04:docker://node:16-bullseye]
C --> D[啟動 Docker 容器: node:16-bullseye]
D --> E[在容器中執行 Job 步驟]
E --> F[返回執行結果給 Gitea]
```
Runner的標籤用於確定Runner可以運行哪些Job以及如何運行它們。
預設標籤為`ubuntu-latest:docker://node:16-bullseye,ubuntu-22.04:docker://node:16-bullseye,ubuntu-20.04:docker://node:16-bullseye,ubuntu-18.04:docker://node:16-buster`
它們是逗號分隔的列表,每個專案都是一個標籤。
讓我們以 `ubuntu-22.04:docker://node:16-bullseye` 為例。
它意味著Runner可以運行帶有`runs-on: ubuntu-22.04`的Job,並且該Job將在使用`node:16-bullseye`鏡像的Docker容器中運行。
如果預設鏡像無法滿足您的需求,並且您有足夠的磁盤空間可以使用更好、更大的鏡像,您可以將其更改為`ubuntu-22.04:docker://<您喜歡的鏡像>`
您可以在[act 鏡像](https://github.com/nektos/act/blob/master/IMAGES.md)上找到更多有用的鏡像。
如果您想直接在主機上運行Job,您可以將其更改為`ubuntu-22.04:host`或僅`ubuntu-22.04``:host`是可選的。
然而,我們建議您使用類似`linux_amd64:host``windows:host`的特殊名稱,以避免誤用。
從 Gitea 1.21 開始,您可以透過修改 runner 的設定文件中的 `container.labels` 來更改標籤(如果沒有設定文件,請參考 [設定教學](#設定)),透過執行 `./runner daemon --config config.yaml` 命令重啟 runner 之後,這些新定義的標籤就會生效。
## 運行
註冊完Runner後,您可以透過運行以下命令來運行它:
```bash
./runner daemon
# or
./runner daemon --config config.yaml
```
Runner將從Gitea實例獲取Job並自動運行它們。
由於Gitea Runner仍在不斷升級中,建議定期檢查最新版本並進行升級。
獲取註冊令牌後,請參閱 [Gitea Runner 文件](/runner/) 了解如何安裝、設定和運行您的 Runner。
+4 -2
View File
@@ -3,6 +3,8 @@ sidebar_position: 1
slug: /
---
import RunnerDoc from '@site/docs/usage/actions/runner.mdx';
# Gitea Runner
<RunnerDoc />
The [Gitea Runner](https://gitea.com/gitea/runner) is the runner for Gitea Actions. This section contains versioned documentation for the runner.
See the latest stable documentation at [Gitea Runner](/runner/).
@@ -39,42 +39,7 @@ If you see the version information, it means that you have downloaded the correc
### Obtain a registration token
You can register a runner at different levels. It can be:
- Instance level: The runner will run jobs for all repositories in the instance.
- Organization level: The runner will run jobs for all repositories in the organization.
- Repository level: The runner will run jobs for the repository it belongs to.
Note that the repository may still use instance-level or organization-level runners even if it has its own repository-level runners. A future release may provide an option to allow more control over this.
Before registering the runner and running it, you need a registration token. The level of the runner determines where to obtain the registration token.
- Instance level: The admin settings page, like `<your_gitea.com>/-/admin/actions/runners`.
- Organization level: The organization settings page, like `<your_gitea.com>/<org>/settings/actions/runners`.
- Repository level: The repository settings page, like `<your_gitea.com>/<owner>/<repo>/settings/actions/runners`.
If you cannot see the settings page, please make sure that you have the right permissions and that Actions have been enabled.
The format of the registration token is a random string `D0gvfu2iHfUjNqCYVljVyRV14fISpJxxxxxxxxxx`.
A registration token can also be obtained from the Gitea [command-line interface](/administration/command-line#actions-generate-runner-token):
```
gitea --config /etc/gitea/app.ini actions generate-runner-token
```
You can also use `GITEA_RUNNER_REGISTRATION_TOKEN`/`GITEA_RUNNER_REGISTRATION_TOKEN_FILE` environment variables to set a global runner registration token when Gitea starts, for example:
```
openssl rand -hex 24 > /some-dir/runner-token
export GITEA_RUNNER_REGISTRATION_TOKEN_FILE=/some-dir/runner-token
./gitea --config ...
```
The token from the environment is valid until you reset the token (re-create a new one) via the web UI or API.
Tokens are valid for registering multiple runners, until they are revoked and replaced by a new token using the token reset link in the web interface.
Registration tokens are managed by your Gitea instance. Refer to the [Gitea Actions documentation](/usage/actions/runner) for details on obtaining a registration token at the instance, organization, or repository level.
### Configuration
@@ -281,14 +246,11 @@ When you are using the docker image, you can specify the configuration file by u
docker run -v $PWD/config.yaml:/config.yaml -e CONFIG_FILE=/config.yaml ...
```
You may notice the commands above are incomplete because it is not time to run the runner yet.
Before running the runner, we need to register it to your Gitea instance first.
### Start the runner with docker
If you are using the docker image, behavior will be slightly different. Registration and running are combined into one step in this case, so you need to specify the registration information when running the runner.
A quick start with docker run along with a minimal parameter set is shown below. You need to get the `<registration_token>` from the above step, and set a unique name for `<gitea_runner_name>` and for `<container_name>`.
A quick start with docker run along with a minimal parameter set is shown below. You need a `<registration_token>` (see [how to obtain a registration token](/usage/actions/runner)), and set a unique name for `<gitea_runner_name>` and for `<container_name>`.
```bash
docker run \
@@ -6,39 +6,13 @@ sidebar_position: 20
# Gitea Runner
This page will introduce the [Gitea Runner](https://gitea.com/gitea/runner) in detail, which is the runner for Gitea Actions.
This page will introduce the [Gitea Runner](https://gitea.com/gitea/runner), which is the runner for Gitea Actions.
## Requirements
:::tip
For detailed installation, configuration, and usage instructions, see the [Gitea Runner documentation](/runner/).
:::
Currently the runner supports three modes in which it can be run.
1. Host: runner will run as an application on the host. This provides no encapsulation.
2. Docker (recommended): Runs jobs in a [Docker](https://docker.com) container. If you choose this mode, you need to [install Docker](https://docs.docker.com/engine/install/) first and make sure that the Docker daemon is running.
3. Docker-in-Docker (DinD): Puts the runner into rootless mode. It then runs in a Docker container with its own Docker daemon that has fewer privileges. It will spawn job containers from there. Best security but more complex setup.
Other OCI container engines which are compatible with Docker's API should also work, but are untested.
However, if you are sure that you want to run jobs directly on the host only, then Docker is not required.
There are multiple ways to install the runner.
## Installation with binary
### Download the binary
You can download the binary from the [release page](https://gitea.com/gitea/runner/releases).
However, if you want to use the latest nightly build, you can download it from the [download page](https://dl.gitea.com/gitea-runner/).
When you download the binary, please make sure that you have downloaded the correct one for your platform.
You can check it by running the following command if you are in a Unix-style OS.
```bash
chmod +x runner
./runner --version
```
If you see the version information, it means that you have downloaded the correct binary.
### Obtain a registration token
## Obtain a registration token
You can register a runner at different levels. It can be:
@@ -48,7 +22,6 @@ You can register a runner at different levels. It can be:
Note that the repository may still use instance-level or organization-level runners even if it has its own repository-level runners. A future release may provide an option to allow more control over this.
Before registering the runner and running it, you need a registration token. The level of the runner determines where to obtain the registration token.
- Instance level: The admin settings page, like `<your_gitea.com>/-/admin/actions/runners`.
@@ -77,383 +50,4 @@ The token from the environment is valid until you reset the token (re-create a n
Tokens are valid for registering multiple runners, until they are revoked and replaced by a new token using the token reset link in the web interface.
### Configuration
Configuration is done via a configuration file. It is optional, and the default configuration will be used when no configuration file is specified. You can generate a configuration file by running the following command:
```bash
./runner generate-config
```
The default configuration is safe to use without any modification, so you can just use it directly.
```bash
./runner generate-config > config.yaml
./runner --config config.yaml [command]
```
### Register the runner
Registration is required before running Gitea Runner, because the runner needs to know where to get jobs from. It is also important for the Gitea instance to identify the runner.
If this has been installed using the binary package, the runner can be registered by running the following command.
```bash
./runner register
```
Alternatively, you can use the `--config` option to specify the configuration file mentioned in the previous section.
```bash
./runner --config config.yaml register
```
You will be asked to input the registration information step by step. This includes:
- The Gitea instance URL, like `https://gitea.com/` or `http://192.168.8.8:3000/`.
- The registration token.
- The runner name, which is optional. If you leave it blank, the hostname will be used.
- The runner labels, which is optional. If you leave it blank, the default labels will be used.
You may be confused about the runner labels, which will be explained later.
If you want to register the runner in a non-interactive way, you can use arguments to do it.
```bash
./runner register --no-interactive --instance <instance_url> --token <registration_token> --name <runner_name> --labels <runner_labels>
```
When you have registered the runner, you can find a new file named `.runner` in the current directory.
This file stores the registration information.
Please do not edit it manually.
If this file is missing or corrupted, you can simply remove it and register again.
If you want to store the registration information in another place, you can specify it in the configuration file,
and don't forget to specify the `--config` option.
#### Ephemeral Runners
Ephemeral runners provide a security hardening mechanism for enabling organization- or instance-wide runners without requiring full user trust. Once a job is assigned within a spot VM or container, the runner's exposed credentials are automatically revoked—blocking it from polling further jobs before any untrusted code runs, while still allowing it to report progress until completion by either Gitea or the runner.
Gitea Runner **0.2.12+** is required.
The updated commands for registering the runner as ephemeral are listed below. Refer to the previous section for detailed information on registering the runner.
```bash
./runner register --ephemeral
```
```bash
./runner --config config.yaml register --ephemeral
```
```bash
./runner register --no-interactive --ephemeral --instance <instance_url> --token <registration_token> --name <runner_name> --labels <runner_labels>
```
The runner must be registered each time it is intended to receive a job. After completing the single job it is designed to execute, the runner terminates.
To automate the registration and startup of new runners when a job is queued, use the `workflow_job` webhook.
### Start the runner from the command line
After you have registered the runner, you can run it with the following command:
```shell
./runner daemon
```
or
```bash
./runner daemon --config config.yaml
```
The runner will fetch jobs from the Gitea instance and run them automatically.
### Start the runner with Systemd
It is also possible to run Gitea Runner as a [systemd](https://en.wikipedia.org/wiki/Systemd) service. Create an unprivileged `runner` user on your system, and create the following file in `/etc/systemd/system/runner.service`. The paths in `ExecStart` and `WorkingDirectory` may need to be adjusted depending on where you installed the `runner` binary, its configuration file, and the home directory of the `runner` user.
```ini
[Unit]
Description=Gitea Actions runner
Documentation=https://gitea.com/gitea/runner
After=docker.service
[Service]
ExecStart=/usr/local/bin/runner daemon --config /etc/runner/config.yaml
ExecReload=/bin/kill -s HUP $MAINPID
WorkingDirectory=/var/lib/runner
TimeoutSec=0
RestartSec=10
Restart=always
User=runner
[Install]
WantedBy=multi-user.target
```
Then:
```bash
# load the new systemd unit file
sudo systemctl daemon-reload
# start the service and enable it at boot
sudo systemctl enable runner --now
```
If using Docker, the `runner` user should also be added to the `docker` group before starting the service. Keep in mind that this effectively gives `runner` root access to the system [[1]](https://docs.docker.com/engine/security/#docker-daemon-attack-surface).
### Start the runner with LaunchDaemon (macOS)
Mac uses `launchd` in place of systemd for registering daemon processes. By default, daemons run as the root user, so if desired an unprivileged `_runner` user can be created via the `dscl` tool. The following file should then be created in the directory `/Library/LaunchDaemon/com.gitea.runner.plist`. The paths for `WorkingDirectory`, `ProgramArguments`, `StandardOutPath`, `StandardErrPath`, and the `HOME` environment variable may need to be updated to reflect your installation. Also note that any executables outside of the example `PATH` shown will need to be explicitly included and will not be inherited from existing configurations.
```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.gitea.runner</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/runner</string>
<string>daemon</string>
<string>--config</string>
<string>/etc/runner/config.yaml</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>WorkingDirectory</key>
<string>/var/lib/runner</string>
<key>StandardOutPath</key>
<string>/var/lib/runner/runner.log</string>
<key>StandardErrorPath</key>
<string>/var/lib/runner/runner.err</string>
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
<key>HOME</key>
<string>/var/lib/runner</string>
</dict>
<key>UserName</key>
<string>_runner</string>
</dict>
</plist>
```
Then:
```bash
sudo launchctl load /Library/LaunchDaemon/com.gitea.runner.plist
```
You can also set up a Linux or Windows service to let the runner run automatically.
## Install with the docker image
### Pull the image
You can use the docker image from [Docker Hub](https://hub.docker.com/r/gitea/runner/tags).
Just like the binary, you can use the latest nightly build by using the `nightly` tag, while the `latest` tag is the latest stable release.
```bash
docker pull docker.io/gitea/runner:latest # for the latest stable release
```
If you want to use the newest or experimental features, you can also use the nightly image.
```bash
docker pull docker.io/gitea/runner:nightly # for the latest nightly build
```
### Configuration
Configuration is optional, but you can also generate a config file with docker:
```bash
docker run --entrypoint="" --rm -it docker.io/gitea/runner:latest runner generate-config > config.yaml
```
When you are using the docker image, you can specify the configuration file by using the `CONFIG_FILE` environment variable. Make sure that the file is mounted into the container as a volume:
```bash
docker run -v $PWD/config.yaml:/config.yaml -e CONFIG_FILE=/config.yaml ...
```
You may notice the commands above are incomplete because it is not time to run the runner yet.
Before running the runner, we need to register it to your Gitea instance first.
### Start the runner with docker
If you are using the docker image, behavior will be slightly different. Registration and running are combined into one step in this case, so you need to specify the registration information when running the runner.
A quick start with docker run along with a minimal parameter set is shown below. You need to get the `<registration_token>` from the above step, and set a unique name for `<gitea_runner_name>` and for `<container_name>`.
```bash
docker run \
-e GITEA_INSTANCE_URL=<instance_url> \
-e GITEA_RUNNER_REGISTRATION_TOKEN=<registration_token> \
-e GITEA_RUNNER_NAME=<gitea_runner_name> \
--name <container_name> \
-v /var/run/docker.sock:/var/run/docker.sock \
-d docker.io/gitea/runner:latest
```
You can add more parameters to use a custom config, add a `data` directory for non-volatile file storage, etc.
```bash
docker run \
-v $PWD/config.yaml:/config.yaml \
-v $PWD/data:/data \
-v /var/run/docker.sock:/var/run/docker.sock \
-e CONFIG_FILE=/config.yaml \
-e GITEA_INSTANCE_URL=<instance_url> \
-e GITEA_RUNNER_REGISTRATION_TOKEN=<registration_token> \
-e GITEA_RUNNER_NAME=<gitea_runner_name> \
-e GITEA_RUNNER_LABELS=<runner_labels> \
--name <container_name> \
-d docker.io/gitea/runner:latest
```
You may notice that we have mounted `/var/run/docker.sock` into the container.
This is because with this setup, the runner will execute jobs in temporary Docker containers, so it needs to communicate with the Docker daemon.
As mentioned, you can remove it if you want to run jobs on the host directly.
To be clear, the "host" actually means the container that is running the runner now, instead of the host machine.
---
To enable ephemeral runners, set the environment variable `GITEA_RUNNER_EPHEMERAL=1` in the runner image. This setup doesn't use a `/data` volume because the credentials are single-use and not intended to be reused. You can find more details about this mode under [Ephemeral runners](#ephemeral-runners).
```bash
docker run \
-e GITEA_INSTANCE_URL=<instance_url> \
-e GITEA_RUNNER_REGISTRATION_TOKEN=<registration_token> \
-e GITEA_RUNNER_EPHEMERAL=1 \
-e GITEA_RUNNER_NAME=<runner_name> \
--name my_runner \
-d docker.io/gitea/runner:nightly
```
```bash
docker run \
-v $PWD/config.yaml:/config.yaml \
-v /var/run/docker.sock:/var/run/docker.sock \
-e CONFIG_FILE=/config.yaml \
-e GITEA_INSTANCE_URL=<instance_url> \
-e GITEA_RUNNER_REGISTRATION_TOKEN=<registration_token> \
-e GITEA_RUNNER_EPHEMERAL=1 \
-e GITEA_RUNNER_NAME=<runner_name> \
-e GITEA_RUNNER_LABELS=<runner_labels> \
--name my_runner \
-d docker.io/gitea/runner:nightly
```
Mounting the host's Docker socket using `/var/run/docker.sock:/var/run/docker.sock` introduces a potential security vulnerability. If a job can access this socket, the reusable `GITEA_RUNNER_REGISTRATION_TOKEN` could be exposed through Docker inspect data.
### Start the runner using docker compose
You could also set up the runner using the following `docker-compose.yml`:
```yml
version: "3.8"
services:
runner:
image: docker.io/gitea/runner:nightly
environment:
CONFIG_FILE: /config.yaml
GITEA_INSTANCE_URL: "${INSTANCE_URL}"
GITEA_RUNNER_REGISTRATION_TOKEN: "${REGISTRATION_TOKEN}"
GITEA_RUNNER_NAME: "${RUNNER_NAME}"
GITEA_RUNNER_LABELS: "${RUNNER_LABELS}"
volumes:
- ./config.yaml:/config.yaml
- ./data:/data
- /var/run/docker.sock:/var/run/docker.sock
```
When using docker, there is no requirement to enter the container and manually run `./runner daemon` command as shown below. Once the container has been started successfully, it will show up as an active runner in your Gitea instance.
---
To enable ephemeral runners, set the environment variable `GITEA_RUNNER_EPHEMERAL=1` in the runner image. This setup doesn't use a `/data` volume because the credentials are single-use and not intended to be reused. You can find more details about this mode under [Ephemeral runners](#ephemeral-runners).
```yml
version: "3.8"
services:
runner:
image: docker.io/gitea/runner:nightly
environment:
CONFIG_FILE: /config.yaml
GITEA_INSTANCE_URL: "${INSTANCE_URL}"
GITEA_RUNNER_REGISTRATION_TOKEN: "${REGISTRATION_TOKEN}"
GITEA_RUNNER_NAME: "${RUNNER_NAME}"
GITEA_RUNNER_LABELS: "${RUNNER_LABELS}"
GITEA_RUNNER_EPHEMERAL: "1"
volumes:
- ./config.yaml:/config.yaml
- /var/run/docker.sock:/var/run/docker.sock
```
Mounting the host's Docker socket using `/var/run/docker.sock:/var/run/docker.sock` introduces a potential security vulnerability. If a job can access this socket, the reusable `GITEA_RUNNER_REGISTRATION_TOKEN` could be exposed through Docker inspect data.
### More start examples
A couple more usage examples can be found in the [runner](https://gitea.com/gitea/runner/src/branch/main/examples) repository.
## Advanced Configurations
### Configuring cache when starting a runner using the docker image
If you do not intend to use `actions/cache` in your workflow, you can ignore this section.
If you use `actions/cache` without any additional configuration, it will return the following error:
> Failed to restore: getCacheEntry failed: connect ETIMEDOUT IP:PORT
The error occurs because the runner container and job container are on different networks, so the job container cannot access the runner container.
Therefore, it is essential to configure the cache action to ensure its proper functioning. Follow these steps:
- 1. Obtain the LAN IP address of the host machine where the runner container is running.
- 2. Find an available port number on the host machine where the runner container is running.
- 3. Configure the following settings in the configuration file:
```yaml
cache:
enabled: true
dir: ""
# Use the LAN IP obtained in step 1
host: "192.168.8.17"
# Use the port number obtained in step 2
port: 8088
```
- 4. When starting the container, map the cache port to the host machine:
```bash
docker run \
--name gitea-docker-runner \
-p 8088:8088 \
-d docker.io/gitea/runner:nightly
```
### Labels
The labels of a runner are used to determine which jobs the runner can run, and how to run them.
The default labels are `ubuntu-latest:docker://node:16-bullseye,ubuntu-22.04:docker://node:16-bullseye,ubuntu-20.04:docker://node:16-bullseye,ubuntu-18.04:docker://node:16-buster`.
It is a comma-separated list, and each item is a label.
Let's take `ubuntu-22.04:docker://node:16-bullseye` as an example.
It means that the runner can run jobs with `runs-on: ubuntu-22.04`, and the job will be run in a docker container with the image `node:16-bullseye`.
If the default image is insufficient for your needs, and you have enough disk space to use a better and bigger one, you can change it to `ubuntu-22.04:docker://<the image you like>`.
You can find more useful images on [act images](https://github.com/nektos/act/blob/master/IMAGES.md).
If you want to run jobs on the host directly, you can change it to `ubuntu-22.04:host` or just `ubuntu-22.04`; `:host` is optional.
However, we suggest you use a special name like `linux_amd64:host` or `windows:host` to avoid misusing it.
Starting with Gitea 1.21, you can change labels by modifying `runners.labels` in the runner configuration file (if you don't have a configuration file, please refer to [configuration tutorials](#configuration)).
The runner will use these new labels as soon as you restart it, i.e., by calling `./runner daemon --config config.yaml`.
Once you have a registration token, follow the [Gitea Runner documentation](/runner/) to install, configure, and run your runner.