2023-03-24 17:42:52 -04:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -ex
|
|
|
|
|
|
|
|
function dependencies() {
|
|
|
|
if ! which go > /dev/null ; then
|
|
|
|
apt-get update
|
|
|
|
apt-get install -y -qq wget tar
|
|
|
|
wget https://go.dev/dl/go1.20.2.linux-amd64.tar.gz
|
|
|
|
tar zxf go1.20.2.linux-amd64.tar.gz
|
|
|
|
export PATH=$PATH:$(pwd)/go/bin
|
|
|
|
fi
|
2023-03-27 17:30:22 -04:00
|
|
|
if ! which make daemon > /dev/null ; then
|
|
|
|
apt-get install -y -qq make daemon
|
2023-03-24 17:42:52 -04:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkout() {
|
|
|
|
local git="$1"
|
|
|
|
if ! test -d forgejo-runner ; then
|
|
|
|
git clone $git forgejo-runner
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function build() {
|
|
|
|
local version="$1"
|
|
|
|
|
|
|
|
(
|
|
|
|
cd forgejo-runner
|
|
|
|
git checkout $version
|
|
|
|
make build
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function register() {
|
|
|
|
local forgejo="$1"
|
|
|
|
docker exec --user 1000 forgejo forgejo actions --registration-token-admin > forgejo-runner-token
|
2023-03-25 11:06:50 -04:00
|
|
|
timeout --signal=KILL 30 ./forgejo-runner/forgejo-runner register --no-interactive --instance "$forgejo" --name runner --token $(cat forgejo-runner-token) --labels ubuntu-latest:docker://node:16-buster,self-hosted
|
2023-03-24 17:42:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function run() {
|
2023-03-27 17:30:22 -04:00
|
|
|
daemon --chdir=$(pwd) --unsafe --pidfile=$(pwd)/forgejo-runner-pid --errlog=$(pwd)/forgejo-runner.log --output=$(pwd)/forgejo-runner.log ./forgejo-runner/forgejo-runner 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() {
|
|
|
|
local git="${1:-https://codeberg.org/forgejo/runner}"
|
2023-03-27 13:39:19 -04:00
|
|
|
local version="${2:-v1.4.1}"
|
|
|
|
local forgejo="${3:-http://$(cat forgejo-ip):3000/}"
|
2023-03-24 17:42:52 -04:00
|
|
|
|
|
|
|
dependencies
|
|
|
|
checkout $git
|
|
|
|
build $version
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
"$@"
|