feat: add gitea runner relavant ex.

This commit is contained in:
2025-10-22 00:36:27 +08:00
parent 0dd0772dc9
commit 150e0d3e72
2 changed files with 149 additions and 0 deletions

View File

@@ -0,0 +1,149 @@
# 配置gitea的action用来执行ci操作
虽然gitea的ci写起来真的真的没有gitlab的好写
但是我还是像eat shit 一样找到了一条解决方法
因为gitea社区对其在k8s中的部署文档支持真的很差
总之终于是补齐了自己对于gitea部署的一块重要拼图
### 运行逻辑
我个人对gitea的action的理解逻辑是这样的
ci配置-->runner-->job
三个基础流程,每一层都有着对应的配置,接下来我将分享我是怎么做的,以及常见的问题
### 第一步注册runner到gitea
我使用的是gitea官方1.24.6的chart包安装的
根据我的研究runner需要自己另外使用deployment或者一个完整的chart我这里直接使用deployment实现
使用官方的镜像 gitea/act_runner:latest 作为pod运行的基础镜像
此时需要通过deployment的环境变量传递四个关键参数
**GITEA_INSTANCE_URL** #gitea的远程地址,就是自己访问的域名;
**GITEA_RUNNER_REGISTRATION_TOKEN** #gitea注册runner时需要的域名分为三种等级项目、组织或个人、全局分别对应着仓库、组织或个人、管理员的设置的action栏目下的runner中右上角创建runner即可复制tokengitea会针对token自己创建对应的等级
**GITEA_RUNNER_NAME** #runner的名字就是直接显示在gitea上的名字
**CONFIG_FILE** #runner的配置文件,用来处理接下来会提到的一个网络配置
我们要修改[config_file示例](./attachments/gitea_act-runner_config-template.yaml)中container的network字段为host或者其他自己的网络否则runner创建的container将无法连接到任何服务
使用configmap预先包装到同一命名空间做好准备例如这样
(labels建议换成相对规范的格式,可以有多个)
```
apiVersion: v1
kind: ConfigMap
metadata:
name: gitea-act-runner-config
namespace: gitea-actions
data:
config.yaml: |
log:
level: info
runner:
name: rke2-runner-1
labels:
- "gitea-official-runner:docker"
capacity: 2
timeout: 1h
container:
network: host
cache:
enabled: true
dir: /data/cache
```
然后编写deployment像这样
```
apiVersion: apps/v1
kind: Deployment
metadata:
name: gitea-runner
namespace: gitea-actions
spec:
replicas: 1
selector:
matchLabels:
app: gitea-runner
template:
metadata:
labels:
app: gitea-runner
spec:
containers:
- name: runner
securityContext:
privileged: true
image: gitea/act_runner:latest
args:
- "daemon"
env:
- name: CONFIG_FILE
value: /data/config.yaml
- name: GITEA_INSTANCE_URL
value: "https://gitea.example.com"
- name: GITEA_RUNNER_REGISTRATION_TOKEN
value: ""
- name: GITEA_RUNNER_NAME
value: "runner"
volumeMounts:
- name: runner-data
mountPath: /data
- name: runner-config
mountPath: /data/config.yaml
subPath: config.yaml
- mountPath: /var/run/docker.sock
name: docker-socket
- mountPath: /root/.docker/config.json
name: docker-token
volumes:
- name: runner-data
emptyDir: {}
- name: runner-config
configMap:
name: gitea-act-runner-config
- name: docker-socket
hostPath:
path: /var/run/docker.sock
- name: docker-token
hostPath:
path: /root/.docker/config.json
```
解释一下为什么要挂在docker-socket和docker-token
主要是为了使用拉取镜像的功能这里不得不提一下action是怎么运行的了
**运行逻辑**
runner使用的镜像只是一个守护进程可以理解为用来和gitea保持联系的进程后面使用的镜像才是重头戏所以runner就必须要使用到docker的套接字去使用docker pull命令
因为官方act_runner镜像自己没有带docker所以我这里使用的是宿主机的docker.sock当然你也可以指定一个DinD的镜像比如把act_runner替换成vegardit/gitea-act-runner:dind-latest
注意如果你的集群有严格的安全限制那么应该只能使用DinD镜像因为官方镜像需要访问宿主机的sock需要privileged权限
如果要从私有仓库拉取镜像就还需要加上config.json里面保存着登录凭证可以直接供拉取镜像时使用我这边因为用的就是宿主机的docker所以顺便也用宿主机的认证了
至此runner注册完成应该可以在管理面板查看存在的runner
### 第二部编写workflow