forgejo-runner

git clone git://git.lin.moe/forgejo-runner.git

 1#!/usr/bin/env bash
 2
 3if [[ ! -d /data ]]; then
 4  mkdir -p /data
 5fi
 6
 7cd /data
 8
 9CONFIG_ARG=""
10if [[ ! -z "${CONFIG_FILE}" ]]; then
11  CONFIG_ARG="--config ${CONFIG_FILE}"
12fi
13EXTRA_ARGS=""
14if [[ ! -z "${GITEA_RUNNER_LABELS}" ]]; then
15  EXTRA_ARGS="${EXTRA_ARGS} --labels ${GITEA_RUNNER_LABELS}"
16fi
17
18# Use the same ENV variable names as https://github.com/vegardit/docker-gitea-act-runner
19
20if [[ ! -s .runner ]]; then
21  try=$((try + 1))
22  success=0
23
24  # 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.  Within
26  # the context of a single docker-compose, something similar could be done via healthchecks, but
27  # this is more flexible.
28  while [[ $success -eq 0 ]] && [[ $try -lt ${GITEA_MAX_REG_ATTEMPTS:-10} ]]; do
29    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.log
34
35    cat /tmp/reg.log | grep 'Runner registered successfully' > /dev/null
36    if [[ $? -eq 0 ]]; then
37      echo "SUCCESS"
38      success=1
39    else
40      echo "Waiting to retry ..."
41      sleep 5
42    fi
43  done
44fi
45# Prevent reading the token from the forgejo-runner process
46unset GITEA_RUNNER_REGISTRATION_TOKEN
47
48forgejo-runner daemon ${CONFIG_ARG}