似乎可以在 Github-Gitea 上兼容地运行 Actions

5 min

language: ja bn en es hi pt ru zh-cn zh-tw

大家好,我是无能君。

我所做的主要是引入 Gitea Actions。

配置 Gitea Actions 的运行环境

我所做的与以下内容基本相同,但

Gitea Actions 来了!

顺便说一句,即使不在app.ini中将[actions]设置为ENABLED=true,它似乎也默认是开启的。

引入时的版本

$ gitea -v
Gitea version 1.22.4 built with GNU Make 4.3, go1.22.9 : bindata, sqlite, sqlite_unlock_notify

由于在 Hetzner 上的 Debian 中通过apt安装的Go版本过旧,导致构建时报错,因此我将安装最新版本的Go

wget https://go.dev/dl/go1.23.4.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.23.4.linux-amd64.tar.gz
exec bash
go version

此时,虽然已经apt remove了,但它仍然指向/usr/bin/go,而且我忘记传递路径,所以重新设置了路径。

echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc
rm /usr/bin/go
exec bash
go version

构建 Gitea Actions 的 runner

它需要作为单独的守护进程运行,并且还需要docker,所以我们来安装它。

apt install -y make docker.io
service docker status

git clone https://gitea.com/gitea/act_runner
cd act_runner/
make build
mv ./act_runner /usr/local/bin
exec bash

通过 act_runner register 进行绑定

我大概在此时明白了为什么它要与Gitea主体的二进制文件分开。

我想这可能是为了方便将运行Gitea Actions的环境与托管Gitea本身的服务器分开。

# act_runner register
INFO Registering runner, arch=amd64, os=linux, version=v0.2.11+6-g8bc0275. 
INFO Enter the Gitea instance URL (for example, https://gitea.com/): 
https://git.domain.tld/ 
INFO Enter the runner token:                      
Secret key
INFO Enter the runner name (if set empty, use hostname: debian-2gb-hel1-1): 
danzig
INFO Enter the runner labels, leave blank to use the default labels (comma-separated, for example, ubuntu-latest:docker://gitea/runner-images:ubuntu-latest): 

INFO Registering runner, name=danzig, instance=https://git.domain.tld/, labels=[ubuntu-latest:docker://gitea/runner-images:ubuntu-latest ubuntu-22.04:docker://gitea/runner-images:ubuntu-22.04 ubuntu-20.04:docker://gitea/runner-images:ubuntu-20.04]. 
DEBU Successfully pinged the Gitea instance server 
INFO Runner registered successfully.              

顺便说一句,获取传递给 Runner 的令牌的方式与前面提到的网站不同,现在是

https://git.domain.tld/admin/actions/runners

了。

虽然有点无聊,但我将 runner name 设置为 danzig,这是 Misfits 乐队主唱的名字。

想象一下 Glenn Danzig 在后台进行构建工作,这很有趣。

似乎需要安装 apparmor

看来缺少必要的模块。

似乎需要SE Linux之外的Linux Security Modules

Image

所以我们来安装它。

apt install -y apparmor apparmor-utils

那么,关于act_runner守护进程的执行二进制文件该怎么办呢?我暂时将其放入rc.local中,只进行启动,作为测试期间的方案。

原因是,如果一开始就将其放入SystemdSupervisord中,当守护进程中途死亡时,检查起来可能会很麻烦。所以,如果它能干净地死亡,之后只需查看nohup.out中的守护进程死亡日志即可,这样更容易找到问题。

将以下内容写入/etc/rc.local

nohup act_runner daemon &

然后重启Docker守护进程。

service docker restart

顺便说一句,我很少使用systemctl的原因是service更通用,可以在其他发行版和 BSD 环境中同样使用。

编辑 yaml

说实话,我不太明白为什么actions/checkout@v4在没有明确指定的情况下也能运行,但查看日志后发现,act_runner似乎巧妙地对其进行了修正,使其能够理解这种语法。

Image

因此,它似乎使用的是 GitHub 上的资产,而不是act_runner端持有的actions/checkout@v4的某种镜像资产。

# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Go

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

jobs:

  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4

    - name: Set up Go
      uses: actions/setup-go@v4
      with:
        go-version: '1.23.3'

    - name: Build
      run: go build -v ./...

    - name: Test
      run: go test -v ./...

在 Qiita 的文章中,除了actions/checkout@v4之外,其他地方都需要明确指定完整的 URL,所以我为name: Set up Gouses指定了完整的 URL。但如果按照前面所说,现在版本已经升级了,也许它能巧妙地识别为 GitHub 资产?

我这样想了,但如果那样做,可能会与Gitea上的资产发生冲突,所以指定完整的 URL 似乎更不容易出问题。

※追记

看来即使是owner/repo@ref的形式,Github 和 Gitea 都能通过,所以可以不用多想了。

成功运行

Image

成功了!!!!

那么,这次就到这里。

下次再见。