-
Notifications
You must be signed in to change notification settings - Fork 11
/
entrypoint.sh
executable file
·50 lines (42 loc) · 1.76 KB
/
entrypoint.sh
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
#!/bin/bash
set -ex
mkdir work-dir
# Grab a runner registration token
# https://docs.github.com/en/rest/actions/self-hosted-runners#create-a-registration-token-for-a-repository
status_code=$(curl \
-s \
-w "%{http_code}" \
-o /tmp/token_response.json \
-X POST \
-H "Authorization: token ${PERSONAL_ACCESS_TOKEN}" \
"https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/actions/runners/registration-token" \
)
if [[ $status_code == "201" ]]
then
REGISTRATION_TOKEN=$(jq -r ".token" /tmp/token_response.json)
else
echo "Got status code $status_code trying to create a GitHub repo registration token."
echo "Response: $(cat /tmp/token_response.json)"
exit 1
fi
# Use the RUNNER_UUID env var if it exists
UNIQUE_ID=${RUNNER_UUID:-$(uuidgen)}
# Register the runner:
# - disable updates since we manage them manually via the container image
# - https://docs.github.com/en/actions/hosting-your-own-runners/autoscaling-with-self-hosted-runners#controlling-runner-software-updates-on-self-hosted-runners
# - register as an ephemeral runner
# - https://docs.github.com/en/actions/hosting-your-own-runners/autoscaling-with-self-hosted-runners#using-ephemeral-runners-for-autoscaling
# - labels argument to config.sh is a comma-separated list
# - https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/using-labels-with-self-hosted-runners#programmatically-assign-labels
LABELS=$(echo "$UNIQUE_ID" "$RUNNER_LABELS" | tr ' ' ',' )
./config.sh \
--unattended \
--url "https://github.com/${REPO_OWNER}/${REPO_NAME}" \
--token "${REGISTRATION_TOKEN}" \
--name "${UNIQUE_ID}" \
--labels "${LABELS}" \
--work work-dir \
--replace \
--disableupdate \
--ephemeral
./run.sh