bromite-buildtools/images/github-runner/startup.sh

65 lines
1.6 KiB
Bash
Raw Permalink Normal View History

2021-07-05 21:18:55 +05:30
#!/bin/bash
2021-07-31 15:36:38 +05:30
echo "Starting Proxy Support"
socat TCP-LISTEN:8118,reuseaddr,fork UNIX-CLIENT:/tmp/forward-proxy/proxy.sock &
sudo iptables -A INPUT -p tcp -s localhost --dport 8118 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 8118 -j DROP
2021-07-05 21:18:55 +05:30
echo "Starting supervisor (Docker)"
sudo service docker start
2021-07-31 15:36:38 +05:30
#bash
2021-07-05 21:18:55 +05:30
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() {
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() {
2021-07-12 20:38:44 +05:30
sudo service docker stop
2021-07-05 21:18:55 +05:30
./config.sh remove --unattended --token "$(generate_token)"
}
service docker status
runner_id=${RUNNER_NAME}_$(openssl rand -hex 6)
echo "Registering runner ${runner_id}"
./config.sh \
--name "${runner_id}" \
--labels "${RUNNER_LABELS}" \
--token "$(generate_token)" \
--url "${registration_url}" \
--allowedauthorslist "${ALLOWEDAUTHORSLIST}" \
--unattended \
2022-02-18 18:22:34 +05:30
--replace \
2022-02-18 20:38:27 +05:30
--disableupdate \
--ephemeral
2021-07-05 21:18:55 +05:30
trap 'remove_runner; exit 130' SIGINT
trap 'remove_runner; exit 143' SIGTERM
for f in runsvc.sh RunnerService.js; do
mv bin/${f}{,.bak}
mv {patched,bin}/${f}
done
2022-02-18 20:38:27 +05:30
./bin/runsvc.sh --once "$*"
2021-07-05 21:18:55 +05:30
remove_runner