Self-hosted Runner

GitHub Actions Self-hosted Runner running on AWS CodeBuild

System Configuration

インストール済

  • awscli
  • docker
  • github-cli

動作確認済み

  • actions/checkout@v2
  • actions/github-script@v2
  • aws-actions/configure-aws-credentials@v1
  • ruby/setup-ruby@v1

GitHub Actions

Inputs

  1. personal-access-token (required) : GitHub Personal access token
  2. project-name (optional) : AWS CodeBuild Project Name, Defaults to SelfHostedRunner
  3. compute-type-override (optional) : AWS CodeBuild Compute Type, Defaults to BUILD_GENERAL1_SMALL
  4. additional-label (optional) : Self-hosted Runner additional label, Defaults to runner

Outputs

  1. aws-build-id : AWS CodeBuild Build ID

Example

steps:
  - uses: aws-actions/configure-aws-credentials@v1
    with:
      aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
      aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
      aws-region: ap-northeast-1
  - uses: rvillage/self_hosted_runner@v1-beta
    id: setup
    with:
      personal-access-token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
  - run: echo ${{ steps.setup.outputs.aws-build-id }}

Setup

AWS

  1. .deploy/cloud_formation/codebuild.ymlでCloudFormationスタックの作成
  2. docker imageのビルドしてECRにプッシュ
DOCKER_BUILDKIT=1 docker build -t xxx.dkr.ecr.ap-northeast-1.amazonaws.com/self_hosted_runner:latest -f Dockerfile .
docker push xxx.dkr.ecr.ap-northeast-1.amazonaws.com/self_hosted_runner:latest
  1. IAMユーザgithub-actions-userのアクセスキーをGitHubリポジトリに設定
  2. RunnerToken発行用のPersonal access tokenをGitHubリポジトリに設定
  3. .github/workflows/test.ymlの作成
jobs:
  setup:
    runs-on: ubuntu-20.04
    steps:
      - uses: aws-actions/configure-aws-credentials@v1
        with:
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          aws-region: ap-northeast-1
      - uses: rvillage/self_hosted_runner@v1-beta
        with:
          personal-access-token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}

  first_job:
    needs: setup
    runs-on: [self-hosted, runner, "${{ github.run_id }}"]
    steps:
      - run: echo "Hello SelfHostedRunner!"

Local

  1. (初回のみ) docker imageのビルド
DOCKER_BUILDKIT=1 docker build -t local/runner -f Dockerfile .
docker-compose up --no-start
  1. (初回のみ) docker-compose.yml.sampleからdocker-compose.ymlにコピーしてenvを設定
  2. 起動
docker-compose start runner && docker-compose logs -f runner
  1. 停止
docker-compose stop runner
  1. クリーンアップ
docker-compose down --volumes