2025-10-28 11:57:22 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
|
#
|
|
|
|
|
RUNNER_HOME=${RUNNER_HOME:-/data}
|
|
|
|
|
|
|
|
|
|
set -ex
|
|
|
|
|
set -o pipefail
|
|
|
|
|
|
2025-10-28 14:27:33 +00:00
|
|
|
mkdir -p ${RUNNER_HOME}
|
|
|
|
|
|
2025-10-28 11:57:22 +01:00
|
|
|
if [ ! -d "${RUNNER_HOME}" ]; then
|
|
|
|
|
log.error "$RUNNER_HOME should be an emptyDir mount. Please fix the pod spec."
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ -z "$METADATA_URL" ]; then
|
|
|
|
|
echo "no token is available and METADATA_URL is not set"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ -z "$CALLBACK_URL" ]; then
|
|
|
|
|
echo "CALLBACK_URL is not set"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2025-10-30 14:15:09 +01:00
|
|
|
if [ -z "$GITHUB_URL" ]; then
|
|
|
|
|
echo "GITHUB_URL is not set"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ -z "$RUNNER_NAME" ]; then
|
|
|
|
|
echo "RUNNER_NAME is not set"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ -z "$BEARER_TOKEN" ]; then
|
|
|
|
|
echo "BEARER_TOKEN is not set"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
function success() {
|
|
|
|
|
MSG="$1"
|
|
|
|
|
ID=${2:-null}
|
|
|
|
|
|
|
|
|
|
call "{\"status\": \"idle\", \"message\": \"$MSG\", \"agent_id\": $ID}"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function call() {
|
|
|
|
|
PAYLOAD="$1"
|
|
|
|
|
local cb_url=$CALLBACK_URL
|
|
|
|
|
[[ $cb_url =~ ^(.*)/status(/)?$ ]] || cb_url="${cb_url}/status"
|
|
|
|
|
curl --retry 5 --retry-delay 5 --retry-connrefused --fail -s -X POST -d "${PAYLOAD}" -H 'Accept: application/json' -H "Authorization: Bearer ${BEARER_TOKEN}" "${cb_url}" || echo "failed to call home: exit code ($?)"
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-28 11:57:22 +01:00
|
|
|
# retrieve runner secret from garm
|
|
|
|
|
RUNNER_SECRET=$(curl --retry 5 --retry-delay 5 --retry-connrefused --fail -v -X GET -H 'Accept: application/json' -H "Authorization: Bearer ${BEARER_TOKEN}" "${METADATA_URL}/runner-registration-token/")
|
|
|
|
|
|
|
|
|
|
forgejo-runner \
|
|
|
|
|
register \
|
|
|
|
|
--no-interactive \
|
|
|
|
|
--token ${RUNNER_SECRET} \
|
|
|
|
|
--name ${RUNNER_NAME} \
|
|
|
|
|
--instance ${GITHUB_URL} \
|
|
|
|
|
--labels ubuntu-host:host
|
|
|
|
|
|
|
|
|
|
forgejo-runner generate-config > config.yml;
|
|
|
|
|
|
2025-10-30 14:15:09 +01:00
|
|
|
success "runner should be working"
|
|
|
|
|
|
2025-10-28 11:57:22 +01:00
|
|
|
unset RUNNER_SECRET
|
|
|
|
|
unset BEARER_TOKEN
|
|
|
|
|
|
2025-10-28 15:30:10 +01:00
|
|
|
docker buildx create --use --name sidecar unix:///run/user/1000/buildkit/buildkitd.sock
|
|
|
|
|
|
2025-10-29 11:29:22 +01:00
|
|
|
/bin/forgejo-runner --config config.yml one-job
|