From 1c9262ada44aa196afbe1a465f65ddd5f7bcfb7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Fr=C3=A9con?= Date: Thu, 28 Mar 2024 15:39:43 +0100 Subject: [PATCH] No separate copy when ephemeral runner is used When the runner is known to be ephemeral, do not copy the content of the runner unpacked distribution to the work directory. Instead, run from there directly and set the RUNNER_BINROOT variable to point to the installation directory. Ensure that the content of the variable is used for deciding where to run the runner from and fix directory tree ownership prior to starting the runner. Rename the label to krun, instead of krunvm. This is to highlight the underlying technology used, rather than how the runners are created. This is a breaking change, but it is not expected to be used in production yet. --- runner/entrypoint.sh | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/runner/entrypoint.sh b/runner/entrypoint.sh index 12835b2..3de6ad2 100755 --- a/runner/entrypoint.sh +++ b/runner/entrypoint.sh @@ -100,6 +100,9 @@ RUNNER_CONTAINERS_CONF="${RUNNER_CONTAINERS_CONFDIR%/}/containers.conf" # Location of the directory where the runner scripts and binaries will log RUNNER_LOGDIR=${RUNNER_LOGDIR:-"/var/log/runner"} +# Default set of labels to attach to the runner when none set +RUNNER_DEFAULT_LABELS=${RUNNER_DEFAULT_LABELS:-"krun"} + # shellcheck disable=SC2034 # Used in sourced scripts KRUNVM_RUNNER_DESCR="Configure and run the installed GitHub runner" @@ -161,13 +164,18 @@ KRUNVM_RUNNER_BIN="${KRUNVM_RUNNER_BIN%.sh}-$RUNNER_ID" # minimal verification of the installation through checking that there is a # config.sh script executable within the copy. runner_install() { - if ! [ -d "${RUNNER_WORKDIR%/}" ]; then - mkdir -p "${RUNNER_WORKDIR%/}" - verbose "Created runner directory ${RUNNER_WORKDIR%/}" + if is_true "$RUNNER_EPHEMERAL"; then + debug "Ephemeral runner: no copy made, running from $RUNNER_INSTDIR" + RUNNER_BINROOT="$RUNNER_INSTDIR" + else + if ! [ -d "${RUNNER_WORKDIR%/}" ]; then + mkdir -p "${RUNNER_WORKDIR%/}" + verbose "Created runner directory ${RUNNER_WORKDIR%/}" + fi + RUNNER_BINROOT="${RUNNER_WORKDIR%/}/runner" + verbose "Copying runner installation to $RUNNER_BINROOT" + cp -rf "$RUNNER_INSTDIR" "$RUNNER_BINROOT" 2>/dev/null fi - RUNNER_BINROOT="${RUNNER_WORKDIR%/}/runner" - verbose "Copying runner installation to $RUNNER_BINROOT" - cp -rf "$RUNNER_INSTDIR" "$RUNNER_BINROOT" 2>/dev/null check_command "${RUNNER_BINROOT}/config.sh" } @@ -403,9 +411,9 @@ RUNNER_NAME=${RUNNER_NAME:-"${RUNNER_PREFIX}-$RUNNER_ID"} RUNNER_WORKDIR=${RUNNER_WORKDIR:-"/_work/${RUNNER_NAME}"} if [ -n "${distro:-}" ]; then - RUNNER_LABELS=${RUNNER_LABELS:-"krunvm,${RUNNER_DISTRO}"} + RUNNER_LABELS=${RUNNER_LABELS:-"${RUNNER_DEFAULT_LABELS%,},${RUNNER_DISTRO}"} else - RUNNER_LABELS=${RUNNER_LABELS:-"krunvm"} + RUNNER_LABELS=${RUNNER_LABELS:-"${RUNNER_DEFAULT_LABELS%,}"} fi # Find the (versioned) directory containing the full installation of the runner @@ -449,7 +457,7 @@ runner_configure if [ "$#" = 0 ]; then warn "No command to run, will take defaults" - set -- "${RUNNER_WORKDIR%/}/runner/bin/Runner.Listener" run --startuptype service + set -- "${RUNNER_BINROOT%/}/bin/Runner.Listener" run --startuptype service fi # Capture termination signals. Pass a boolean to runner_unregister: don't break @@ -480,7 +488,7 @@ case "$RUNNER_USER" in if id "$RUNNER_USER" >/dev/null 2>&1; then if [ "$(id -u)" = "0" ]; then verbose "Starting runner as $RUNNER_USER" - chown -R "$RUNNER_USER" "$RUNNER_WORKDIR" + chown -R "$RUNNER_USER" "$RUNNER_WORKDIR" "$RUNNER_BINROOT" runas "$@" > "$RUNNER_LOGDIR/runner.log" 2>&1 & RUNNER_PID=$! elif [ "$(id -un)" = "$RUNNER_USER" ]; then