From bd301103c458f5d22aba603b6c783e23f60eb265 Mon Sep 17 00:00:00 2001 From: casjay Date: Fri, 5 Jun 2026 13:14:39 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20REPLACE=5F*=20token=20subs?= =?UTF-8?q?titution=20in=20config=20files=20=F0=9F=90=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two substitution bugs fixed: act_runner (zz-act_runner.sh): - REPLACE_RUNNER_* tokens were only substituted inside the registration block (guarded by SYS_AUTH_TOKEN + runners file absence). If gitea wasn't ready on first boot, the file was copied with tokens intact and never substituted on subsequent boots. - Fix: substitute tokens immediately after copy, unconditionally. Registration logic remains gated on auth token availability. gitea app.ini (08-gitea.sh): - REPLACE_SERVER_NAME and REPLACE_SERVER_PROTO had no matching env vars — the script used HOSTNAME and SERVICE_PROTOCOL instead, so __initialize_replace_variables left those tokens unsubstituted. - Fix: export SERVER_NAME="${DOMAIN:-$HOSTNAME}" and SERVER_PROTO="${SERVICE_PROTOCOL:-http}" as aliases after the HOSTNAME chain is resolved. - rootfs/usr/local/etc/docker/init.d/08-gitea.sh: add SERVER_NAME and SERVER_PROTO aliases for token substitution - rootfs/usr/local/etc/docker/init.d/zz-act_runner.sh: move REPLACE_ substitution outside registration guard rootfs/usr/local/etc/docker/init.d/08-gitea.sh rootfs/usr/local/etc/docker/init.d/zz-act_runner.sh --- rootfs/usr/local/etc/docker/init.d/08-gitea.sh | 3 +++ rootfs/usr/local/etc/docker/init.d/zz-act_runner.sh | 11 ++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/rootfs/usr/local/etc/docker/init.d/08-gitea.sh b/rootfs/usr/local/etc/docker/init.d/08-gitea.sh index 5eefa36..0370d29 100755 --- a/rootfs/usr/local/etc/docker/init.d/08-gitea.sh +++ b/rootfs/usr/local/etc/docker/init.d/08-gitea.sh @@ -253,6 +253,9 @@ GITEA_SQL_USER="${ENV_GITEA_SQL_USER:-$GITEA_SQL_USER}" GITEA_SQL_PASS="${ENV_GITEA_SQL_PASS:-$GITEA_SQL_PASS}" GITEA_SQL_TYPE="${ENV_GITEA_SQL_TYPE:-${GITEA_SQL_TYPE:-sqlite3}}" HOSTNAME="${GITEA_SERVER:-${GITEA_HOSTNAME:-${FULL_DOMAIN_NAME:-$(hostname -f 2>/dev/null || echo "$HOSTNAME")}}}" +# Aliases so __initialize_replace_variables can substitute REPLACE_SERVER_NAME and REPLACE_SERVER_PROTO +SERVER_NAME="${DOMAIN:-$HOSTNAME}" +SERVER_PROTO="${SERVICE_PROTOCOL:-http}" GITEA_SECRET_KEY="${GITEA_SECRET_KEY:-$(__random_password 32)}" GITEA_LFS_JWT_SECRET="${GITEA_LFS_JWT_SECRET:-$($EXEC_CMD_BIN generate secret LFS_JWT_SECRET)}" GITEA_INTERNAL_TOKEN="${GITEA_INTERNAL_TOKEN:-$($EXEC_CMD_BIN generate secret INTERNAL_TOKEN)}" diff --git a/rootfs/usr/local/etc/docker/init.d/zz-act_runner.sh b/rootfs/usr/local/etc/docker/init.d/zz-act_runner.sh index 76658c4..c008181 100755 --- a/rootfs/usr/local/etc/docker/init.d/zz-act_runner.sh +++ b/rootfs/usr/local/etc/docker/init.d/zz-act_runner.sh @@ -367,12 +367,13 @@ __run_pre_execute_checks() { if [ -f "$RUNNER_CONFIG_DEFAULT" ]; then mkdir -p "$RUNNER_DEFAULT_HOME" "$TMP_DIR/runners/gitea" [ -f "$RUNNER_DEFAULT_HOME/$RUNNER_CONFIG_NAME" ] || copy "$RUNNER_CONFIG_DEFAULT" "$RUNNER_DEFAULT_HOME/$RUNNER_CONFIG_NAME" - if [ ! -f "$RUNNER_DEFAULT_HOME/runners" ] && [ -n "$SYS_AUTH_TOKEN" ] && [ -f "$RUNNER_DEFAULT_HOME/$RUNNER_CONFIG_NAME" ]; then + # Always substitute tokens immediately after copy, regardless of registration state + __replace "REPLACE_RUNNER_TEMP" "$TMP_DIR/runners/gitea" "$RUNNER_DEFAULT_HOME/$RUNNER_CONFIG_NAME" + __replace "REPLACE_RUNNER_HOME" "$RUNNER_DEFAULT_HOME" "$RUNNER_DEFAULT_HOME/$RUNNER_CONFIG_NAME" + __replace "REPLACE_RUNNER_CACHE_HOST" "$RUNNER_CACHE_HOST" "$RUNNER_DEFAULT_HOME/$RUNNER_CONFIG_NAME" + __replace "REPLACE_RUNNER_CACHE_PORT" "$RUNNER_CACHE_PORT" "$RUNNER_DEFAULT_HOME/$RUNNER_CONFIG_NAME" + if [ ! -f "$RUNNER_DEFAULT_HOME/runners" ] && [ -n "$SYS_AUTH_TOKEN" ]; then echo "creating gitea runner in $RUNNER_DEFAULT_HOME and registering with http://$INSTANCE_HOSTNAME" - __replace "REPLACE_RUNNER_TEMP" "$TMP_DIR/runners/gitea" "$RUNNER_DEFAULT_HOME/$RUNNER_CONFIG_NAME" - __replace "REPLACE_RUNNER_HOME" "$RUNNER_DEFAULT_HOME" "$RUNNER_DEFAULT_HOME/$RUNNER_CONFIG_NAME" - __replace "REPLACE_RUNNER_CACHE_HOST" "$RUNNER_CACHE_HOST" "$RUNNER_DEFAULT_HOME/$RUNNER_CONFIG_NAME" - __replace "REPLACE_RUNNER_CACHE_PORT" "$RUNNER_CACHE_PORT" "$RUNNER_DEFAULT_HOME/$RUNNER_CONFIG_NAME" act_runner register --config "$RUNNER_DEFAULT_HOME/$RUNNER_CONFIG_NAME" --labels "$RUNNER_LABELS" --name "gitea" --instance "http://$RUNNER_IP_ADDRESS:$GITEA_PORT" --token "$SYS_AUTH_TOKEN" --no-interactive >>"$RUNNER_LOG_FILE" 2>&1 & echo $! >"$RUN_DIR/act_runner.gitea.pid" fi