Closed7
GitHubでself-hosted runnerを使いたい

GitHub Teamプラン
CI/CD時間 3,000分/月
なのでセルフホステッド ランナーを追加したい

AWSにubuntuのEC2インスタンスを起動
アーキテクチャ:Arm(64bit) ※Gravitonのインスタンスタイプを選択したいため
AMI ID:ami-007bc34ad4cc33773
AMI 名:ubuntu/images/hvm-ssd-gp3/ubuntu-noble-24.04-arm64-server-20240801

この手順に従う
(リポジトリの設定ページを開く権限が必要)
新しいランナーをクリック後、OSとアーキテクチャを選択すると、一時トークンを含むコマンドが表示されるので実行
$ mkdir actions-runner; cd actions-runner
$ curl -o actions-runner-linux-arm64-2.319.1.tar.gz -L https://github.com/actions/runner/releases/download/v2.319.1/actions-runner-linux-arm64-2.319.1.tar.gz
$ echo "03d993c65e0c4daa5e3bf5a5a35ba356f363bdb5ceb6b5808fd52fdb813dd8e8 actions-runner-linux-arm64-2.319.1.tar.gz" | shasum -a 256 -c
actions-runner-linux-arm64-2.319.1.tar.gz: OK
$ tar xzf ./actions-runner-linux-arm64-2.319.1.tar.gz
$ ./config.sh --url https://github.com/example-org/example-app --token ABCDEFGHIJKLMNOPQRSTUVWXYZ123
--------------------------------------------------------------------------------
| ____ _ _ _ _ _ _ _ _ |
| / ___(_) |_| | | |_ _| |__ / \ ___| |_(_) ___ _ __ ___ |
| | | _| | __| |_| | | | | '_ \ / _ \ / __| __| |/ _ \| '_ \/ __| |
| | |_| | | |_| _ | |_| | |_) | / ___ \ (__| |_| | (_) | | | \__ \ |
| \____|_|\__|_| |_|\__,_|_.__/ /_/ \_\___|\__|_|\___/|_| |_|___/ |
| |
| Self-hosted runner registration |
| |
--------------------------------------------------------------------------------
# Authentication
√ Connected to GitHub
# Runner Registration
Enter the name of the runner group to add this runner to: [press Enter for Default]
Enter the name of runner: [press Enter for ip-10-0-1-5]
This runner will have the following labels: 'self-hosted', 'Linux', 'ARM64'
Enter any additional labels (ex. label-1,label-2): [press Enter to skip]
√ Runner successfully added
√ Runner connection is good
# Runner settings
Enter name of work folder: [press Enter for _work]
√ Settings Saved.

一時トークンの有効期限はこのページを開いて新規に作成されてから1時間なようで、1時間以上経過したトークンでコンフィグ実行しようとしたら404エラーが発生した
$ ./config.sh --url https://github.com/example-org/example-app --token ABCDEFGHIJKLMNOPQRSTUVWXYZ123
Http response code: NotFound from 'POST https://api.github.com/actions/runner-registration'
{"message":"Not Found","documentation_url":"https://docs.github.com/rest"}
Response status code does not indicate success: 404 (Not Found).

./run.sh
を実行し、接続が表示されればOK
$ ./run.sh
√ Connected to GitHub
Current runner version: '2.319.1'
2024-09-11 06:24:47Z: Listening for Jobs
GitHub上のRunners画面に戻るとランナーが追加されていることが確認できる

./run.sh
だとターミナルが切れると使えないので、サービス化する
インスタンスを起動停止しても自動起動されるよう設定
$ sudo ./svc.sh install
$ sudo ./svc.sh start
$ sudo ./svc.sh enable
ステータスの確認
$ sudo ./svc.sh status
/etc/systemd/system/actions.runner.example-org-example-app.ip-10-0-1-5.service
● actions.runner.example-org-example-app.ip-10-0-1-5.service - GitHub Actions Runner (example-org-example-app.ip-10-0-1-5)
Loaded: loaded (/etc/systemd/system/actions.runner.example-org-example-app.ip-10-0-1-5.service; enabled; preset: enabled)
Active: active (running) since Wed 2024-09-11 06:26:01 UTC; 14s ago
Main PID: 1442 (runsvc.sh)
Tasks: 23 (limit: 9302)
Memory: 51.6M (peak: 51.8M)
CPU: 2.074s
CGroup: /system.slice/actions.runner.example-org-example-app.ip-10-0-1-5.service
tq1442 /bin/bash /home/ubuntu/actions-runner/runsvc.sh
tq1445 ./externals/node16/bin/node ./bin/RunnerService.js
mq1452 /home/ubuntu/actions-runner/bin/Runner.Listener run --start …
Sep 11 06:26:01 ip-10-0-1-5 systemd[1]: Started actions.runner.serverworks…42).
Sep 11 06:26:01 ip-10-0-1-5 runsvc.sh[1442]: .path=/usr/local/sbin:/usr/loc…bin
Sep 11 06:26:01 ip-10-0-1-5 runsvc.sh[1445]: Starting Runner listener with …ice
Sep 11 06:26:01 ip-10-0-1-5 runsvc.sh[1445]: Started listener process, pid:…452
Sep 11 06:26:01 ip-10-0-1-5 runsvc.sh[1445]: Started running service
Sep 11 06:26:04 ip-10-0-1-5 runsvc.sh[1445]: √ Connected to GitHub
Sep 11 06:26:05 ip-10-0-1-5 runsvc.sh[1445]: Current runner version: '2.319.1'
Sep 11 06:26:05 ip-10-0-1-5 runsvc.sh[1445]: 2024-09-11 06:26:05Z: Listenin…obs
Hint: Some lines were ellipsized, use -l to show in full.

セルフホステッド ランナーの準備は出来たが、実際に使うためにはリポジトリ内のワークフローファイルもセルフホステッド ランナーを使うよう指定する必要があるので、書き換える
.github/workflows/xxx.yml
# Use this YAML in your workflow file for each job
runs-on: self-hosted
このスクラップは2024/09/11にクローズされました