Cirry's Blog

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

Dec 27, 2024
docker docker
4分钟
682字

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

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

搭建gitea-runner

官方默认docker-compose.yml
services:
runner:
image: gitea/act_runner:0.2.11
environment:
CONFIG_FILE: /config.yaml # 配置文件位置
GITEA_INSTANCE_URL: "${INSTANCE_URL}" # gitea实例的地址
GITEA_RUNNER_REGISTRATION_TOKEN: "${REGISTRATION_TOKEN}" # 注册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

获取注册令牌

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
# Example configuration file, it's safe to copy this as the default config file without any modification.
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: 1
# Extra environment variables to run jobs.
envs:
A_TEST_ENV_NAME_1: a_test_env_value_1
A_TEST_ENV_NAME_2: a_test_env_value_2
40 collapsed lines
# 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
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: 0.0.0.0
# The port of the cache server.
# 0 means to use a random available port.
port: 8088
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: ""
# 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:

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

docker-compose.yml
services:
runner:
image: gitea/act_runner:0.2.11
environment:
CONFIG_FILE: /config.yaml
GITEA_INSTANCE_URL: https://gitea.cirry.cn # gitea实例的地址
GITEA_RUNNER_REGISTRATION_TOKEN: n9avKdN11dTb6qiO9oHx5WHKg9yQ8igXopeKA9vz # 注册token
# GITEA_RUNNER_NAME: "${RUNNER_NAME}"
# GITEA_RUNNER_LABELS: "${RUNNER_LABELS}"
ports:
- "8088:8088"
volumes:
- ./config.yaml:/config.yaml
- ./data:/data
- /var/run/docker.sock:/var/run/docker.sock

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

default

使用Actions

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

本文标题:Gitea启用Actions自动打包部署博客应用
文章作者:Cirry
发布时间:Dec 27, 2024
感谢大佬送来的咖啡☕
alipayQRCode
wechatQRCode
总访问量
总访客数人次