4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

GitHub Actions self-hosted runnerをインストールしてCI/CDを実行

Last updated at Posted at 2020-10-28

以下のガイドを見ながら実際にインストールを行った.

Adding self-hosted runners

GitHubリポジトリにアクセスして,Settings → Actionsを選ぶ.

image.png

Add runnerを選ぶ.

image.png

利用するプラットフォームとアーキテクチャを選ぶ.

image.png

インストール方法に沿ってコマンドを実行する.

sudo mkdir /opt/actions-runner
cd /opt/actions-runner
chown `whoami`: /opt/actions-runner
curl -O -L https://github.com/actions/runner/releases/download/v2.273.5/actions-runner-linux-x64-2.273.5.tar.gz
tar xzf ./actions-runner-linux-x64-2.273.5.tar.gz
./config.sh --url https://github.com/cdsl-research/stns-config --token XXXXXXXXXXXXXXXXXXXXXX

実行結果は以下になる.

image.png

起動スクリプトでRunnerを起動する.

./run.sh

実行結果は以下になる.

image.png

Runnerの実行時の起点ディレクトリは次のパスになる.

/opt/actions-runner/_work/repository_name/repository_name/

実際に .github/workflows/xxx.yml を作成してみる.

name: Sample Workflows

on:
  push:
    branches:
      - master

jobs:
  deploy:
    runs-on: self-hosted
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-python@v2
      - name: Setup Python
        run: |
          python -m pip install --upgrade pip
          pip install -r requirements.txt
      - run: |
          python a.py

以下は実行結果は次のようになる.

image.png

systemdのserviceファイルを書く.テンプレートを公式が提供している.

/etc/systemd/system/github-actions-runner.service
[Unit]
Description=GitHub Actions Runner
After=network.target

[Service]
WorkingDirectory=/opt/actions-runner
User=gha-runner
Group=gha-runner
ExecStart=/opt/actions-runner/bin/runsvc.sh
Restart=always
KillMode=process
KillSignal=SIGTERM
TimeoutStopSec=5min

[Install]
WantedBy=multi-user.target

ユーザを追加

sudo useradd gha-runner

ディレクトリの所有者を変更

sudo chown -R gha-runner: /opt/actions-runner

systemdへ追加して永続化と起動

sudo systemctl daemon-reload
sudo systemctl enable --now github-actions-runner
4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?