介绍

In the previous, we experienced the convenience brought by Github Actions. In this chapter, we will build code artifacts in our intranet environment by creating our own Runner.

In this article, I won't provide extensive explanations of the code, as the articles I wrote before have been lost, yes, lost...

So, feel free to download the code and use it directly :)

Repository from: https://github.com/bohai-repo/builder_template/blob/main/github-runner/README.md

特性

  • Repository runners
  • Organizational runners
  • Labels Diy
  • Graceful shutdown
  • Supports arm64 and amd64
  • Supports docker and Kubernetes
  • Support for installing additional debian packages
  • Auto-update after the release of a new version

构建

Building the container

git clone https://github.com/bohai-repo/builder_template
cd builder_template/github-runner/

sh actions.sh
docker build -t github-runner .

Examples

Register a runner to a repository.

docker run -itd --name github-runner \
     -e REGIST_TYPE='personal' \
     -e GITHUB_OWNER=username-or-organization \
     -e GITHUB_REPOSITORY=my-repository \
     -e GITHUB_PAT=[PAT] \
     -v /var/run/docker.sock:/var/run/docker.sock \
     registry.ap-northeast-1.aliyuncs.com/bohai_repo/github-runner:2.304.0

Register a runner with github token.

docker run -itd --name github-runner \
     -e GITHUB_OWNER=username-or-organization \
     -e GITHUB_REPOSITORY=my-repository \
     -e GITHUB_TOKEN=[github.token] \
     -v /var/run/docker.sock:/var/run/docker.sock \
     registry.ap-northeast-1.aliyuncs.com/bohai_repo/github-runner:2.304.0

Create an organization-wide runner.

docker run -itd --name github-runner \
    -e REGIST_TYPE='organizational' \
    -e GITHUB_ORG_NAME=username-or-organization \
    -e GITHUB_PAT=[PAT] \
     -v /var/run/docker.sock:/var/run/docker.sock \
    registry.ap-northeast-1.aliyuncs.com/bohai_repo/github-runner:2.304.0

Set labels on the runner.

add env:

    -e RUNNER_LABELS='[you labels]' \

Use arm64 CPU

change image:

registry.ap-northeast-1.aliyuncs.com/bohai_repo/github-runner:2.304.0-arm64

Install additional tools on the runner.

docker run -itd --name github-runner \
    -e GITHUB_OWNER=username-or-organization \
    -e GITHUB_REPOSITORY=my-repository \
    -e GITHUB_PAT=[PAT] \
    -e ADDITIONAL_PACKAGES=firefox-esr,chromium \
     -v /var/run/docker.sock:/var/run/docker.sock \
    registry.ap-northeast-1.aliyuncs.com/bohai_repo/github-runner:2.304.0

Running GitHub Actions on Kubernetes

kubectl create ns ops
kubectl apply -f deployment.yml -n ops
kubectl get po -n ops

NAME                                      READY   STATUS    RESTARTS   AGE
github-actions-builder-68f989b844-2gf7z   1/1     Running   0          70s
github-actions-builder-68f989b844-2lnv6   1/1     Running   0          70s
github-actions-builder-68f989b844-8zhpl   1/1     Running   0          70s
github-actions-builder-68f989b844-fzmwm   1/1     Running   0          66s
github-actions-builder-68f989b844-n95gj   1/1     Running   0          65s
最后修改:2026 年 07 月 15 日
如果觉得我的文章对你有用,请随意赞赏