packer build github-runner.json
Last active
August 21, 2020 17:48
-
-
Save alexgandy/470dd89d79f327a048c30dfd66eecb36 to your computer and use it in GitHub Desktop.
Quick EC2 Hosted Github Action Runner (Packer/Docker -- Free)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
cd /home/ubuntu | |
mkdir actions-runner && cd actions-runner | |
curl -O -L curl -O -L https://github.com/actions/runner/releases/download/v2.272.0/actions-runner-linux-x64-2.272.0.tar.gz | |
tar xzf ./actions-runner-linux-x64-2.272.0.tar.gz | |
INSTANCE_ID=$(wget -q -O - http://169.254.169.254/latest/meta-data/instance-id) | |
GH_REPO=https://github.com/meetrics-io/***************** | |
GH_ACTION_TOKEN=**************************************** | |
export RUNNER_ALLOW_RUNASROOT=1 | |
./config.sh --unattended --url $GH_REPO --token $GH_ACTION_TOKEN --name $INSTANCE_ID --work "_work" | |
sudo ./svc.sh install | |
sudo ./svc.sh start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -x | |
apt-get -y update | |
apt-get install -y make git sudo | |
curl -fsSL https://get.docker.com -o get-docker.sh | |
sudo sh get-docker.sh | |
sudo usermod -a -G sudo ubuntu | |
echo "%sudo ALL = (ALL) NOPASSWD: ALL" | sudo tee -a /etc/sudoers | |
sudo curl -L "https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose | |
sudo chmod +x /usr/local/bin/docker-compose | |
sudo chmod o+rw /var/run/docker.sock | |
whoami | |
docker --version | |
docker-compose --version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"min_packer_version": "0.12.0", | |
"variables": { | |
"aws_region": "us-east-1" | |
}, | |
"builders": [ | |
{ | |
"name": "github-runner-ubuntu-18.04-ami", | |
"ami_name": "github-runner-ami-{{isotime | clean_resource_name}}", | |
"ami_description": "Github Runner (Ubuntu 18.04 - HVM/EBS)", | |
"instance_type": "t3.medium", | |
"region": "{{user `aws_region`}}", | |
"type": "amazon-ebs", | |
"profile": "*****************YOUR_AWS_PROFILE_HERE*****************", | |
"user_data_file": "./boot.sh", | |
"source_ami_filter": { | |
"filters": { | |
"virtualization-type": "hvm", | |
"architecture": "x86_64", | |
"name": "ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-*", | |
"block-device-mapping.volume-type": "gp2", | |
"root-device-type": "ebs" | |
}, | |
"owners": [ | |
"099720109477" | |
], | |
"most_recent": true | |
}, | |
"ssh_username": "ubuntu" | |
} | |
], | |
"provisioners": [ | |
{ | |
"type": "shell", | |
"inline": ["export PATH=$HOME/bin:$PATH >> /etc/profile"], | |
"execute_command": "{{.Vars}} sudo -S -E bash '{{.Path}}'" | |
}, | |
{ | |
"type": "shell", | |
"execute_command": "{{.Vars}} bash '{{.Path}}'", | |
"script": "./dependencies.sh" | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment