简介
Gitea 1.19.0 引入了一个名为 Gitea Actions 的新功能,这是 Gitea 的内置CI系统,类似并兼容于 GitHub Actions。
开启
默认gitea action是不被开启的,如果想要启用 Actions,需要在配置文件中添加
[actions]
ENABLED=true
配置runner
runner推荐直接运行在宿主机中,我的做法是专门创建一个虚拟机去运行它,而且这台机器需要安装nodejs还有docker,不然是不能使用action的
具体的安装方法可以参考下面
https://gitea.com/gitea/act_runner
从下面地址下载你系统架构的runner
https://dl.gitea.com/act_runner/main/
并且使用下面命令注册到gitea
./act_runner register
你需要输入gitea的地址,runner的tag,还有注册到gitea的token,token可以从your_gitea.com/admin/runners
获取
注册完成之后当前的目录中会出现.runner
这个文件,这个文件保存了注册相关的信息
最后你可以运行这个runner
nohup ./act_runner daemon &
安装docker
如果你和我一样是使用alma linux的,你可以直接使用下面方法安装docker
sudo dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
sudo dnf update
sudo dnf install docker-ce docker-ce-cli containerd.io
如果是其他的系统,可以试试docker的官方安装脚本
curl get.docker.com
安装nodejs
默认yum源里面的nodejs还是比较老的,下面的方法可以直接安装最新版本的nodejs
dnf module reset nodejs
看下最新版本的nodejs
dnf module list nodejs
安装最新版本的nodejs
dnf module install nodejs:18
使用action
虽然在gitea的配置文件中启用了action,但是action在repo中默认是禁用的,你需要在仓库的设置页面中启用action才可以使用
和github action一样,对于gitea action,你需要在.gitea/workflows/
这个目录下创建对应的yaml去定义你所需要运行的pipeline,下面是一个编译docker image的案例
.gitea/workflows/build.yaml
name: ci
on:
push:
branches:
- 'master'
jobs:
docker:
runs-on: docker
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
registry: ${{ secrets.DOCKERHUB_URL }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v4
with:
push: true
tags: |
reg.xxx.com/bboysoul/xxx:latest
reg.xxx.com/bboysoul/xxx:${{ github.sha }}
# dingtalk alert
- name: dingtalk alert success
uses: bboysoul/dingding-alert-action@main
if: ${{ success() }}
env:
DING_SECRET: ${{ secrets.DING_SECRET }}
DING_BASE_URL: ${{ secrets.DING_BASE_URL }}
TITLE: "镜像编译"
MSG: "镜像编译成功"
- name: dingtalk alert failed
uses: bboysoul/dingding-alert-action@main
if: ${{ failure() }}
env:
DING_SECRET: ${{ secrets.DING_SECRET }}
DING_BASE_URL: ${{ secrets.DING_BASE_URL }}
TITLE: "镜像编译"
MSG: "镜像编译失败"
可以看到的是,如果你之前一直使用的是github action那么几乎可以不用修改扔河东西就可以迁移到gitea action
但是gitea action中
uses: bboysoul/dingding-alert-action@main
默认是从https://gitea.com/bboysoul/dingding-alert-action
去拉取而不是https://github.com/bboysoul/dingding-alert-action
如果你想使用github上的action,那么要写全地址
uses: https://github.com/bboysoulcn/dingding-alert-action
runs-on: docker
这个里面的docker就是runner的标签
gitea action是可以使用${{ github.sha }}
作为变量的,但是同时也可以使用${{ gitea.sha }}
对于gitea action来说推荐使用${{ gitea.sha }}
而不是${{ github.sha }}
总结
玩了许多 CICD 相关的项目,我认为最强的还是 GitHub Actions。
因此,对于自己托管的项目,没有比 Gitea Actions 更合适的了。
虽然目前 Gitea Actions 还不是特别完善,但已经可以使用了。
所以,我认为完全没有使用 GitLab 的理由了。这两天,我已经将大部分的流水线从 Drone 迁移到了 Gitea Actions。
欢迎关注我的博客www.bboy.app
Have Fun