1#!/usr/bin/env bash23if [[ ! -d /data ]]; then4 mkdir -p /data5fi67cd /data89CONFIG_ARG=""10if [[ ! -z "${CONFIG_FILE}" ]]; then11 CONFIG_ARG="--config ${CONFIG_FILE}"12fi13EXTRA_ARGS=""14if [[ ! -z "${GITEA_RUNNER_LABELS}" ]]; then15 EXTRA_ARGS="${EXTRA_ARGS} --labels ${GITEA_RUNNER_LABELS}"16fi1718# Use the same ENV variable names as https://github.com/vegardit/docker-gitea-act-runner1920if [[ ! -s .runner ]]; then21 try=$((try + 1))22 success=02324 # The point of this loop is to make it simple, when running both forgejo-runner and gitea in docker,25 # for the forgejo-runner to wait a moment for gitea to become available before erroring out. Within26 # the context of a single docker-compose, something similar could be done via healthchecks, but27 # this is more flexible.28 while [[ $success -eq 0 ]] && [[ $try -lt ${GITEA_MAX_REG_ATTEMPTS:-10} ]]; do29 forgejo-runner register \30 --instance "${GITEA_INSTANCE_URL}" \31 --token "${GITEA_RUNNER_REGISTRATION_TOKEN}" \32 --name "${GITEA_RUNNER_NAME:-`hostname`}" \33 ${CONFIG_ARG} ${EXTRA_ARGS} --no-interactive 2>&1 | tee /tmp/reg.log3435 cat /tmp/reg.log | grep 'Runner registered successfully' > /dev/null36 if [[ $? -eq 0 ]]; then37 echo "SUCCESS"38 success=139 else40 echo "Waiting to retry ..."41 sleep 542 fi43 done44fi45# Prevent reading the token from the forgejo-runner process46unset GITEA_RUNNER_REGISTRATION_TOKEN4748forgejo-runner daemon ${CONFIG_ARG}