From 418489ad4fa5433438e0191ec94bd7ed73f97648 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Wed, 20 Dec 2023 22:22:14 +0100 Subject: [PATCH 1/4] no longer use /usr/local/bin --- .forgejo/workflows/integration-scripts.yml | 2 +- action.yml | 2 +- forgejo-lib.sh | 10 ++++++---- forgejo-runner.sh | 14 +++++++------- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/.forgejo/workflows/integration-scripts.yml b/.forgejo/workflows/integration-scripts.yml index 876fbfe..dce0a49 100644 --- a/.forgejo/workflows/integration-scripts.yml +++ b/.forgejo/workflows/integration-scripts.yml @@ -48,7 +48,7 @@ jobs: LXC_IP_PREFIX=10.0.10 forgejo-dependencies.sh 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-runner.sh setup" forgejo diff --git a/action.yml b/action.yml index 44e27e3..53af620 100644 --- a/action.yml +++ b/action.yml @@ -98,7 +98,7 @@ runs: fi if test "${{ inputs.binary }}"; then 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-runner.sh setup ${{ inputs.runner }} ${{ inputs.runner-version }} $(cat forgejo-url)" forgejo else diff --git a/forgejo-lib.sh b/forgejo-lib.sh index 7269a4c..108ed75 100644 --- a/forgejo-lib.sh +++ b/forgejo-lib.sh @@ -66,16 +66,18 @@ function checkout() { function build_runner() { local git="$1" local version="${2:-main}" - local dir=$(mktemp -d) + local dir="$3" + + local tmp=$(mktemp -d) ( - cd $dir + cd $tmp checkout "$git" dependency_go cd forgejo-runner git checkout "$version" make build ) - mv $dir/forgejo-runner/forgejo-runner /usr/local/bin + mv $tmp/forgejo-runner/forgejo-runner $dir forgejo-runner --version - rm -fr "$dir" + rm -fr "$tmp" } diff --git a/forgejo-runner.sh b/forgejo-runner.sh index cc61d08..68dbc89 100755 --- a/forgejo-runner.sh +++ b/forgejo-runner.sh @@ -20,12 +20,12 @@ function download() { local runner_repository="$1" local version="$2" - if ! which 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 ! which $DIR/forgejo-runner > /dev/null; 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 - 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 - chmod 755 /usr/local/bin/forgejo-runner + chmod 755 $DIR/forgejo-runner fi } @@ -35,7 +35,7 @@ function register() { $DIR/forgejocli actions generate-runner-token | tee $DIR/forgejo-runner-token ( 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 \ --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 -- \ - forgejo-runner --config $FORGEJO_RUNNER_CONFIG daemon + $DIR/forgejo-runner --config $FORGEJO_RUNNER_CONFIG daemon sleep 1 cat $DIR/forgejo-runner.log } @@ -64,7 +64,7 @@ function setup() { dependencies if [[ "$version" =~ ^@ ]] ; then local branch=${version##@} - build_runner $runner_repository $branch + build_runner $runner_repository $branch $DIR else download $runner_repository $version fi From b51343081a7e13ac9f1c826f52f8e251891fbeda Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Wed, 20 Dec 2023 22:22:58 +0100 Subject: [PATCH 2/4] forgejo-runner needs an IP, not localhost for the artifacts server --- forgejo-binary-app.ini | 1 + forgejo-binary.sh | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/forgejo-binary-app.ini b/forgejo-binary-app.ini index b2a6922..4809a61 100644 --- a/forgejo-binary-app.ini +++ b/forgejo-binary-app.ini @@ -3,6 +3,7 @@ WORK_PATH = ${WORK_PATH} [server] APP_DATA_PATH = ${WORK_PATH}/data +DOMAIN = ${IP} HTTP_PORT = 3000 LFS_START_SERVER = true diff --git a/forgejo-binary.sh b/forgejo-binary.sh index 8bb6059..533232e 100755 --- a/forgejo-binary.sh +++ b/forgejo-binary.sh @@ -78,6 +78,10 @@ function create_user() { forgejo-curl.sh api_json $url/api/forgejo/v1/version } +function myip() { + hostname -I | cut -f1 -d' ' +} + function start_forgejo() { 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 @@ -88,7 +92,7 @@ function start_forgejo() { fi echo "$DIR/forgejo --config $work_path/app.ini --work-path $work_path" '"$@"' > $DIR/forgejocli chmod +x $DIR/forgejocli - hostname -I | cut -f1 -d' ' > $DIR/forgejo-ip + myip > $DIR/forgejo-ip } function reset_forgejo() { @@ -96,7 +100,7 @@ function reset_forgejo() { local work_path=$DIR/forgejo-work-path rm -fr $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() { From 65957effd90e6c037d9d95ebffedcf1ea7be6e25 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Wed, 20 Dec 2023 22:24:23 +0100 Subject: [PATCH 3/4] avoid confusing message about non error during teardown --- forgejo-runner.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/forgejo-runner.sh b/forgejo-runner.sh index 68dbc89..35e3e1c 100755 --- a/forgejo-runner.sh +++ b/forgejo-runner.sh @@ -74,7 +74,9 @@ function setup() { function teardown() { 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 } "$@" From 05385ad75ebe8a580631cb5cfcbba9f5a62e5cdb Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Wed, 20 Dec 2023 22:24:48 +0100 Subject: [PATCH 4/4] do not override the DOT variable from forgejo-curl.sh --- forgejo-binary.sh | 1 - forgejo-test-helper.sh | 1 - 2 files changed, 2 deletions(-) diff --git a/forgejo-binary.sh b/forgejo-binary.sh index 533232e..351a136 100755 --- a/forgejo-binary.sh +++ b/forgejo-binary.sh @@ -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 generate-access-token -u "$user" --raw --scopes all > $DIR/forgejo-token - export DOT=$DIR local url="http://$(cat $DIR/forgejo-ip):3000" echo "$url" > $DIR/forgejo-url echo "http://${user}:${password}@$(cat $DIR/forgejo-ip):3000" > $DIR/forgejo-auth-url diff --git a/forgejo-test-helper.sh b/forgejo-test-helper.sh index 85da371..91727af 100755 --- a/forgejo-test-helper.sh +++ b/forgejo-test-helper.sh @@ -10,7 +10,6 @@ source $SELF_DIR/forgejo-lib.sh : ${LOOP_DELAY:=5} WORKDIR=$(mktemp -d) : ${DIR:=$(pwd)} -export DOT=$DIR trap "rm -fr $WORKDIR" EXIT