setup-forgejo/forgejo-runner.sh

66 lines
1.5 KiB
Bash
Raw Normal View History

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
if ! which make > /dev/null ; then
apt-get install -y -qq make
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() {
./forgejo-runner/forgejo-runner daemon >& forgejo-runner.log &
echo $! > forgejo-runner-pid
}
function setup() {
local git="${1:-https://codeberg.org/forgejo/runner}"
local version="${1:-v1.4.1}"
2023-03-25 09:34:41 -04:00
local forgejo="${1:-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
kill -9 $(cat forgejo-runner-pid)
rm -f forgejo-runner-pid
fi
}
"$@"