0%

gitea actions CICD 自动化

gitea 已经支持自己的 CI 工具: gitea actions,兼容 github actions

之前使用drone搭配gitea进行自动化,效果还可以,但是终究不是官方支持。

而最新的 gitea 1.21 之后的版本,开始支持actions功能,使用方式更贴近github actions

这里做一个简单部署说明,具体的用法可以看官方文档以及github actions的用法。

效果

gitea-actions

注意事项

  1. 注意giteagitea runner之间的网络互通问题。
  2. 部署时候,需要先启动gitea,配置完成之后,拿到gitea runner注册TOKEN
  3. 如果外部端口与内部端口不一致,nginx 部分请加上对应的端口监听。
  4. 需要给gitea runner设置container network,名字查看 docker network ls
  5. gitea runner 建议设置 ENV RUNNER_TOOL_CACHE: /toolcache 方便缓存工具链。
  6. docker启动的gitea runner 不建议设置 GITEA_RUNNER_LABELS ,会导致不起作用。

将两个配置配好之后,执行启动命令,即可。

修改 gitea 配置

gitea/gitea/conf/app.ini 配置启用 actions

1
2
3
[actions]
ENABLED=true
DEFAULT_ACTIONS_URL=github

启动 GITEA 并获取runner token

执行 docker compose up -d gitea,正常配置完成之后,进去管理后台-》Actions-》Runners里面点击创建Runners获得Token,再将Token填入docker-compose.yaml对应配置项目,即可使用。
get_runner_token.png

docker-compose.yaml 配置参数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
version: "3"

services:
reverseproxy:
image: nginx:alpine
container_name: reverseproxy
restart: always
ports:
- 10080:80 # 可以选择其他的端口号
dns:
- 101.101.101.101
- 8.8.8.8
- 114.114.114.114
volumes:
- ./nginx/conf.d/:/etc/nginx/conf.d/
- ./nginx/pem/:/pem/
networks:
gitea_net:
aliases:
- 定义内部域名例如:git.example.com
depends_on:
- gitea
gitea:
image: gitea/gitea:latest
container_name: gitea
dns:
- 101.101.101.101
- 8.8.8.8
- 114.114.114.114
environment:
- APP_NAME=当前的gitea名
- RUN_MODE=prod
- ROOT_URL=外部访问的地址
#- SECRET_KEY=${GITEA_SECRET_KEY}
restart: always
networks:
- gitea_net
volumes:
- ./gitea:/data
act_runner:
image: gitea/act_runner
container_name: act_runner
dns:
- 101.101.101.101
- 8.8.8.8
- 114.114.114.114
restart: always
depends_on:
- gitea
- reverseproxy
networks:
- gitea_net
environment:
CONFIG_FILE: /config.yaml
GITEA_INSTANCE_URL: "gitea 的访问地址,也可以是内部的"
GITEA_RUNNER_REGISTRATION_TOKEN: "从启动的 Gitea 里面拿"
GITEA_RUNNER_NAME: "act_runner"
# runs-on 的标签实际上是下面这个,上面的只是名字
# GITEA_RUNNER_LABELS: "ubuntu-latest"
volumes:
- ./act_runner/config.yaml:/config.yaml
- ./act_runner/data:/data
- ./act_runner/cache:/root/.cache
- /var/run/docker.sock:/var/run/docker.sock
networks:
gitea_net:

gitea runner.conf 配置

路径:act_runner/config.yaml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# 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.

log:
# The level of logging, can be trace, debug, info, warn, error, fatal
level: info

runner:
# Where to store the registration result.
file: .runner
# Execute how many tasks concurrently at the same time.
capacity: 4
# Extra environment variables to run jobs.
envs:
RUNNER_TOOL_CACHE: /toolcache
# Extra environment variables to run jobs from a file.
# It will be ignored if it's empty or the file doesn't exist.
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.
timeout: 3h
# Whether skip verifying the TLS certificate of the Gitea instance.
insecure: false
# The timeout for fetching the job from the Gitea instance.
fetch_timeout: 5s
# The interval for fetching the job from the Gitea instance.
fetch_interval: 2s
# The labels of a runner are used to determine which jobs the runner can run, and how to run them.
# Like: ["macos-arm64:host", "ubuntu-latest:docker://node:16-bullseye", "ubuntu-22.04:docker://node:16-bullseye"]
# If it's empty when registering, it will ask for inputting labels.
# If it's empty when execute `deamon`, will use labels in `.runner` file.
labels: []

cache:
# Enable cache server to use actions/cache.
enabled: true
# The directory to store the cache data.
# If it's empty, the cache data will be stored in $HOME/.cache/actcache.
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.
host: ""
# The port of the cache server.
# 0 means to use a random available port.
port:
# 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 "/".
external_server: ""

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.
network: "实际 network 名字"
# Whether to use privileged mode or not when launching task containers (privileged mode is required for Docker-in-Docker).
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.
# If it's empty, /workspace will be used.
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:
# - '**'
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_host: ""
# Pull docker image(s) even if already present
force_pull: false

host:
# The parent directory of a job's working directory.
# If it's empty, $HOME/.cache/act/ will be used.
workdir_parent: