forked from ThewBear/do-actions-runner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
49 lines (38 loc) · 992 Bytes
/
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
#!/usr/bin/env bash
set -eEuo pipefail
if [ -z "${TOKEN:-}" ]
then
echo "TOKEN is required"
exit 1
fi
if [ -n "${ORG:-}" ]
then
API_PATH=orgs/${ORG}
CONFIG_PATH=${ORG}
elif [ -n "${OWNER:-}" ] && [ -n "${REPO:-}" ]
then
API_PATH=repos/${OWNER}/${REPO}
CONFIG_PATH=${OWNER}/${REPO}
else
echo "[ORG] or [OWNER and REPO] is required"
exit 1
fi
RUNNER_TOKEN=$(curl -s -X POST -H "authorization: token ${TOKEN}" "https://api.github.com/${API_PATH}/actions/runners/registration-token" | jq -r .token)
cleanup() {
./config.sh remove --token "${RUNNER_TOKEN}"
}
# run a dummy web server to pass health checks
while true; do
echo -e "HTTP/1.1 200 OK\n\n $(date)" | nc -l -p 8080 -q 1 > /dev/null 2>&1
done&
echo "Setting up GH worker"
./config.sh \
--url "https://github.com/${CONFIG_PATH}" \
--token "${RUNNER_TOKEN}" \
--name "${NAME:-$(hostname)}" \
--labels "${LABELS}:-self-hosted" \
--unattended
trap 'cleanup' SIGTERM
echo "Starting"
./run.sh
wait $!