Gitea Runner 통한 Gitea Actions 구성하기 #2

Paul
21 min readMay 8, 2024

--

Photo by James Harrison on Unsplash

앞에서 Gitea 환경을 구성했습니다. 이번에는 Gitea Actions (Gitea 버전이 1.19.0 이상)활용해 CI/CD 파이프 라인을 구성하기 전에, Gitea Actions 작업을 실행할 Gitea Runner에 대해서 알아보겠습니다. Gitea Runner 설정에 대한 자세한 정보는 아래 GitHub 소스를 참고해 주시기 바랍니다.

Gitea Actions 이란

Gitea 는 CI/CD 구성을 위해 Gitea Actions 를 제공합니다. Gitea Actions 기능은 Gitea 1.19부터 사용 가능하며 대부분의 기능이 GitHub Actions와 호환되도록 설계되었습니다. 또한 로컬에서 GitHub 워크플로를 실행할 수 있는 act_runner 제공합니다.

Gitea Actions 설정하기

Gitea 1.21.0부터 Gitea Actions은 기본적으로 활성화됩니다. 1.21.0 이전 버전을 사용하는 경우 이를 활성화하려면, 구성 파일(app.ini)에 설정을 추가해야 합니다. Gitea Actions 의 추가 옵션에 대해서는 여기를 참고하세요.


# app.ini
[actions]
ENABLED=true
DEFAULT_ACTIONS_URL=github

Gitea Runner 구성하기(act runner)

Gitea는 CI/CD 기능을 내장하고 있지 않기 때문에 빌드, 테스트, 배포 등의 작업을 수행하기 위해서는 Gitea Runner(act runner)를 사용합니다. Gitea Runner 구성하려면 먼저 act_runner를 다운로드를 받습니다. act_runner 바이너리를 사용하여 Gitea Runner의 환경 설정 파일을 생성합니다.

./act_runner generate-config > config.yaml

Gitea Runner 실행할 Docker Compose 파일을 작성을 합니다.

version: "3"

services:
act_runner:
image: gitea/act_runner:0.2.10
container_name: act_runner
privileged: true
environment:
CONFIG_FILE: /config.yaml
GITEA_INSTANCE_URL: "https://192.168.56.173:3300"
GITEA_RUNNER_REGISTRATION_TOKEN: 50XjwfkyYFMnS2xiTuXZ8WYEB1CySlJOyWtd3L7y
GITEA_RUNNER_NAME: "act_runner"
#GITEA_RUNNER_LABELS: ubuntu-latest:docker
volumes:
- ~/act-runner/data:/data
- ~/act-runner/cache:/root/.cache
- ./config.yaml:/config.yaml
- /var/run/docker.sock:/var/run/docker.sock
  • GITEA_INSTANCE_URL : Gitea 호스트 서버의 정보를 입력합니다.
  • GITEA_RUNNER_REGISTRATION_TOKEN : Gitea Runner에 등록할 Token 정보는 Gitea 서버의 설정> Actions 항목에서 Runners 선택 > Create new Runner 선택하면 Token 값을 얻을 수 있습니다.
  • GITEA_RUNNER_NAME : Gitea Runner 이름을 설정합니다.
  • GITEA_RUNNER_LABELS : 레이블 사용하여 CI/CD 파이프 라인에서 빌드 단계를 수행할 도커 컨테이너 설정을 할 수 있습니다. 또한 config.yaml 파일에서 LABELS 값으로도 설정을 할 수 있습니다.
# config.yaml 파일 
# The labels of a runner are used to determine which jobs the runner can run, and how to run them.
# Like: "macos-arm64:host" or "ubuntu-latest:docker://gitea/runner-images:ubuntu-latest"
# Find more images provided by Gitea at https://gitea.com/gitea/runner-images .
# If it's empty when registering, it will ask for inputting labels.
# If it's empty when execute `daemon`, will use labels in `.runner` file.
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"

Gitea Runner를 가상 환경에서 실행해 보도록 하겠습니다.

