2021-11-17 11:28:25 -08:00
|
|
|
#!/bin/bash
|
|
|
|
|
2023-01-25 19:45:11 -08:00
|
|
|
if [[ "$@" == "bash" ]]; then
|
|
|
|
exec $@
|
|
|
|
fi
|
|
|
|
|
2023-02-22 19:08:25 -08:00
|
|
|
ulimit -n 1024
|
|
|
|
|
2023-01-27 12:55:49 -08:00
|
|
|
export XDG_RUNTIME_DIR=$HOME/.docker/run
|
|
|
|
export DOCKER_HOST=unix:///home/docker/.docker/run/docker.sock
|
2023-01-25 19:45:11 -08:00
|
|
|
rm -rf $XDG_RUNTIME_DIR
|
|
|
|
mkdir -p $XDG_RUNTIME_DIR
|
2023-01-27 12:55:49 -08:00
|
|
|
PATH=/usr/bin:/sbin:/usr/sbin:$PATH dockerd-rootless.sh >/opt/docker.log 2>/opt/docker.log &
|
2023-01-25 19:45:11 -08:00
|
|
|
|
2021-11-17 14:03:18 -08:00
|
|
|
cd /opt/actions-runner
|
2021-11-17 11:28:25 -08:00
|
|
|
|
2023-01-23 15:03:43 -08:00
|
|
|
if [[ -z $RUNNER_NAME ]]; then
|
|
|
|
echo "RUNNER_NAME environment variable is not set, using '${HOSTNAME}'."
|
|
|
|
export RUNNER_NAME=${HOSTNAME}
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -z $RUNNER_WORK_DIRECTORY ]]; then
|
|
|
|
echo "RUNNER_WORK_DIRECTORY environment variable is not set, using '_work'."
|
|
|
|
export RUNNER_WORK_DIRECTORY="_work"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -z $RUNNER_TOKEN && -z $GITHUB_ACCESS_TOKEN ]]; then
|
|
|
|
echo "Error : You need to set RUNNER_TOKEN (or GITHUB_ACCESS_TOKEN) environment variable."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -z $RUNNER_REPOSITORY_URL && -z $RUNNER_ORGANIZATION_URL ]]; then
|
|
|
|
echo "Error : You need to set the RUNNER_REPOSITORY_URL (or RUNNER_ORGANIZATION_URL) environment variable."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -z $RUNNER_REPLACE_EXISTING ]]; then
|
|
|
|
export RUNNER_REPLACE_EXISTING="true"
|
|
|
|
fi
|
|
|
|
|
|
|
|
CONFIG_OPTS=""
|
|
|
|
if [ "$(echo $RUNNER_REPLACE_EXISTING | tr '[:upper:]' '[:lower:]')" == "true" ]; then
|
|
|
|
CONFIG_OPTS="--replace"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -n $RUNNER_LABELS ]]; then
|
|
|
|
CONFIG_OPTS="${CONFIG_OPTS} --labels ${RUNNER_LABELS}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -f ".runner" ]]; then
|
|
|
|
echo "Runner already configured. Skipping config."
|
|
|
|
else
|
|
|
|
if [[ ! -z $RUNNER_ORGANIZATION_URL ]]; then
|
|
|
|
SCOPE="orgs"
|
|
|
|
RUNNER_URL="${RUNNER_ORGANIZATION_URL}"
|
|
|
|
else
|
|
|
|
SCOPE="repos"
|
|
|
|
RUNNER_URL="${RUNNER_REPOSITORY_URL}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -n $GITHUB_ACCESS_TOKEN ]]; then
|
|
|
|
|
|
|
|
echo "Exchanging the GitHub Access Token with a Runner Token (scope: ${SCOPE})..."
|
|
|
|
|
|
|
|
_PROTO="$(echo "${RUNNER_URL}" | grep :// | sed -e's,^\(.*://\).*,\1,g')"
|
|
|
|
_URL="$(echo "${RUNNER_URL/${_PROTO}/}")"
|
|
|
|
_PATH="$(echo "${_URL}" | grep / | cut -d/ -f2-)"
|
|
|
|
|
|
|
|
RUNNER_TOKEN="$(curl -XPOST -fsSL \
|
|
|
|
-H "Authorization: token ${GITHUB_ACCESS_TOKEN}" \
|
|
|
|
-H "Accept: application/vnd.github.v3+json" \
|
|
|
|
"https://api.github.com/${SCOPE}/${_PATH}/actions/runners/registration-token" \
|
|
|
|
| jq -r '.token')"
|
|
|
|
fi
|
2021-11-17 11:28:25 -08:00
|
|
|
|
2023-01-23 15:03:43 -08:00
|
|
|
./config.sh \
|
|
|
|
--url $RUNNER_URL \
|
|
|
|
--token $RUNNER_TOKEN \
|
|
|
|
--name $RUNNER_NAME \
|
|
|
|
--work $RUNNER_WORK_DIRECTORY \
|
|
|
|
$CONFIG_OPTS \
|
|
|
|
--unattended
|
2021-11-17 14:03:18 -08:00
|
|
|
fi
|
2021-11-17 11:28:25 -08:00
|
|
|
|
2023-01-25 19:45:11 -08:00
|
|
|
exec "$@"
|