Cirry's Blog

Gitea启用Actions自动打包部署博客应用

2024-12-27
docker docker
4分钟
682字

先上官网链接Gitea-Actions快速入门Act Runner

为了避免出现不兼容等问题,我们先升级下gitea到最新稳定版本。

搭建gitea-runner

官方默认docker-compose.yml
1
services:
2
runner:
3
image: gitea/act_runner:0.2.11
4
environment:
5
CONFIG_FILE: /config.yaml # 配置文件位置
6
GITEA_INSTANCE_URL: "${INSTANCE_URL}" # gitea实例的地址
7
GITEA_RUNNER_REGISTRATION_TOKEN: "${REGISTRATION_TOKEN}" # 注册token
8
GITEA_RUNNER_NAME: "${RUNNER_NAME}"
9
GITEA_RUNNER_LABELS: "${RUNNER_LABELS}"
10
volumes:
11
- ./config.yaml:/config.yaml
12
- ./data:/data
13
- /var/run/docker.sock:/var/run/docker.sock

获取注册令牌

Runner级别决定了从哪里获取注册令牌。

  • 实例级别:管理员设置页面,例如 <your_gitea.com>/admin/actions/runners。
  • 组织级别:组织设置页面,例如 <your_gitea.com>//settings/actions/runners。
  • 存储库级别:存储库设置页面,例如 <your_gitea.com>///settings/actions/runners。

获取注册令牌的地址方式如下,使用管理员账号登录gitea后访问上面的地址<your_gitea.com>/admin/actions/runners就可以看到了。

default

创建runner

添加容器的配置文件:

注意这个配置文档中可以启用cache功能。

config.yaml
1
# Example configuration file, it's safe to copy this as the default config file without any modification.
2
3
log:
4
# The level of logging, can be trace, debug, info, warn, error, fatal
5
level: info
6
7
runner:
8
# Where to store the registration result.
9
file: .runner
10
# Execute how many tasks concurrently at the same time.
11
capacity: 1
12
# Extra environment variables to run jobs.
13
envs:
14
A_TEST_ENV_NAME_1: a_test_env_value_1
15
A_TEST_ENV_NAME_2: a_test_env_value_2
40 collapsed lines
16
# Extra environment variables to run jobs from a file.
17
# It will be ignored if it's empty or the file doesn't exist.
18
env_file: .env
19
# The timeout for a job to be finished.
20
# Please note that the Gitea instance also has a timeout (3h by default) for the job.
21
# So the job could be stopped by the Gitea instance if it's timeout is shorter than this.
22
timeout: 3h
23
# Whether skip verifying the TLS certificate of the Gitea instance.
24
insecure: false
25
# The timeout for fetching the job from the Gitea instance.
26
fetch_timeout: 5s
27
# The interval for fetching the job from the Gitea instance.
28
fetch_interval: 2s
29
30
cache:
31
# Enable cache server to use actions/cache.
32
enabled: true
33
# The directory to store the cache data.
34
# If it's empty, the cache data will be stored in $HOME/.cache/actcache.
35
dir: ""
36
# The host of the cache server.
37
# It's not for the address to listen, but the address to connect from job containers.
38
# So 0.0.0.0 is a bad choice, leave it empty to detect automatically.
39
host: 0.0.0.0
40
# The port of the cache server.
41
# 0 means to use a random available port.
42
port: 8088
43
44
container:
45
# Specifies the network to which the container will connect.
46
# Could be host, bridge or the name of a custom network.
47
# If it's empty, act_runner will create a network automatically.
48
network: ""
49
# Whether to use privileged mode or not when launching task containers (privileged mode is required for Docker-in-Docker).
50
privileged: false
51
# And other options to be used when the container is started (eg, --add-host=my.gitea.url:host-gateway).
52
options:
53
# The parent directory of a job's working directory.
54
# If it's empty, /workspace will be used.
55
workdir_parent:

修改官方的docker-compose.yml文件:

docker-compose.yml
1
services:
2
runner:
3
image: gitea/act_runner:0.2.11
4
environment:
5
CONFIG_FILE: /config.yaml
6
GITEA_INSTANCE_URL: https://gitea.cirry.cn # gitea实例的地址
7
GITEA_RUNNER_REGISTRATION_TOKEN: n9avKdN11dTb6qiO9oHx5WHKg9yQ8igXopeKA9vz # 注册token
8
# GITEA_RUNNER_NAME: "${RUNNER_NAME}"
9
# GITEA_RUNNER_LABELS: "${RUNNER_LABELS}"
10
ports:
11
- "8088:8088"
12
volumes:
13
- ./config.yaml:/config.yaml
14
- ./data:/data
15
- /var/run/docker.sock:/var/run/docker.sock

修改上面两行高亮的参数后启动act_runner,启动完成后刷新获取注册token的runner页面,可以看到已经有一个runner创建成功了。

default

使用Actions

首先你需要在你的仓库设置中打开actions功能,参考这里:使用Actions

本文标题:Gitea启用Actions自动打包部署博客应用
文章作者:Cirry
发布时间:2024-12-27
感谢大佬送来的咖啡☕
alipayQRCode
wechatQRCode