-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuserdata.sh
More file actions
63 lines (50 loc) · 2.04 KB
/
userdata.sh
File metadata and controls
63 lines (50 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
# -------------------------------
# Ubuntu 24.04 User Data for Self-Hosted GitHub Runner
# -------------------------------
# Update system and install dependencies
apt-get update -y
apt-get install -y curl jq unzip git
# -------------------------------
# Install AWS CLI v2
# -------------------------------
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
./aws/install
aws --version
# -------------------------------
# GitHub repo details
# -------------------------------
GH_OWNER="malikanish"
GH_REPO="Github-selfhosted-runner"
REGION="us-east-1"
SSM_PARAM_NAME="/github/selfhosted/pat"
# Fetch GitHub PAT from SSM Parameter Storee
GH_PAT=$(aws ssm get-parameter --name "$SSM_PARAM_NAME" --with-decryption --region $REGION --query "Parameter.Value" --output text)
# Download and setup latest GitHub Runner
# -------------------------------
RUNNER_VERSION=$(curl -s https://api.github.com/repos/actions/runner/releases/latest | jq -r .tag_name)
RUNNER_DIR="/home/ubuntu/actions-runner"
rm -rf $RUNNER_DIR
mkdir -p $RUNNER_DIR
chown -R ubuntu:ubuntu $RUNNER_DIR
cd $RUNNER_DIR || exit 1
# Download latest runner tar as ubuntu
sudo -u ubuntu curl -o actions-runner.tar.gz -L https://github.com/actions/runner/releases/download/${RUNNER_VERSION}/actions-runner-linux-x64-${RUNNER_VERSION:1}.tar.gz
sudo -u ubuntu tar xzf actions-runner.tar.gz --strip-components=1
# Make all scripts executable
chmod +x *.sh
chown -R ubuntu:ubuntu $RUNNER_DIR
# -------------------------------
# Register runner with GitHubbb
# -------------------------------
RUNNER_TOKEN=$(curl -s -X POST -H "Authorization: token ${GH_PAT}" \
https://api.github.com/repos/${GH_OWNER}/${GH_REPO}/actions/runners/registration-token | jq -r .token)
# Configure runner
sudo -u ubuntu ./config.sh --url https://github.com/${GH_OWNER}/${GH_REPO} --token ${RUNNER_TOKEN} --unattended --labels ec2
# -------------------------------
# Start runner service
# -------------------------------
sudo ./svc.sh install
sudo ./svc.sh start
sudo ./svc.sh status