Merge pull request 'forgejo-runner needs an IP, not localhost for the artifacts server' (#110) from earl-warren/setup-forgejo:wip-cleanup into main

Reviewed-on: https://code.forgejo.org/actions/setup-forgejo/pulls/110
Reviewed-by: dachary <dachary@noreply.code.forgejo.org>
This commit is contained in:
earl-warren 2023-12-20 21:47:49 +00:00
commit 0720d52456
7 changed files with 25 additions and 18 deletions

View file

@ -48,7 +48,7 @@ jobs:
LXC_IP_PREFIX=10.0.10 forgejo-dependencies.sh LXC_IP_PREFIX=10.0.10 forgejo-dependencies.sh
forgejo-binary.sh ensure_user forgejo forgejo-binary.sh ensure_user forgejo
chown forgejo $DIR /usr/local/bin chown forgejo $DIR
su -c "DIR=$DIR bash -x forgejo-binary.sh setup root admin1234 ${{ matrix.binary }}" forgejo su -c "DIR=$DIR bash -x forgejo-binary.sh setup root admin1234 ${{ matrix.binary }}" forgejo
su -c "DIR=$DIR bash -x forgejo-runner.sh setup" forgejo su -c "DIR=$DIR bash -x forgejo-runner.sh setup" forgejo

View file

@ -98,7 +98,7 @@ runs:
fi fi
if test "${{ inputs.binary }}"; then if test "${{ inputs.binary }}"; then
forgejo-binary.sh ensure_user forgejo forgejo-binary.sh ensure_user forgejo
chown forgejo $(pwd) /usr/local/bin chown forgejo $(pwd)
su -c "DIR=$(pwd) forgejo-binary.sh setup ${{ inputs.user }} ${{ inputs.password }} ${{ inputs.binary }}" forgejo su -c "DIR=$(pwd) forgejo-binary.sh setup ${{ inputs.user }} ${{ inputs.password }} ${{ inputs.binary }}" forgejo
su -c "DIR=$(pwd) forgejo-runner.sh setup ${{ inputs.runner }} ${{ inputs.runner-version }} $(cat forgejo-url)" forgejo su -c "DIR=$(pwd) forgejo-runner.sh setup ${{ inputs.runner }} ${{ inputs.runner-version }} $(cat forgejo-url)" forgejo
else else

View file

@ -3,6 +3,7 @@ WORK_PATH = ${WORK_PATH}
[server] [server]
APP_DATA_PATH = ${WORK_PATH}/data APP_DATA_PATH = ${WORK_PATH}/data
DOMAIN = ${IP}
HTTP_PORT = 3000 HTTP_PORT = 3000
LFS_START_SERVER = true LFS_START_SERVER = true

View file

@ -69,7 +69,6 @@ function create_user() {
$DIR/forgejocli admin user create --admin --username "$user" --password "$password" --email "$user@example.com" $DIR/forgejocli admin user create --admin --username "$user" --password "$password" --email "$user@example.com"
$DIR/forgejocli admin user generate-access-token -u "$user" --raw --scopes all > $DIR/forgejo-token $DIR/forgejocli admin user generate-access-token -u "$user" --raw --scopes all > $DIR/forgejo-token
export DOT=$DIR
local url="http://$(cat $DIR/forgejo-ip):3000" local url="http://$(cat $DIR/forgejo-ip):3000"
echo "$url" > $DIR/forgejo-url echo "$url" > $DIR/forgejo-url
echo "http://${user}:${password}@$(cat $DIR/forgejo-ip):3000" > $DIR/forgejo-auth-url echo "http://${user}:${password}@$(cat $DIR/forgejo-ip):3000" > $DIR/forgejo-auth-url
@ -78,6 +77,10 @@ function create_user() {
forgejo-curl.sh api_json $url/api/forgejo/v1/version forgejo-curl.sh api_json $url/api/forgejo/v1/version
} }
function myip() {
hostname -I | cut -f1 -d' '
}
function start_forgejo() { function start_forgejo() {
local work_path=$DIR/forgejo-work-path local work_path=$DIR/forgejo-work-path
daemon --chdir=$DIR --unsafe --env="TERM=$TERM" --env="HOME=$HOME" --env="PATH=$PATH" --pidfile=$DIR/forgejo-pid --errlog=$DIR/forgejo-err.log --output=$DIR/forgejo-out.log -- $DIR/forgejo --config $work_path/app.ini --work-path $work_path daemon --chdir=$DIR --unsafe --env="TERM=$TERM" --env="HOME=$HOME" --env="PATH=$PATH" --pidfile=$DIR/forgejo-pid --errlog=$DIR/forgejo-err.log --output=$DIR/forgejo-out.log -- $DIR/forgejo --config $work_path/app.ini --work-path $work_path
@ -88,7 +91,7 @@ function start_forgejo() {
fi fi
echo "$DIR/forgejo --config $work_path/app.ini --work-path $work_path" '"$@"' > $DIR/forgejocli echo "$DIR/forgejo --config $work_path/app.ini --work-path $work_path" '"$@"' > $DIR/forgejocli
chmod +x $DIR/forgejocli chmod +x $DIR/forgejocli
hostname -I | cut -f1 -d' ' > $DIR/forgejo-ip myip > $DIR/forgejo-ip
} }
function reset_forgejo() { function reset_forgejo() {
@ -96,7 +99,7 @@ function reset_forgejo() {
local work_path=$DIR/forgejo-work-path local work_path=$DIR/forgejo-work-path
rm -fr $work_path rm -fr $work_path
mkdir -p $work_path mkdir -p $work_path
WORK_PATH=$work_path envsubst < $SELF_DIR/$config-app.ini > $work_path/app.ini IP=$(myip) WORK_PATH=$work_path envsubst < $SELF_DIR/$config-app.ini > $work_path/app.ini
} }
function teardown() { function teardown() {

View file

@ -66,16 +66,18 @@ function checkout() {
function build_runner() { function build_runner() {
local git="$1" local git="$1"
local version="${2:-main}" local version="${2:-main}"
local dir=$(mktemp -d) local dir="$3"
local tmp=$(mktemp -d)
( (
cd $dir cd $tmp
checkout "$git" checkout "$git"
dependency_go dependency_go
cd forgejo-runner cd forgejo-runner
git checkout "$version" git checkout "$version"
make build make build
) )
mv $dir/forgejo-runner/forgejo-runner /usr/local/bin mv $tmp/forgejo-runner/forgejo-runner $dir
forgejo-runner --version forgejo-runner --version
rm -fr "$dir" rm -fr "$tmp"
} }

View file

@ -20,12 +20,12 @@ function download() {
local runner_repository="$1" local runner_repository="$1"
local version="$2" local version="$2"
if ! which forgejo-runner > /dev/null; then if ! which $DIR/forgejo-runner > /dev/null; then
if ! curl -L --fail -sS $runner_repository/releases/download/$version/forgejo-runner-${version#v}-linux-amd64 > /usr/local/bin/forgejo-runner ; then if ! curl -L --fail -sS $runner_repository/releases/download/$version/forgejo-runner-${version#v}-linux-amd64 > $DIR/forgejo-runner ; then
# backward compatibility for for the naming scheme prior to 3.0.0 # backward compatibility for for the naming scheme prior to 3.0.0
curl -L --fail -sS $runner_repository/releases/download/$version/forgejo-runner-linux-amd64 > /usr/local/bin/forgejo-runner curl -L --fail -sS $runner_repository/releases/download/$version/forgejo-runner-linux-amd64 > $DIR/forgejo-runner
fi fi
chmod 755 /usr/local/bin/forgejo-runner chmod 755 $DIR/forgejo-runner
fi fi
} }
@ -35,7 +35,7 @@ function register() {
$DIR/forgejocli actions generate-runner-token | tee $DIR/forgejo-runner-token $DIR/forgejocli actions generate-runner-token | tee $DIR/forgejo-runner-token
( (
cd $DIR cd $DIR
timeout --signal=KILL 30 forgejo-runner register --no-interactive --instance "$forgejo" --name runner --token $(cat $DIR/forgejo-runner-token) --labels docker:docker://code.forgejo.org/oci/node:20-bookworm,ubuntu-latest:docker://code.forgejo.org/oci/node:20-bookworm,self-hosted:lxc://debian:bookworm timeout --signal=KILL 30 $DIR/forgejo-runner register --no-interactive --instance "$forgejo" --name runner --token $(cat $DIR/forgejo-runner-token) --labels docker:docker://code.forgejo.org/oci/node:20-bookworm,ubuntu-latest:docker://code.forgejo.org/oci/node:20-bookworm,self-hosted:lxc://debian:bookworm
) )
} }
@ -44,7 +44,7 @@ function run() {
daemon --chdir=$DIR --unsafe \ daemon --chdir=$DIR --unsafe \
--env="TERM=$TERM" --env="HOME=$(cat $DIR/forgejo-runner-home)" --env="PATH=$PATH" --env="USER=$USER" --env="TERM=dumb" --env="USERNAME=$USERNAME" --env="LANG=$LANG" \ --env="TERM=$TERM" --env="HOME=$(cat $DIR/forgejo-runner-home)" --env="PATH=$PATH" --env="USER=$USER" --env="TERM=dumb" --env="USERNAME=$USERNAME" --env="LANG=$LANG" \
--pidfile=$DIR/forgejo-runner-pid --errlog=$DIR/forgejo-runner.log --output=$DIR/forgejo-runner.log -- \ --pidfile=$DIR/forgejo-runner-pid --errlog=$DIR/forgejo-runner.log --output=$DIR/forgejo-runner.log -- \
forgejo-runner --config $FORGEJO_RUNNER_CONFIG daemon $DIR/forgejo-runner --config $FORGEJO_RUNNER_CONFIG daemon
sleep 1 sleep 1
cat $DIR/forgejo-runner.log cat $DIR/forgejo-runner.log
} }
@ -64,7 +64,7 @@ function setup() {
dependencies dependencies
if [[ "$version" =~ ^@ ]] ; then if [[ "$version" =~ ^@ ]] ; then
local branch=${version##@} local branch=${version##@}
build_runner $runner_repository $branch build_runner $runner_repository $branch $DIR
else else
download $runner_repository $version download $runner_repository $version
fi fi
@ -74,7 +74,9 @@ function setup() {
function teardown() { function teardown() {
stop_daemon forgejo-runner $DIR stop_daemon forgejo-runner $DIR
rm -fr $(cat $DIR/forgejo-runner-home) if test -f $DIR/forgejo-runner-home ; then
rm -fr $(cat $DIR/forgejo-runner-home)
fi
} }
"$@" "$@"

View file

@ -10,7 +10,6 @@ source $SELF_DIR/forgejo-lib.sh
: ${LOOP_DELAY:=5} : ${LOOP_DELAY:=5}
WORKDIR=$(mktemp -d) WORKDIR=$(mktemp -d)
: ${DIR:=$(pwd)} : ${DIR:=$(pwd)}
export DOT=$DIR
trap "rm -fr $WORKDIR" EXIT trap "rm -fr $WORKDIR" EXIT