2023-03-24 17:42:52 -04:00
|
|
|
#!/bin/bash
|
2023-04-01 05:08:06 -04:00
|
|
|
# SPDX-License-Identifier: MIT
|
2023-03-24 17:42:52 -04:00
|
|
|
|
|
|
|
set -ex
|
|
|
|
|
2023-05-29 11:12:23 -04:00
|
|
|
: ${FORGEJO_RUNNER_CONFIG:=$(pwd)/runner-config.yaml}
|
|
|
|
|
2023-03-24 17:42:52 -04:00
|
|
|
function dependencies() {
|
2023-04-04 06:51:16 -04:00
|
|
|
if ! which curl daemon > /dev/null ; then
|
|
|
|
apt-get install -y -qq curl daemon
|
2023-03-24 17:42:52 -04:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2023-04-04 06:51:16 -04:00
|
|
|
function download() {
|
|
|
|
local runner_repository="$1"
|
|
|
|
local version="$2"
|
2023-03-24 17:42:52 -04:00
|
|
|
|
2023-04-04 12:24:21 -04:00
|
|
|
if ! which forgejo-runner > /dev/null; then
|
|
|
|
curl -L --fail -sS $runner_repository/releases/download/$version/forgejo-runner-amd64 > /bin/forgejo-runner
|
|
|
|
chmod 755 /bin/forgejo-runner
|
|
|
|
fi
|
2023-03-24 17:42:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function register() {
|
|
|
|
local forgejo="$1"
|
2023-04-30 03:21:22 -04:00
|
|
|
docker exec --user 1000 forgejo forgejo actions generate-runner-token > forgejo-runner-token
|
2023-05-30 09:16:16 -04:00
|
|
|
timeout --signal=KILL 30 forgejo-runner register --no-interactive --instance "$forgejo" --name runner --token $(cat forgejo-runner-token) --labels docker:docker://node:16-bullseye,ubuntu-latest:docker://node:16-buster,self-hosted
|
2023-03-24 17:42:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function run() {
|
2023-04-04 12:24:21 -04:00
|
|
|
rm -f forgejo-runner.log
|
2023-05-29 11:12:23 -04:00
|
|
|
daemon --chdir=$(pwd) --unsafe --env="TERM=$TERM" --env="HOME=$HOME" --env="PATH=$PATH" --env="USER=$USER" --env="TERM=dumb" --env="USERNAME=$USERNAME" --env="LANG=$LANG" --pidfile=$(pwd)/forgejo-runner-pid --errlog=$(pwd)/forgejo-runner.log --output=$(pwd)/forgejo-runner.log -- forgejo-runner --config $FORGEJO_RUNNER_CONFIG daemon
|
2023-03-27 13:39:19 -04:00
|
|
|
sleep 1
|
|
|
|
cat forgejo-runner.log
|
2023-03-24 17:42:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function setup() {
|
2023-04-04 06:51:16 -04:00
|
|
|
local runner_repository="${1:-https://code.forgejo.org/forgejo/runner}"
|
2023-05-22 05:27:50 -04:00
|
|
|
local version="${2:-v2.0.0}"
|
2023-03-27 13:39:19 -04:00
|
|
|
local forgejo="${3:-http://$(cat forgejo-ip):3000/}"
|
2023-03-24 17:42:52 -04:00
|
|
|
|
|
|
|
dependencies
|
2023-04-04 06:51:16 -04:00
|
|
|
download $runner_repository $version
|
2023-03-24 17:42:52 -04:00
|
|
|
register $forgejo
|
|
|
|
run
|
|
|
|
}
|
|
|
|
|
|
|
|
function teardown() {
|
|
|
|
if test -f forgejo-runner-pid ; then
|
2023-03-27 17:30:22 -04:00
|
|
|
kill -TERM $(cat forgejo-runner-pid)
|
2023-03-24 17:42:52 -04:00
|
|
|
rm -f forgejo-runner-pid
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
"$@"
|