vagrant@gitea:~$ cd /vagrant/docker/gitea-runner/
vagrant@gitea:/vagrant/docker/gitea-runner$ ls
certs config.yaml docker-compose.yaml
vagrant@gitea:/vagrant/docker/gitea-runner$ ls -al
total 12
drwxrwxrwx 1 vagrant vagrant 0 Apr 27 15:59 .
drwxrwxrwx 1 vagrant vagrant 0 Apr 27 15:58 ..
drwxrwxrwx 1 vagrant vagrant 0 Apr 27 15:59 certs
-rwxrwxrwx 1 vagrant vagrant 4887 Apr 20 01:13 config.yaml
-rwxrwxrwx 1 vagrant vagrant 639 Apr 27 16:16 docker-compose.yaml
vagrant@gitea:/vagrant/docker/gitea-runner$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
50b8f735dd2f gitea/gitea:1.21.10 "/usr/bin/entrypoint…" 9 hours ago Up 9 hours 3000/tcp, 0.0.0.0:3300->3300/tcp, :::3300->3300/tcp, 0.0.0.0:222->22/tcp, :::222->22/tcp gitea
vagrant@gitea:/vagrant/docker/gitea-runner$
vagrant@gitea:/vagrant/docker/gitea-runner$
vagrant@gitea:/vagrant/docker/gitea-runner$ ls
certs config.yaml docker-compose.yaml
vagrant@gitea:/vagrant/docker/gitea-runner$ docker-compose up -d
[+] Running 5/5
⠿ act_runner Pulled 7.5s
⠿ 619be1103602 Already exists 0.0s
⠿ 0af10301d634 Pull complete 3.0s
⠿ b08f35e7c291 Pull complete 3.9s
⠿ 51b7b011c8e3 Pull complete 4.0s
[+] Running 2/2
⠿ Network gitea-runner_default Created 0.2s
⠿ Container act_runner Started 1.2s
vagrant@gitea:/vagrant/docker/gitea-runner$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f0f0c1372a6f gitea/act_runner:0.2.10 "/sbin/tini -- /opt/…" 20 seconds ago Up 19 seconds
act_runner
50b8f735dd2f gitea/gitea:1.21.10 "/usr/bin/entrypoint…" 9 hours ago Up 9 hours 3000/tcp, 0.0.0.0:3300->3300/tcp, :::3300->3300/tcp, 0.0.0.0:222->22/tcp, :::222->22/tcp gitea
vagrant@gitea:/vagrant/docker/gitea-runner$ docker logs -f f0
.runner is missing or not a regular file
level=info msg="Registering runner, arch=amd64, os=linux, version=v0.2.10."
level=debug msg="Successfully pinged the Gitea instance server"
level=info msg="Runner registered successfully."
SUCCESS
time="2024-04-28T00:13:39Z" level=info msg="Starting runner daemon"
time="2024-04-28T00:13:39Z" level=info msg="runner: act_runner, with version: v0.2.10, with labels: [ubuntu-latest ubuntu-22.04 ubuntu-20.04], declare successfully"

Gitea Runner Docker 컨테이너를 실행한 후 로그를 통해 정상적으로 작동하는지 확인할 수 있습니다. 실행 중 에러가 발생하지 않았다면, 아래와 같이 Gitea 서버에 Runner가 성공적으로 등록되었음을 확인할 수 있습니다.

Gita Actions 데모 실행하기

Gitea Actions 테스트를 위해 새로운 저장소를 생성합니다.

저장소 생성된 후에 설정에서 Actions 활성화 체크 후 저장을 합니다.

저장소 설정 화면에 Actions 탭이 활성화가 됩니다.

신규 저장소를 생성할 때마다 Actions을 설정하는 것은 매우 번거로울 수 있습니다. 이를 간소화하기 위해, Gitea 서버의 환경 설정 파일(app.ini)에 DEFAULT_REPO_UNITS 설정을 추가하여, 신규 저장소가 생성될 때마다 Actions이 기본적으로 설정되도록 했습니다.

