0
1

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 の Runner を一発で構築するスクリプト

Posted at

Terraform で EC2 の user_data に突っ込んで、自動構築した。

gh-action.tf
resource "aws_security_group" "runner" {
  egress {
    from_port   = 0
    to_port     = 0
    protocol    = "-1"
    cidr_blocks = ["0.0.0.0/0"]
  }
}

resource "aws_instance" "runner" {
  ami                    = "ami-0278fe6949f6b1a06" # ubuntu 18.04
  instance_type          = "t2.small"
  vpc_security_group_ids = [aws_security_group.runner.id]
  user_data              = file("./ec2-scripts/init-gh-action-runner.sh")
}
./ec2-scripts/init-gh-action-runner.sh
#!/bin/bash

set -ue

curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo usermod -aG docker ubuntu

mkdir actions-runner
cd actions-runner
curl -O -L https://github.com/actions/runner/releases/download/v2.169.1/actions-runner-linux-x64-2.169.1.tar.gz
tar xzf ./actions-runner-linux-x64-2.169.1.tar.gz
chown -R ubuntu: /actions-runner
sudo -i -u ubuntu /actions-runner/config.sh \
    --url https://github.com/org/repo \
    --token AAAAAAAAAAAAAAAAAAAAAAAAAAAAA \
    --name $HOSTNAME \
    --work _work \
    --unattended \
    --replace

/actions-runner/svc.sh install
/actions-runner/svc.sh start

TODO: GitHub Actions のトークンの作成を自動化したい

参考: https://github.com/myoung34/docker-github-actions-runner

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?