41 lines
1.2 KiB
Bash
41 lines
1.2 KiB
Bash
#!/usr/bin/env sh
|
|
|
|
set -o errexit
|
|
set -o nounset
|
|
|
|
GITEA_RUNNER_NAME="${GITEA_RUNNER_NAME:-main}"
|
|
|
|
LOG_PIPE="$(mktemp -u)"
|
|
mkfifo "$LOG_PIPE"
|
|
|
|
(
|
|
while IFS= read -r line; do
|
|
if echo "$line" | grep -qiE 'level=(warn|error|fatal)'; then
|
|
echo "$line" >&2
|
|
else
|
|
echo "$line"
|
|
fi
|
|
done < "$LOG_PIPE"
|
|
) &
|
|
|
|
if [ ! -f /var/lib/gitea-act-runner/registration ]; then
|
|
GITEA_API="${GITEA_INSTANCE_URL%/}/api/v1"
|
|
|
|
auth="Authorization: Basic $(printf '%s:%s' "$GITEA_ADMIN_USERNAME" "$GITEA_ADMIN_PASSWORD" | base64 -w 0)"
|
|
|
|
runners="$(curl -sf --retry 10 --retry-connrefused -H "$auth" "$GITEA_API/admin/actions/runners")"
|
|
|
|
echo "$runners" | jq -r ".runners[] | select(.name == \"$GITEA_RUNNER_NAME\") | .id" | while read -r runner_id; do
|
|
curl -sf -X DELETE -H "$auth" "$GITEA_API/admin/actions/runners/$runner_id"
|
|
done
|
|
|
|
act_runner --config /etc/gitea-act-runner/config.yaml register \
|
|
--no-interactive \
|
|
--instance "$GITEA_INSTANCE_URL" \
|
|
--token "$GITEA_RUNNER_REGISTRATION_TOKEN" \
|
|
--name "$GITEA_RUNNER_NAME" \
|
|
--labels "${GITEA_RUNNER_LABELS:-}" > "$LOG_PIPE" 2>&1
|
|
fi
|
|
|
|
exec act_runner --config /etc/gitea-act-runner/config.yaml daemon "$@" > "$LOG_PIPE" 2>&1
|