DEFAULT_REPO_UNITS 설정은 Gitea에서 저장소를 생성할 때 기본적으로 활성화되는 기능 단위(Units)를 정의합니다. 각 Unit은 저장소의 특정 기능을 나타냅니다. 예를 들어, 이슈 추적, 위키, 풀 리퀘스트 등이 각각 별도의 Unit으로 관리됩니다.(https://docs.gitea.com/usage/actions/faq#is-it-possible-to-enable-actions-for-new-repositories-by-default-for-my-own-instance, https://docs.gitea.com/administration/config-cheat-sheet)

# app.ini
APP_NAME = Gitea: Git with a cup of tea
RUN_MODE = prod
RUN_USER = git
WORK_PATH = /data/gitea

[repository]
ROOT = /data/git/repositories
DEFAULT_REPO_UNITS = repo.actions,repo.code,repo.issues,repo.ext_wiki,repo.forks,repo.releases,repo.projects,repo.wiki

Gitea Actions 데모를 위해 저장소에 .gitea/workflows/demo.yaml 파일을 생성하고, 아래와 같이 내용을 작성합니다.

name: Gitea Actions Demo
run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀
on: [push]

jobs:
Explore-Gitea-Actions:
runs-on: ubuntu-latest
steps:
- run: echo "🎉 The job was automatically triggered by a ${{ gitea.event_name }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by Gitea!"
- run: echo "🔎 The name of your branch is ${{ gitea.ref }} and your repository is ${{ gitea.repository }}."
- name: Check out repository code
uses: actions/checkout@v3
- run: echo "💡 The ${{ gitea.repository }} repository has been cloned to the runner."
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
- name: List files in the repository
run: |
ls ${{ gitea.workspace }}
- run: echo "🍏 This job's status is ${{ job.status }}."

.gitea/workflows/demo.yaml 파일을 저장소에 git push를 하면 아래와 같이 Actions 탭을 선택 하시면 Gitea Actions 실행 되는 화면을 확인 할 수 있습니다.

Actions에서 에러가 발생을 하는 것을 확인 할 수 있습니다.

Waiting 16 seconds before trying again
[command]/usr/bin/git -c protocol.version=2 fetch --no-tags --prune --progress --no-recurse-submodules --depth=1 origin +222c071616690d33ac36da1805eb9674ccce928a:refs/remotes/origin/master
fatal: unable to access 'https://192.168.56.173:3300/gitea/gitea-actions-repo/':
server certificate verification failed. CAfile: none CRLfile: none
::remove-matcher owner=checkout-git::
::error::The process '/usr/bin/git' failed with exit code 128

서버 인증서 확인 실패로 인해 ‘server certificate verification failed. CAfile: none CRLfile: none’ 오류가 발생했습니다. 이는 Gitea 서버의 HTTPS 설정에 사용된 사설 인증서 때문입니다. 이 문제를 해결하기 위해 Job에서 사용할 도커 컨테이너를 생성한 후에 LABLES 설정을 변경해 보도록 하겠습니다.

Gitea Runner 위한 Lables 컨테이너 생성하기

Gitea Actions에서 Job은 Gitea Runner에 설정된 Labels를 가진 컨테이너 이미지를 사용합니다.

# Gitea Runner config.yaml 파일
# The labels of a runner are used to determine which jobs the runner can run, and how to run them.
# Like: "macos-arm64:host" or "ubuntu-latest:docker://gitea/runner-images:ubuntu-latest"
# Find more images provided by Gitea at https://gitea.com/gitea/runner-images .
# If it's empty when registering, it will ask for inputting labels.
# If it's empty when execute `daemon`, will use labels in `.runner` file.
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"


# Gitea Action demo.yaml 파일
name: Gitea Actions Demo
run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀
on: [push]

jobs:
Explore-Gitea-Actions:
# Job이 실행할 컨테이너 이미지 Gitea Runner 설정파일에 있는
# labels 정보임. Docker Hub의 gitea/runner-images:ubuntu-latest 사용함.
runs-on: ubuntu-latest

사용자 정의 컨테이너 이미지를 생성한 후에 Docker Hub에 업로드를 하겠습니다. 기본 이미지는 gitea/runner-images:ubuntu-20.04 사용합니다. 또한 Gitea 서버에서 생성한 cert.pem 파일을 /etc/ssl/certs 폴더에 복사해서, git clone 시 server certificate verification failed. CAfile: none CRLfile: none 오류가 발생하지 않도록 했습니다.

# Dockerfile
FROM gitea/runner-images:ubuntu-20.04

# Gitea HTTPS pem
COPY ./cert.pem /etc/ssl/certs/cert.pem

Docker Hub에 로그인하기 위해 docker login을 사용한 후, docker builddocker push 명령어를 통해 이미지를 업로드합니다.

vagrant@gitea:/vagrant/docker/gitea-label/ubuntu-20.04$ docker build --tag gnu96/default-image:ubuntu-20.04 .

[+] Building 0.0s (0/0) docker:default
[+] Building 2.7s (10/10) FINISHED docker:default
=> [internal] load build definition from Dockerfile 0.1s
=> => transferring dockerfile: 728B 0.0s
=> [internal] load metadata for docker.io/gitea/runner-images:ubuntu-20.04 2.0s
=> [internal] load .dockerignore
..
vagrant@gitea:/vagrant/docker/gitea-label/ubuntu-20.04$ docker push gnu96/default-image:ubuntu-20.04
The push refers to repository [docker.io/gnu96/default-image]
c59aab1fdd6d: Pushed
3a84f51b1d89: Pushed
bf783e4fa58c: Pushing [========================> ] 235.2MB/480.5MB
15fc8a7a0e09: Pushed
5f70bf18a086: Layer already exists

Gitea Runner 설정 파일(config.yaml)에서 labels 설정을 아래와 같이 변경을 합니다.

  # The labels of a runner are used to determine which jobs the runner can run, and how to run them.
# Like: "macos-arm64:host" or "ubuntu-latest:docker://gitea/runner-images:ubuntu-latest"
# Find more images provided by Gitea at https://gitea.com/gitea/runner-images .
# If it's empty when registering, it will ask for inputting labels.
# If it's empty when execute `daemon`, will use labels in `.runner` file.
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"
- "ubuntu-20.04:docker://gnu96/default-image:ubuntu-20.04"

Gitea Actions 에서 demo.yaml 에서 runs-on 정보를 ubuntu-20.04 으로 변경 후 Actions를 다시 실행합니다.

# Gitea Action demo.yaml 파일
name: Gitea Actions Demo
run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀
on: [push]

jobs:
Explore-Gitea-Actions:
# Job이 실행할 컨테이너 이미지 Gitea Runner 설정파일에 있는
# labels 정보임. Docker Hub의 gitea/runner-images:ubuntu-latest 사용함.
runs-on: ubuntu-20.04

Actions 에서 Check out repository code 에서 에러가 발생하지 않고 정상적으로 모든 Actions이 실행이 되는 것을 확인 할 수 있습니다.

마무리하며

Gitea에서 Gitea Actions을 사용하기 위한 환경을 구성하고 간단한 샘플 예제를 실행해 보았습니다. 다음으로는 Gitea Actions를 활용해 CI/CD 파이프라인을 생성해 보도록 하겠습니다.

참고사이트

--

--