diff --git a/base/base.sh b/base/base.sh index 8d1d195..beaa72d 100755 --- a/base/base.sh +++ b/base/base.sh @@ -54,7 +54,7 @@ BASE_DOCKER_WRAPPER=${BASE_DOCKER_WRAPPER:-$BASE_ROOTDIR/docker.sh} . "$BASE_ROOTDIR/../lib/common.sh" # shellcheck disable=SC2034 # Used in sourced scripts -KRUNVM_RUNNER_MAIN="Install a base GitHub runner environment in Fedora" +KRUNVM_RUNNER_DESCR="Install a base GitHub runner environment in Fedora" while getopts "dl:vh-" opt; do case "$opt" in diff --git a/lib/common.sh b/lib/common.sh index a0dadc6..a65684b 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -39,7 +39,7 @@ random_string() { usage() { # This uses the comments behind the options to show the help. Not extremly # correct, but effective and simple. - echo "$0 -- ${KRUNVM_RUNNER_MAIN:-"Part of the gh-krunvm-runner project"}" && \ + echo "$0 -- ${KRUNVM_RUNNER_DESCR:-"Part of the gh-krunvm-runner project"}" && \ grep "[[:space:]].) #" "$0" | sed 's/#//' | sed -r 's/([a-zA-Z-])\)/-\1/' @@ -75,9 +75,13 @@ run_krunvm() { _log() { # Capture level and shift it away, rest will be passed blindly to printf _lvl=${1:-LOG}; shift + if [ -z "${KRUNVM_RUNNER_BIN:-}" ]; then + KRUNVM_RUNNER_BIN=$(basename "$0") + KRUNVM_RUNNER_BIN=${KRUNVM_RUNNER_BIN%.sh} + fi # shellcheck disable=SC2059 # We want to expand the format string printf '[%s] [%s] [%s] %s\n' \ - "$(basename "$0")" \ + "${KRUNVM_RUNNER_BIN:-$(basename "$0")}" \ "$_lvl" \ "$(date +'%Y%m%d-%H%M%S')" \ "$(printf "$@")" \ diff --git a/orchestrator.sh b/orchestrator.sh index 1f769e2..5a3ed89 100755 --- a/orchestrator.sh +++ b/orchestrator.sh @@ -98,7 +98,7 @@ RUNNER_UPDATE=${RUNNER_UPDATE:-"0"} . "$ORCHESTRATOR_ROOTDIR/lib/common.sh" # shellcheck disable=SC2034 # Used in sourced scripts -KRUNVM_RUNNER_MAIN="Run several krunvm-based GitHub runners on a single host" +KRUNVM_RUNNER_DESCR="Run several krunvm-based GitHub runners on a single host" while getopts "c:d:D:g:G:i:Il:L:m:M:n:p:s:t:T:u:Uvh-" opt; do @@ -238,7 +238,8 @@ for i in $(seq 1 "$runners"); do "$ORCHESTRATOR_ROOTDIR/runner.sh" \ -n "$ORCHESTRATOR_NAME" \ -D "$ORCHESTRATOR_DIR" \ - -E "${ORCHESTRATOR_ENVIRONMENT:-}" & + -E "${ORCHESTRATOR_ENVIRONMENT:-}" \ + -- "$i" & set -- "$@" "$!" fi done diff --git a/runner.sh b/runner.sh index 7a5897c..534334c 100755 --- a/runner.sh +++ b/runner.sh @@ -83,7 +83,7 @@ RUNNER_EPHEMERAL=${RUNNER_EPHEMERAL:-"1"} . "$RUNNER_ROOTDIR/lib/common.sh" # shellcheck disable=SC2034 # Used in sourced scripts -KRUNVM_RUNNER_MAIN="Create runners forever using krunvm" +KRUNVM_RUNNER_DESCR="Create runners forever using krunvm" while getopts "D:E:g:G:l:L:M:n:p:s:T:u:Uvh-" opt; do @@ -118,6 +118,8 @@ while getopts "D:E:g:G:l:L:M:n:p:s:T:u:Uvh-" opt; do RUNNER_VERBOSE=$((RUNNER_VERBOSE+1));; h) # Print help and exit usage;; + -) # End of options, follows the identifier of the runner, if any + break;; ?) usage 1;; esac @@ -127,6 +129,11 @@ shift $((OPTIND-1)) # Pass logging configuration and level to imported scripts KRUNVM_RUNNER_LOG=$RUNNER_LOG KRUNVM_RUNNER_VERBOSE=$RUNNER_VERBOSE +loop=${1:-} +if [ -n "${loop:-}" ]; then + KRUNVM_RUNNER_BIN=$(basename "$0") + KRUNVM_RUNNER_BIN="${KRUNVM_RUNNER_BIN%.sh}-$loop" +fi # Decide which runner.sh implementation (this is the "entrypoint" of the # microVM) to use: the one from the mount point, or the built-in one. @@ -138,25 +145,27 @@ else fi while true; do - verbose "Starting microVM $RUNNER_NAME to run an ephemeral GitHub runner" + id=$(random_string) + RUNNER_ID=${loop}-${id} + verbose "Starting microVM $RUNNER_NAME to run ephemeral GitHub runner $RUNNER_ID" if [ -n "$RUNNER_ENVIRONMENT" ]; then # Create an env file with most of the RUNNER_ variables. This works because # the `runner.sh` script that will be called uses the same set of variables. - id=$(random_string) - verbose "Creating isolation environment ${RUNNER_ENVIRONMENT}/${id}.env" + verbose "Creating isolation environment ${RUNNER_ENVIRONMENT}/${RUNNER_ID}.env" while IFS= read -r varset; do # shellcheck disable=SC2163 # We want to expand the variable - printf '%s\n' "$varset" >> "${RUNNER_ENVIRONMENT}/${id}.env" + printf '%s\n' "$varset" >> "${RUNNER_ENVIRONMENT}/${RUNNER_ID}.env" done <