diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3309c67..a8ecd8e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -33,3 +33,21 @@ automatically removed as soon as the microVM has booted is running the `runner.sh` script, workflows are not able to break the external loop: they are able to create files in the `/_environment` directory, but they cannot know the value of the secret to put into the file to force the exiting handshake. + +## Changes to the Installation Scripts + +The installation of both images is handled by the [`base.sh`](./base/base.sh) +and [`install.sh`](./runner/install.sh). When making changes to these scripts, +or to the [`docker.sh`](./base/docker.sh) docker CLI wrapper, you will need to +wait for the results of the [`dev.yml`](./.github/workflows/dev.yml) workflow to +finish and for the resulting image to be published at the GHCR before being able +to test. The images will be published for amd64 only and with a tag named after +the name of the branch. Check out the "Inspect image" step of the `merge` job to +collect the fully-qualified name of the image. Once done, provide that name to +the `-i` option of the [`orchestrator.sh`](./orchestrator.sh) script. + +Note that when changing the logic of the "entrypoints", i.e. the scripts run at +microVM initialisation, you do not need to wait for the image to be created. +Instead, pass `-D /local` to the [`orchestrator.sh`](./orchestrator.sh) script. +This will mount the [`runner`](./runner/) directory into the microVM at `/local` +and run the scripts that it contains from there instead. diff --git a/runner/runner.sh b/runner/runner.sh index 95fe4fe..a283b32 100755 --- a/runner/runner.sh +++ b/runner/runner.sh @@ -79,6 +79,9 @@ RUNNER_EPHEMERAL=${RUNNER_EPHEMERAL:-"0"} # Root installation of the runner RUNNER_INSTALL=${RUNNER_INSTALL:-"/opt/gh-runner-krunvm/share/runner"} +# Permit several installations +RUNNER_MULTI=${RUNNER_MULTI:-"0"} + # Should the runner auto-update RUNNER_UPDATE=${RUNNER_UPDATE:-"0"} @@ -153,13 +156,22 @@ 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() { - # Make a directory where to install a copy of the runner. - if ! [ -d "${RUNNER_WORKDIR%/}/runner" ]; then - mkdir -p "${RUNNER_WORKDIR%/}/runner" - verbose "Created runner directory ${RUNNER_WORKDIR%/}/runner" + if [ "$RUNNER_MULTI" = 1 ]; then + # Make a directory where to install a copy of the runner. + if ! [ -d "${RUNNER_WORKDIR%/}/runner" ]; then + mkdir -p "${RUNNER_WORKDIR%/}/runner" + verbose "Created runner directory ${RUNNER_WORKDIR%/}/runner" + fi + verbose "Installing runner in ${RUNNER_WORKDIR%/}/runner" + tar -C "${RUNNER_WORKDIR%/}/runner" -zxf "$RUNNER_TAR" + else + if ! [ -d "${RUNNER_WORKDIR%/}" ]; then + mkdir -p "${RUNNER_WORKDIR%/}" + verbose "Created runner directory ${RUNNER_WORKDIR%/}" + fi + verbose "Moving runner installation to ${RUNNER_WORKDIR%/}/runner" + mv -f "$RUNNER_INSTDIR" "${RUNNER_WORKDIR%/}/runner" 2>/dev/null fi - verbose "Installing runner in ${RUNNER_WORKDIR%/}/runner" - tar -C "${RUNNER_WORKDIR%/}/runner" -zxf "$RUNNER_TAR" check_command "${RUNNER_WORKDIR%/}/runner/config.sh" } @@ -367,10 +379,14 @@ else RUNNER_LABELS=${RUNNER_LABELS:-"krunvm"} fi -RUNNER_TAR=$(find "$RUNNER_INSTALL" -type f -name "*.tgz" | sort -r | head -n 1) +RUNNER_TAR=$(find_pattern "${RUNNER_INSTALL}/*.tgz" f | sort -r | head -n 1) if [ -z "$RUNNER_TAR" ]; then error "No runner tar file found under $RUNNER_INSTALL" fi +RUNNER_INSTDIR=$(find_pattern "${RUNNER_INSTALL}/runner-*" d | sort -r | head -n 1) +if [ -z "$RUNNER_INSTDIR" ]; then + error "No runner installation directory found under $RUNNER_INSTALL" +fi # Construct the runner URL, i.e. where the runner will be registered RUNNER_SCOPE=$(to_lower "$RUNNER_SCOPE")