mirror of
https://gitea.com/gitea/docs.git
synced 2026-11-04 17:19:52 +00:00
Simplify the runner docs and fix their outdated facts (#600)
The runner pages had drifted from the runner. They claimed Podman is unsupported, a registration retry limit of 10, a `container.env` proxy override that has no effect, and they used the deprecated `generate-config` command, while the actual instructions were buried under implementation details. The develop and 5.x pages are rewritten from the current runner sources (`main` is `v5.2.0`). They are shorter and aimed at operators, with a new page covering what jobs get. The reference generator now documents the `config` command, and the quickstart pages in every language use the `gitea-runner` binary name. Reviewed-on: https://gitea.com/gitea/docs/pulls/600 Reviewed-by: Lunny Xiao <[email protected]> Co-authored-by: silverwind <[email protected]>
This commit is contained in:
1 parent
a874918bb7
commit
be6aefc7e8
53 files changed
+1531
-1661
No files matched your search
+64
-93
@@ -1,107 +1,78 @@
|
||||
---
|
||||
sidebar_position: 5
|
||||
sidebar_position: 6
|
||||
---
|
||||
|
||||
# Caching
|
||||
|
||||
Every runner starts its own cache server, so `actions/cache` works without any configuration. Cache entries are local to that runner: two runners do not share a cache unless you make them.
|
||||
|
||||
## Cache service v2
|
||||
|
||||
`actions/[email protected]` and later can use the *cache service v2* API. The runner serves it from the same store as v1, on by default, and it also works behind a shared cache server. Turn it off with:
|
||||
|
||||
```yaml
|
||||
cache:
|
||||
v2: false
|
||||
```
|
||||
|
||||
Those actions refuse any host they do not take for GitHub. Rather than misreport the server URL, the runner edits that check out of the action's own JavaScript bundle and keeps the untouched copy beside it; a bundle it does not recognise is left alone and keeps to v1. The same edit lets the stock `actions/upload-artifact` and `actions/download-artifact` work from `v4.4.0` on, without the `gitea-upload-artifact` fork.
|
||||
|
||||
Because `ACTIONS_RESULTS_URL` names one origin that has to serve the whole results API, the cache server also forwards the artifact half of it to the Gitea instance the job belongs to. Jobs are therefore pointed at the cache server, which is what makes clients such as `docker buildx` find the cache service instead of receiving a 404 from Gitea.
|
||||
|
||||
## Where cache blobs are stored
|
||||
|
||||
```yaml
|
||||
cache:
|
||||
enabled: true
|
||||
dir: /var/lib/gitea-runner/cache # default: $HOME/.cache/actcache
|
||||
```
|
||||
|
||||
The directory grows with use; entries are evicted as they expire, so give it a filesystem with room to spare and monitor it like any other build cache.
|
||||
|
||||
## Dockerized runners
|
||||
|
||||
When the runner itself runs in a container and creates a network per job, the address it detects for its own cache server is often unreachable from the job containers. `actions/cache` then fails with:
|
||||
|
||||
```text
|
||||
Failed to restore: getCacheEntry failed: connect ETIMEDOUT IP:PORT
|
||||
```
|
||||
|
||||
Pin the address and the port the job containers should use, and make that endpoint reachable:
|
||||
|
||||
1. take an address of the host that job containers can reach, and a free port on it;
|
||||
2. configure them:
|
||||
|
||||
```yaml
|
||||
cache:
|
||||
enabled: true
|
||||
dir: ""
|
||||
host: "192.168.8.17"
|
||||
port: 8088
|
||||
```
|
||||
|
||||
3. publish the port when starting the runner container:
|
||||
|
||||
```bash
|
||||
docker run -d --name gitea-runner -p 8088:8088 ... docker.io/gitea/runner:nightly
|
||||
```
|
||||
|
||||
Putting the runner and the job containers on one shared `container.network` instead works too, and then the auto-detected address is reachable.
|
||||
By default, each runner runs a cache server for `actions/cache`, so caching works without setup.
|
||||
The runner stores entries in `cache.dir`, which defaults to `$HOME/.cache/actcache`. It does not share entries with other runners.
|
||||
|
||||
## Sharing a cache between runners
|
||||
|
||||
Run one dedicated cache server that every runner points at.
|
||||
Run one `gitea-runner cache-server` and configure each runner to use it. Use the same secret on the cache server and every runner. Generate the secret with `openssl rand -hex 32`.
|
||||
|
||||
1. Config for the cache server host:
|
||||
|
||||
```yaml
|
||||
cache:
|
||||
dir: /data/actcache
|
||||
port: 8088
|
||||
external_secret: "replace-with-a-strong-random-secret"
|
||||
# external_secret_file: /run/secrets/cache-secret # or keep it out of this file
|
||||
```
|
||||
|
||||
2. Start it:
|
||||
|
||||
```bash
|
||||
gitea-runner -c cache-server-config.yaml cache-server
|
||||
```
|
||||
|
||||
3. On every runner:
|
||||
|
||||
```yaml
|
||||
cache:
|
||||
external_server: "http://cache-host:8088/"
|
||||
external_secret: "replace-with-a-strong-random-secret" # must match the server
|
||||
```
|
||||
|
||||
The secret authenticates runners against the shared server and must be identical on all of them; generate one with `openssl rand -hex 32`. Setting both `external_secret` and `external_secret_file` is an error.
|
||||
|
||||
`cache-server` accepts `--dir`, `--host` and `--port`, which override the corresponding `cache.*` keys. Every other setting, `external_secret` included, has to come from the config file.
|
||||
|
||||
### Alternatives
|
||||
|
||||
- **Shared filesystem** — mount the same NFS/CIFS share on every runner and point `cache.dir` at it. Simpler, but repositories are less isolated from each other than behind a cache server.
|
||||
- **Object storage** — mount S3 or MinIO as a FUSE filesystem, e.g. with [s3fs](https://github.com/s3fs-fuse/s3fs-fuse) or [goofys](https://github.com/kahing/goofys), and set `cache.dir` to the mount point.
|
||||
|
||||
## Action repository cache
|
||||
|
||||
Actions pulled by `uses:` are cached too, and by default refreshed on every job so a moved tag is picked up. To pin them to what has already been fetched:
|
||||
On the cache server:
|
||||
|
||||
```yaml
|
||||
cache:
|
||||
offline_mode: true
|
||||
dir: /data/actcache
|
||||
port: 8088
|
||||
external_secret_file: /run/secrets/cache-secret
|
||||
```
|
||||
|
||||
A re-tagged `v6` or an updated branch then stays at the cached commit until its entry expires or is removed. Combined with `runner.action_shallow_clone` (on by default, fetching only the requested ref at depth 1), this keeps job startup fast on runners with limited bandwidth.
|
||||
```bash
|
||||
gitea-runner -c cache-server.yaml cache-server
|
||||
```
|
||||
|
||||
On each runner:
|
||||
|
||||
```yaml
|
||||
cache:
|
||||
external_server: "http://cache-host:8088/"
|
||||
external_secret_file: /run/secrets/cache-secret
|
||||
```
|
||||
|
||||
Jobs send cache requests to their runner, which forwards them to the shared cache server. Only the runners need to reach the shared cache server. Set `external_secret` to supply the secret inline instead of from a file.
|
||||
|
||||
Runners can also share a `cache.dir` directory on a filesystem that supports file locks. This makes cache requests slower.
|
||||
|
||||
## S3-compatible storage
|
||||
|
||||
Use an S3-compatible bucket such as AWS S3, MinIO or RustFS to share the cache without a separate cache server:
|
||||
|
||||
```yaml
|
||||
cache:
|
||||
s3:
|
||||
endpoint: "http://minio:9000"
|
||||
bucket: "runner-cache"
|
||||
access_key_file: "/run/secrets/cache-s3-access-key"
|
||||
secret_key_file: "/run/secrets/cache-s3-secret-key"
|
||||
```
|
||||
|
||||
Runners with the same settings share the cache. An entry saved on one runner becomes available to the others within 30 seconds. The eviction settings below do not apply to the bucket. Add lifecycle rules to expire old entries and abort incomplete multipart uploads.
|
||||
|
||||
## Eviction
|
||||
|
||||
| Option | Default | Removes |
|
||||
| --- | --- | --- |
|
||||
| `cache.retention` | `168h` | Entries not read or written within this time |
|
||||
| `cache.repo_size_limit` | `10GB` | Least recently used entries when a repository's cache exceeds this size |
|
||||
| `cache.size_limit` | off | Least recently used entries when the whole cache exceeds this size |
|
||||
|
||||
The cache also keeps 1024 MiB free on its volume, or `health_check.min_free_disk_space_mb` when [health checks](monitoring.md#health-checks) are enabled. With a shared cache server, set these options on the server.
|
||||
|
||||
## Artifacts
|
||||
|
||||
The runner adapts `actions/cache`, `actions/upload-artifact` and `actions/download-artifact` while a job runs so these actions work with Gitea. With these changes, the cache uses the cache service v2 protocol.
|
||||
|
||||
Artifact uploads go through the runner's cache server, so jobs must be able to reach it. Set `cache.v2: false` to send artifact uploads directly to Gitea. Set `runner.patch_actions: false` to run every action exactly as published. This uses the cache service v1 protocol and causes the published artifact actions to fail.
|
||||
|
||||
## Jobs cannot reach the cache
|
||||
|
||||
If `actions/cache` fails with `connect ETIMEDOUT`, jobs cannot reach the runner's cache server.
|
||||
|
||||
A runner container connects itself to each job network when it uses the same Docker daemon as its jobs. For jobs on another Docker daemon, for example through a remote `DOCKER_HOST`, set `cache.host` and `cache.port` to an address and port the jobs can reach. Jobs using `container.network: bridge` cannot reach a runner container outside that network. Leave `container.network` empty or use a network that includes the runner container.
|
||||
|
||||
## Action cache
|
||||
|
||||
For each job, the runner checks action tags and branches for updates, so it picks up moved tags such as `v6`. With `cache.offline_mode: true`, the runner reuses its downloaded copy. This speeds up jobs on slow networks, but moved tags and updated branches stay at the cached commit.
|
||||
Reference in new issue
Block a user