docs: rewrite Gitea Actions cache tutorial and adapt for localized usage
Revised and translated the guide for enabling Gitea Actions cache to streamline CI/CD workflows. Added localized examples, clarified tool and action caching configurations, and linked relevant resources for improved usability. Removed redundant sections and updated structure for better readability.
This commit is contained in:
parent
5ab0c9524e
commit
4c0ff6008d
|
|
@ -2,200 +2,173 @@
|
|||
type: Guide
|
||||
status: ACTIVE
|
||||
owner: DevOps Engineer
|
||||
source: https://about.gitea.com/resources/tutorials/enable-gitea-actions-cache-to-accelerate-cicd/
|
||||
author: Nanguan Lin
|
||||
date: 2023-10-26
|
||||
---
|
||||
# Enable Gitea Actions Cache to Accelerate CI/CD
|
||||
|
||||
[Gitea](/)
|
||||
# Gitea Actions Cache aktivieren und CI/CD beschleunigen
|
||||
|
||||
Open the main menu
|
||||
> **Quelle:** [Gitea Tutorial](https://about.gitea.com/resources/tutorials/enable-gitea-actions-cache-to-accelerate-cicd/) — übersetzt und für dieses Projekt adaptiert.
|
||||
|
||||
Products
|
||||
## Einleitung
|
||||
|
||||
[Gitea Cloud](/products/cloud/)
|
||||
Caching ist ein wesentlicher Bestandteil moderner Softwareentwicklung. In diesem Dokument wird erläutert, wie der Gitea Actions Cache (Giteas integriertes CI/CD-System) aktiviert wird, um Build-Zeiten zu reduzieren.
|
||||
|
||||
Get a DevOps instance in minutes
|
||||
Gitea Actions nutzt zwei Arten von Caches:
|
||||
|
||||
[Gitea Enterprise](/products/gitea-enterprise/)
|
||||
1. **Runner Tool Cache** — wird beim Start eines Runners angelegt. Der Runner erstellt ein Volume namens `act-toolcache`, das ins lokale Dateisystem eingehängt wird (standardmäßig `/opt/hostedtoolcache`). Wenn eine Action wie `setup-go` verwendet wird, lädt sie eine Go-Version herunter und speichert sie in diesem Volume — dadurch werden redundante Downloads verhindert.
|
||||
|
||||
Run an enhanced DevOps instance yourself
|
||||
2. **Action Cache (`actions/cache`)** — feingranularer Cache, der aus GitHub Actions stammt, aber vollständig mit Gitea Actions kompatibel ist. Er verwendet einen Hash-Schlüssel zum Abrufen eines spezifischen Caches. Details zur Konfiguration: [GitHub Offizielle Dokumentation](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows).
|
||||
|
||||
[Gitea](/products/gitea/)
|
||||
---
|
||||
|
||||
Run a free DevOps instance yourself
|
||||
## Runner Tool Cache verwenden
|
||||
|
||||
[Gitea Actions](/products/runner/)
|
||||
Die Einrichtung ist unkompliziert: Die Umgebungsvariable `RUNNER_TOOL_CACHE` im Workflow setzen — der Act Runner erkennt diese automatisch und speichert den Download-Cache dort.
|
||||
|
||||
Automate your Gitea workflows
|
||||
> **Hinweis:** `/toolcache` ist im Upstream-Projekt `nektos/act` [hardcodiert](https://github.com/nektos/act/blob/4fae81efe4cdd9e09e7ef8e874a2d63b1ed98524/pkg/runner/run_context.go#L137-L139) und kann nicht geändert werden.
|
||||
|
||||
[Tea](/products/tea/)
|
||||
**Beispiel-Konfiguration:**
|
||||
|
||||
Command line tool to interact with Gitea Servers
|
||||
```yaml
|
||||
jobs:
|
||||
build:
|
||||
env:
|
||||
RUNNER_TOOL_CACHE: /toolcache
|
||||
# ...
|
||||
```
|
||||
|
||||
Resources
|
||||
Alternativ kann ein **Docker Volume** explizit gemountet werden:
|
||||
|
||||
[News](/news)
|
||||
```yaml
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: dein_docker_image
|
||||
volumes:
|
||||
- dein_docker_volume:/opt/hostedtoolcache # Standard-Cache-Pfad des Runners
|
||||
```
|
||||
|
||||
Vergleich der Download-Zeiten:
|
||||
|
||||
- Vor dem Cache: 
|
||||
- Nach dem Cache: 
|
||||
|
||||
What happened around CommitGo and Gitea
|
||||
---
|
||||
|
||||
## Cache Action verwenden
|
||||
|
||||
[Documentations](https://docs.gitea.com)
|
||||
Der Runner verwendet einen Cache-Server zum Speichern von Schlüssel/Wert-Paaren. Dieser ist standardmäßig aktiviert — `actions/cache` kann direkt genutzt werden.
|
||||
|
||||
Documentation for Gitea and related tools
|
||||
**Beispiel-Konfiguration:**
|
||||
|
||||
[Tutorials](/resources/tutorials/)
|
||||
```yaml
|
||||
name: Caching mit Go
|
||||
on: push
|
||||
jobs:
|
||||
Cache-Go:
|
||||
name: Cache Go
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: '>=1.20.1'
|
||||
- uses: https://gitea.com/actions/go-hashfiles@v0.0.1
|
||||
id: hash-go
|
||||
with:
|
||||
patterns: |
|
||||
go.mod
|
||||
go.sum
|
||||
- name: Go Cache
|
||||
id: cache-go
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: |
|
||||
/dein_cache_pfad
|
||||
key: go_path-${{ steps.hash-go.outputs.hash }}
|
||||
restore-keys: |-
|
||||
go_cache-${{ steps.hash-go.outputs.hash }}
|
||||
```
|
||||
|
||||
Tutorals and advice on using Gitea
|
||||
Hier wird `go-hashfiles` verwendet, um einen Hash aus `go.mod` und `go.sum` zu erzeugen. Der Cache-Pfad und Schlüssel sind je nach Programmiersprache anzupassen.
|
||||
|
||||
[Blog](/blog)
|
||||
> **Wichtige Hinweise:**
|
||||
>
|
||||
> 1. Bei Verwendung des Runners mit Docker kann es zu Netzwerkproblemen mit dem Cache-Server kommen. In diesem Fall muss `host` und `port` des Cache-Servers in der `config.yaml` des Act Runners angepasst werden. Details: [Gitea Dokumentation](https://docs.gitea.com/usage/actions/act-runner#configuring-cache-when-starting-a-runner-using-docker-image)
|
||||
> 2. Die eingebaute Funktion `hashFiles` im Workflow-YAML wird in Gitea Actions aktuell **nicht** unterstützt. Als Alternative: [`go-hashfiles`](https://gitea.com/actions/go-hashfiles) (gepflegt von den Gitea-Maintainern).
|
||||
|
||||
Release notes and updates about Gitea Products
|
||||
---
|
||||
|
||||
Community
|
||||
## Vollständiges Beispiel
|
||||
|
||||
[Forum](https://forum.gitea.com)
|
||||
Annahme: Es wird eine App namens `Hello-Gitea` mit Go gebaut, mit aktiviertem Gitea Actions Workflow für jeden Push.
|
||||
|
||||
Find or help out with community support
|
||||
Workflow-Datei (auch verfügbar [auf Gitea](https://gitea.com/lng2020/cache_example/src/branch/main/.gitea/workflows/cache.yaml)):
|
||||
|
||||
[Chatroom](https://discord.gg/gitea)
|
||||
|
||||
Chat with the community
|
||||
|
||||
[Open Source](https://github.com/go-gitea/gitea)
|
||||
|
||||
View Gitea code and contribute development
|
||||
|
||||
[Community Blog](https://blog.gitea.com)
|
||||
|
||||
Release notes and updates about Gitea
|
||||
|
||||
[Translation](https://translate.gitea.com)
|
||||
|
||||
Help translate Gitea
|
||||
|
||||
[Supporters](/community/supporters/)
|
||||
|
||||
View supporters of Gitea
|
||||
|
||||
[Pricing](/pricing)[Cloud](https://cloud.gitea.com)
|
||||
|
||||
[Sign In](https://gitea.com/user/login) [Contact Us](/contact/contact)
|
||||
|
||||

|
||||
|
||||
# Enable Gitea Actions Cache to Accelerate CI/CD
|
||||
|
||||

|
||||
|
||||
[Nanguan Lin](https://github.com/lng2020)
|
||||
|
||||
2023-10-26
|
||||
|
||||
4 min read
|
||||
|
||||
[CI/CD](/resources/tutorials?category=cicd)
|
||||
|
||||
## Introduction
|
||||
|
||||
Caching is a vital aspect of modern computer science. Today, we will discuss enabling Gitea Actions(Gitea's built-in CI/CD) cache to speed up CI/CD.
|
||||
|
||||
Gitea Actions utilizes two types of caches. The first is the Runner Tool Cache, created when launching a runner. This runner creates a volume named `act-toolcache`, which is mounted to the local file system(usually `/opt/hostedtoolcache`). When an action like `setup-go` is used, it downloads and installs a version of Go, storing it in this special volume, thus preventing redundant downloads of dependencies.
|
||||
|
||||
The second type is more fine-grained. Originating from Github Actions but compatible with Gitea Actions, it's called `action/cache`. This action uses a hash key to retrieve the specific cache. For more specific information and detailed configuration about this action, refer to this [Github Offical Doc](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows). In this tutorial, we will enable both types of caches to accelerate CI/CD.
|
||||
|
||||
## Use Runner Tool Cache
|
||||
|
||||
The process is straightforward. Just add an `env` variable called `RUNNER_TOOL_CACHE` in your Gitea action workflow, and the Gitea act runner will automatically detect this environment and store the download cache there.
|
||||
|
||||
**Notice**: For now, `/toolcache` is [hardcoded](https://github.com/nektos/act/blob/4fae81efe4cdd9e09e7ef8e874a2d63b1ed98524/pkg/runner/run_context.go#L137-L139) in the upstream project `nektos/act`. So it cannot be changed.
|
||||
|
||||
An example configuration:
|
||||
|
||||
`jobs: build: env: RUNNER_TOOL_CACHE: /toolcache ...`
|
||||
|
||||
Alternatively, you can use `Docker Volume` to specifically mount the cache volume:
|
||||
|
||||
`jobs: build: runs-on: ubuntu-latest container: image: your_docker_image volumes: - your_docker_volumn:/opt/hostedtoolcache # this is where Runner store their cache default`
|
||||
|
||||
download time before: 
|
||||
|
||||
download time after: 
|
||||
|
||||
## Use Cache Action
|
||||
|
||||
The Runner uses a cache server to store the key/value pair cache. The cache server is enabled by default. So You can directly use the `action/cache`.
|
||||
|
||||
An example configuration:
|
||||
|
||||
`name: Caching with Go on: push jobs: Cache-Go: name: Cache Go runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-go@v3 with: go-version: '>=1.20.1' - uses: https://gitea.com/actions/go-hashfiles@v0.0.1 id: hash-go with: patterns: | go.mod go.sum - name: cache go id: cache-go uses: actions/cache@v3 with: # Specify with your cache path path: | /your_cache_path key: go_path-${{ steps.hash-go.outputs.hash }} restore-keys: |- go_cache-${{ steps.hash-go.outputs.hash }}`
|
||||
|
||||
This example utilizes a go cache and `go-hashfiles` to generate a hash. You should specify your cache path according to your programming language and define the key in any form you like.
|
||||
|
||||
**Notice**
|
||||
|
||||
1. If you are running the Runner with docker. You may encounter network issue with the cache server. You should change the cache server host and port in `config.yaml` for your Act Runner. The configuration is explained [here](https://docs.gitea.com/usage/actions/act-runner#configuring-cache-when-starting-a-runner-using-docker-image) in detail.
|
||||
2. The built-in function `hashFiles` in the workflow yaml is not supported in Gitea Actions right now. You can use [`go-hashfiles`](https://gitea.com/actions/go-hashfiles)(maintained by Gitea maintainers) or other alternatives instead.
|
||||
|
||||
## A Complete Example
|
||||
|
||||
Let's use an example to demonstrate how to utilize these two types of caches in a real development environment.
|
||||
|
||||
Assume we're going to build an app called `Hello-Gitea` using Go, and we enable the Gitea Actions workflow for every Push.
|
||||
|
||||
Here is the workflow yaml(this file is also available [on Gitea website](https://gitea.com/lng2020/cache_example/src/branch/main/.gitea/workflows/cache.yaml))
|
||||
|
||||
`name: Test Cache on: push jobs: TestCache: env: RUNNER_TOOL_CACHE: /toolcache # Runner Tool Cache name: Cache Go runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-go@v3 with: go-version: '>=1.20.1' - name: Get go-hashfiles uses: https://gitea.com/actions/go-hashfiles@v0.0.1 id: hash-go with: patterns: |- go.mod go.sum - name: Echo hash run: echo ${{ steps.hash-go.outputs.hash }} - name: Cache go id: cache-go uses: https://github.com/actions/cache@v3 # Action cache with: # specify with your GOMODCACHE and GOCACHE path: |- /root/go/pkg/mod /root/.cache/go-build key: go_cache-${{ steps.hash-go.outputs.hash }} restore-keys: |- go_cache-${{ steps.hash-go.outputs.hash }} - name: Build run: go build -v . - name: Test run: go test -v ./...`
|
||||
|
||||
After setting everything up, we can see how these caches are utilized.
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
## FAQ
|
||||
|
||||
Q: Why should I specify `RUNNER_TOOL_CACHE: /toolcache` to make the Runner Tool Cache work? It seems like it should cache the file by default
|
||||
|
||||
A: It's an upstream issue of `nektos/act`. See the [issue](https://gitea.com/gitea/act_runner/issues/70) for more details.
|
||||
|
||||
Q: Can different act runners on the same host share the Runner Tool Cache?
|
||||
|
||||
A: Yes, they can. To do so, use a Docker volume to map the cache directory.
|
||||
|
||||
## Footer
|
||||
|
||||

|
||||
|
||||
Private, Fast, Reliable DevOps Platform
|
||||
|
||||
[LinkedIn](https://linkedin.com/company/commitgo)[X](https://twitter.com/giteaio)[GitHub](https://github.com/go-gitea/gitea)[Gitea](https://gitea.com/gitea)
|
||||
|
||||
© 2026 CommitGo, Inc. All rights reserved.
|
||||
|
||||
### Products
|
||||
|
||||
* [Gitea Cloud](/products/cloud)
|
||||
* [Gitea Enterprise](/products/gitea-enterprise)
|
||||
* [Gitea](/products/gitea)
|
||||
* [Gitea Runner](/products/runner)
|
||||
* [Tea Command-line Tool](/products/tea)
|
||||
|
||||
### Support
|
||||
|
||||
* [Pricing](/pricing/)
|
||||
* [Documentation](https://docs.gitea.com)
|
||||
* [Tutorials](/resources/tutorials/)
|
||||
* [API](https://docs.gitea.com/api/1.21/)
|
||||
* [Blog](https://blog.gitea.com)
|
||||
* [Forum](https://forum.gitea.com)
|
||||
* [Chatroom](https://discord.gg/gitea)
|
||||
|
||||
### About Us
|
||||
|
||||
* [What is DevOps](/about/devops)
|
||||
* [Why Gitea](/about/whygitea)
|
||||
* [Contact Us](/contact/contact)
|
||||
* [Compliance](/about/compliance)
|
||||
|
||||
### Legal
|
||||
|
||||
* [Privacy](/privacy-policy/)
|
||||
* [Terms](/terms-of-service/)
|
||||
```yaml
|
||||
name: Test Cache
|
||||
on:
|
||||
push
|
||||
jobs:
|
||||
TestCache:
|
||||
env:
|
||||
RUNNER_TOOL_CACHE: /toolcache # Runner Tool Cache
|
||||
name: Cache Go
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: '>=1.20.1'
|
||||
|
||||
- name: go-hashfiles laden
|
||||
uses: https://gitea.com/actions/go-hashfiles@v0.0.1
|
||||
id: hash-go
|
||||
with:
|
||||
patterns: |-
|
||||
go.mod
|
||||
go.sum
|
||||
|
||||
- name: Hash ausgeben
|
||||
run: echo ${{ steps.hash-go.outputs.hash }}
|
||||
|
||||
- name: Go Cache
|
||||
id: cache-go
|
||||
uses: https://github.com/actions/cache@v3 # Action Cache
|
||||
with:
|
||||
path: |-
|
||||
/root/go/pkg/mod
|
||||
/root/.cache/go-build
|
||||
key: go_cache-${{ steps.hash-go.outputs.hash }}
|
||||
restore-keys: |-
|
||||
go_cache-${{ steps.hash-go.outputs.hash }}
|
||||
|
||||
- name: Build
|
||||
run: go build -v .
|
||||
|
||||
- name: Test
|
||||
run: go test -v ./...
|
||||
```
|
||||
|
||||
Nach der Einrichtung sind beide Cache-Typen aktiv:
|
||||
|
||||
- Tool Cache: 
|
||||
- Action Cache: 
|
||||
|
||||
---
|
||||
|
||||
## Häufige Fragen (FAQ)
|
||||
|
||||
**F: Warum muss `RUNNER_TOOL_CACHE: /toolcache` explizit gesetzt werden? Sollte das nicht standardmäßig funktionieren?**
|
||||
|
||||
A: Das ist ein Upstream-Problem von `nektos/act`. Details: [Issue #70](https://gitea.com/gitea/act_runner/issues/70).
|
||||
|
||||
---
|
||||
|
||||
**F: Können mehrere Act Runner auf demselben Host den Runner Tool Cache teilen?**
|
||||
|
||||
A: Ja. Dazu ein Docker Volume verwenden und das Cache-Verzeichnis einmappen.
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user