-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathstartup.sh
56 lines (44 loc) · 1.33 KB
/
startup.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
51
52
53
54
55
56
#!/bin/bash
echo "Starting supervisor (Docker)"
sudo service docker start
if [ -n "${GITHUB_REPOSITORY}" ]; then
auth_url="https://api.github.com/repos/${GITHUB_OWNER}/${GITHUB_REPOSITORY}/actions/runners/registration-token"
registration_url="https://github.com/${GITHUB_OWNER}/${GITHUB_REPOSITORY}"
else
auth_url="https://api.github.com/orgs/${GITHUB_OWNER}/actions/runners/registration-token"
registration_url="https://github.com/${GITHUB_OWNER}"
fi
generate_token() {
local payload
local runner_token
payload=$(curl -sX POST -H "Authorization: token ${GITHUB_PERSONAL_TOKEN}" "${auth_url}")
runner_token=$(echo "${payload}" | jq .token --raw-output)
if [ "${runner_token}" == "null" ]; then
echo "${payload}"
exit 1
fi
echo "${runner_token}"
}
remove_runner() {
./config.sh remove --unattended --token "$(generate_token)"
}
service docker status
runner_id=${RUNNER_NAME}_$(openssl rand -hex 6)
echo "Registering runner ${runner_id}"
RUNNER_TOKEN=$(generate_token)
test $? -ne 0 && {
echo "Debugging token"
echo "${RUNNER_TOKEN}"
exit 1
}
./config.sh \
--name "${runner_id}" \
--labels "${RUNNER_LABELS}" \
--token "${RUNNER_TOKEN}" \
--url "${registration_url}" \
--unattended \
--replace \
--ephemeral
trap 'remove_runner; exit 130' SIGINT
trap 'remove_runner; exit 143' SIGTERM
./run.sh "$*"