From f92200ae81ccc22b5524d7b4a29dd342a93c5be3 Mon Sep 17 00:00:00 2001 From: Yusuke Kuoka Date: Tue, 23 May 2023 01:46:21 +0000 Subject: [PATCH 1/3] Enhance ARC runner image dockerfiles for RunnerScaleSet compatibility --- ...nner-dind-rootless.ubuntu-20.04.dockerfile | 4 +- ...nner-dind-rootless.ubuntu-22.04.dockerfile | 4 +- ...ctions-runner-dind.ubuntu-20.04.dockerfile | 4 +- ...ctions-runner-dind.ubuntu-22.04.dockerfile | 4 +- runner/actions-runner.ubuntu-20.04.dockerfile | 7 +- runner/actions-runner.ubuntu-22.04.dockerfile | 8 +- runner/startup.sh | 105 ++++++++++-------- 7 files changed, 83 insertions(+), 53 deletions(-) diff --git a/runner/actions-runner-dind-rootless.ubuntu-20.04.dockerfile b/runner/actions-runner-dind-rootless.ubuntu-20.04.dockerfile index bc84f460..9fa0a298 100644 --- a/runner/actions-runner-dind-rootless.ubuntu-20.04.dockerfile +++ b/runner/actions-runner-dind-rootless.ubuntu-20.04.dockerfile @@ -77,7 +77,9 @@ RUN export ARCH=$(echo ${TARGETPLATFORM} | cut -d / -f2) \ && curl -fLo /usr/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v${DUMB_INIT_VERSION}/dumb-init_${DUMB_INIT_VERSION}_${ARCH} \ && chmod +x /usr/bin/dumb-init -ENV RUNNER_ASSETS_DIR=/runnertmp +# Set this to /home/runner for compatibility with v1 runners +ARG RUNNER_ASSETS_DIR=/runnertmp +ENV RUNNER_ASSETS_DIR=$RUNNER_ASSETS_DIR RUN export ARCH=$(echo ${TARGETPLATFORM} | cut -d / -f2) \ && if [ "$ARCH" = "amd64" ] || [ "$ARCH" = "x86_64" ] || [ "$ARCH" = "i386" ]; then export ARCH=x64 ; fi \ && mkdir -p "$RUNNER_ASSETS_DIR" \ diff --git a/runner/actions-runner-dind-rootless.ubuntu-22.04.dockerfile b/runner/actions-runner-dind-rootless.ubuntu-22.04.dockerfile index 6fafdb5c..91794744 100644 --- a/runner/actions-runner-dind-rootless.ubuntu-22.04.dockerfile +++ b/runner/actions-runner-dind-rootless.ubuntu-22.04.dockerfile @@ -54,7 +54,9 @@ RUN export ARCH=$(echo ${TARGETPLATFORM} | cut -d / -f2) \ && curl -fLo /usr/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v${DUMB_INIT_VERSION}/dumb-init_${DUMB_INIT_VERSION}_${ARCH} \ && chmod +x /usr/bin/dumb-init -ENV RUNNER_ASSETS_DIR=/runnertmp +# Set this to /home/runner for compatibility with v1 runners +ARG RUNNER_ASSETS_DIR=/runnertmp +ENV RUNNER_ASSETS_DIR=$RUNNER_ASSETS_DIR RUN export ARCH=$(echo ${TARGETPLATFORM} | cut -d / -f2) \ && if [ "$ARCH" = "amd64" ] || [ "$ARCH" = "x86_64" ] || [ "$ARCH" = "i386" ]; then export ARCH=x64 ; fi \ && mkdir -p "$RUNNER_ASSETS_DIR" \ diff --git a/runner/actions-runner-dind.ubuntu-20.04.dockerfile b/runner/actions-runner-dind.ubuntu-20.04.dockerfile index 2b60c37c..e8ca8a9f 100644 --- a/runner/actions-runner-dind.ubuntu-20.04.dockerfile +++ b/runner/actions-runner-dind.ubuntu-20.04.dockerfile @@ -72,7 +72,9 @@ RUN export ARCH=$(echo ${TARGETPLATFORM} | cut -d / -f2) \ && curl -fLo /usr/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v${DUMB_INIT_VERSION}/dumb-init_${DUMB_INIT_VERSION}_${ARCH} \ && chmod +x /usr/bin/dumb-init -ENV RUNNER_ASSETS_DIR=/runnertmp +# Set this to /home/runner for compatibility with v1 runners +ARG RUNNER_ASSETS_DIR=/runnertmp +ENV RUNNER_ASSETS_DIR=$RUNNER_ASSETS_DIR RUN export ARCH=$(echo ${TARGETPLATFORM} | cut -d / -f2) \ && if [ "$ARCH" = "amd64" ] || [ "$ARCH" = "x86_64" ] || [ "$ARCH" = "i386" ]; then export ARCH=x64 ; fi \ && mkdir -p "$RUNNER_ASSETS_DIR" \ diff --git a/runner/actions-runner-dind.ubuntu-22.04.dockerfile b/runner/actions-runner-dind.ubuntu-22.04.dockerfile index 25ad586c..ad75c84b 100644 --- a/runner/actions-runner-dind.ubuntu-22.04.dockerfile +++ b/runner/actions-runner-dind.ubuntu-22.04.dockerfile @@ -48,7 +48,9 @@ RUN export ARCH=$(echo ${TARGETPLATFORM} | cut -d / -f2) \ && curl -fLo /usr/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v${DUMB_INIT_VERSION}/dumb-init_${DUMB_INIT_VERSION}_${ARCH} \ && chmod +x /usr/bin/dumb-init -ENV RUNNER_ASSETS_DIR=/runnertmp +# Set this to /home/runner for compatibility with v1 runners +ARG RUNNER_ASSETS_DIR=/runnertmp +ENV RUNNER_ASSETS_DIR=$RUNNER_ASSETS_DIR RUN export ARCH=$(echo ${TARGETPLATFORM} | cut -d / -f2) \ && if [ "$ARCH" = "amd64" ] || [ "$ARCH" = "x86_64" ] || [ "$ARCH" = "i386" ]; then export ARCH=x64 ; fi \ && mkdir -p "$RUNNER_ASSETS_DIR" \ diff --git a/runner/actions-runner.ubuntu-20.04.dockerfile b/runner/actions-runner.ubuntu-20.04.dockerfile index 2683d47f..c5cfeb12 100644 --- a/runner/actions-runner.ubuntu-20.04.dockerfile +++ b/runner/actions-runner.ubuntu-20.04.dockerfile @@ -68,7 +68,10 @@ RUN export ARCH=$(echo ${TARGETPLATFORM} | cut -d / -f2) \ && curl -fLo /usr/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v${DUMB_INIT_VERSION}/dumb-init_${DUMB_INIT_VERSION}_${ARCH} \ && chmod +x /usr/bin/dumb-init -ENV RUNNER_ASSETS_DIR=/runnertmp +# Set this to /home/runner for compatibility with v1 runners +ARG RUNNER_ASSETS_DIR=/runnertmp +ENV RUNNER_ASSETS_DIR=$RUNNER_ASSETS_DIR +ARG EXTERNALS_DIR_NAME=externalstmp RUN export ARCH=$(echo ${TARGETPLATFORM} | cut -d / -f2) \ && if [ "$ARCH" = "amd64" ] || [ "$ARCH" = "x86_64" ] || [ "$ARCH" = "i386" ]; then export ARCH=x64 ; fi \ && mkdir -p "$RUNNER_ASSETS_DIR" \ @@ -77,7 +80,7 @@ RUN export ARCH=$(echo ${TARGETPLATFORM} | cut -d / -f2) \ && tar xzf ./runner.tar.gz \ && rm runner.tar.gz \ && ./bin/installdependencies.sh \ - && mv ./externals ./externalstmp \ + && if [ "${EXTERNALS_DIR_NAME}" != externals ]; then mv ./externals ./${EXTERNALS_DIR_NAME}; fi \ # libyaml-dev is required for ruby/setup-ruby action. # It is installed after installdependencies.sh and before removing /var/lib/apt/lists # to avoid rerunning apt-update on its own. diff --git a/runner/actions-runner.ubuntu-22.04.dockerfile b/runner/actions-runner.ubuntu-22.04.dockerfile index a85833b2..3112f86b 100644 --- a/runner/actions-runner.ubuntu-22.04.dockerfile +++ b/runner/actions-runner.ubuntu-22.04.dockerfile @@ -45,7 +45,11 @@ RUN export ARCH=$(echo ${TARGETPLATFORM} | cut -d / -f2) \ && curl -fLo /usr/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v${DUMB_INIT_VERSION}/dumb-init_${DUMB_INIT_VERSION}_${ARCH} \ && chmod +x /usr/bin/dumb-init -ENV RUNNER_ASSETS_DIR=/runnertmp +# Set this to /home/runner for compatibility with v1 runners +ARG RUNNER_ASSETS_DIR=/runnertmp +ENV RUNNER_ASSETS_DIR=$RUNNER_ASSETS_DIR +# Set this to "externals" for compatibility with v1 runners +ARG EXTERNALS_DIR_NAME=externalstmp RUN export ARCH=$(echo ${TARGETPLATFORM} | cut -d / -f2) \ && if [ "$ARCH" = "amd64" ] || [ "$ARCH" = "x86_64" ] || [ "$ARCH" = "i386" ]; then export ARCH=x64 ; fi \ && mkdir -p "$RUNNER_ASSETS_DIR" \ @@ -54,7 +58,7 @@ RUN export ARCH=$(echo ${TARGETPLATFORM} | cut -d / -f2) \ && tar xzf ./runner.tar.gz \ && rm runner.tar.gz \ && ./bin/installdependencies.sh \ - && mv ./externals ./externalstmp \ + && if [ "${EXTERNALS_DIR_NAME}" != externals ]; then mv ./externals ./${EXTERNALS_DIR_NAME}; fi \ # libyaml-dev is required for ruby/setup-ruby action. # It is installed after installdependencies.sh and before removing /var/lib/apt/lists # to avoid rerunning apt-update on its own. diff --git a/runner/startup.sh b/runner/startup.sh index de60ff5f..e0717ff2 100755 --- a/runner/startup.sh +++ b/runner/startup.sh @@ -88,58 +88,73 @@ if [ "${DISABLE_RUNNER_UPDATE:-}" == "true" ]; then log.debug 'Passing --disableupdate to config.sh to disable automatic runner updates.' fi -update-status "Registering" +# This is for registering ARC v0 runners. +# ARC v1 runners do not need config.sh for registering themselves. +# ARC v1 runners are supposed to given the ACTIONS_RUNNER_INPUT_JITCONFIG envvars +# so we use it as the trigger to skip config.sh. +if [ -z "${ACTIONS_RUNNER_INPUT_JITCONFIG:-}" ]; then + update-status "Registering" -retries_left=10 -while [[ ${retries_left} -gt 0 ]]; do - log.debug 'Configuring the runner.' - ./config.sh --unattended --replace \ - --name "${RUNNER_NAME}" \ - --url "${GITHUB_URL}${ATTACH}" \ - --token "${RUNNER_TOKEN}" \ - --runnergroup "${RUNNER_GROUPS}" \ - --labels "${RUNNER_LABELS}" \ - --work "${RUNNER_WORKDIR}" "${config_args[@]}" + retries_left=10 + while [[ ${retries_left} -gt 0 ]]; do + log.debug 'Configuring the runner.' + ./config.sh --unattended --replace \ + --name "${RUNNER_NAME}" \ + --url "${GITHUB_URL}${ATTACH}" \ + --token "${RUNNER_TOKEN}" \ + --runnergroup "${RUNNER_GROUPS}" \ + --labels "${RUNNER_LABELS}" \ + --work "${RUNNER_WORKDIR}" "${config_args[@]}" - if [ -f .runner ]; then - log.debug 'Runner successfully configured.' - break + if [ -f .runner ]; then + log.debug 'Runner successfully configured.' + break + fi + + log.debug 'Configuration failed. Retrying' + retries_left=$((retries_left - 1)) + sleep 1 + done + + # Note that ARC v1 runners do create this file, but only after the runner + # agent is up and running. + # On the other hand, this logic assumes the file to be created BEFORE + # the runner is up, by running `config.sh`, which is not present in a v1 runner deployment. + # That's why we need to skip this check for v1 runners. + # Otherwise v1 runner will never start up due to this check. + if [ ! -f .runner ]; then + # we couldn't configure and register the runner; no point continuing + log.error 'Configuration failed!' + exit 2 fi - log.debug 'Configuration failed. Retrying' - retries_left=$((retries_left - 1)) - sleep 1 -done - -if [ ! -f .runner ]; then - # we couldn't configure and register the runner; no point continuing - log.error 'Configuration failed!' - exit 2 + cat .runner + # Note: the `.runner` file's content should be something like the below: + # + # $ cat /runner/.runner + # { + # "agentId": 117, #=> corresponds to the ID of the runner + # "agentName": "THE_RUNNER_POD_NAME", + # "poolId": 1, + # "poolName": "Default", + # "serverUrl": "https://pipelines.actions.githubusercontent.com/SOME_RANDOM_ID", + # "gitHubUrl": "https://github.com/USER/REPO", + # "workFolder": "/some/work/dir" #=> corresponds to Runner.Spec.WorkDir + # } + # + # Especially `agentId` is important, as other than listing all the runners in the repo, + # this is the only change we could get the exact runnner ID which can be useful for further + # GitHub API call like the below. Note that 171 is the agentId seen above. + # curl \ + # -H "Accept: application/vnd.github.v3+json" \ + # -H "Authorization: bearer ${GITHUB_TOKEN}" + # https://api.github.com/repos/USER/REPO/actions/runners/171 fi -cat .runner -# Note: the `.runner` file's content should be something like the below: -# -# $ cat /runner/.runner -# { -# "agentId": 117, #=> corresponds to the ID of the runner -# "agentName": "THE_RUNNER_POD_NAME", -# "poolId": 1, -# "poolName": "Default", -# "serverUrl": "https://pipelines.actions.githubusercontent.com/SOME_RANDOM_ID", -# "gitHubUrl": "https://github.com/USER/REPO", -# "workFolder": "/some/work/dir" #=> corresponds to Runner.Spec.WorkDir -# } -# -# Especially `agentId` is important, as other than listing all the runners in the repo, -# this is the only change we could get the exact runnner ID which can be useful for further -# GitHub API call like the below. Note that 171 is the agentId seen above. -# curl \ -# -H "Accept: application/vnd.github.v3+json" \ -# -H "Authorization: bearer ${GITHUB_TOKEN}" -# https://api.github.com/repos/USER/REPO/actions/runners/171 - # Hack due to the DinD volumes +# This is necessary only for legacy ARC v0.x. +# ARC v1.x uses the "externals" as the copy source and "tmpDir" as the copy destionation. +# See https://github.com/actions/actions-runner-controller/blob/91c8991835016f8c6568f101d4a28185baec3dcc/charts/gha-runner-scale-set/templates/_helpers.tpl#L76-L87 if [ -z "${UNITTEST:-}" ] && [ -e ./externalstmp ]; then mkdir -p ./externals mv ./externalstmp/* ./externals/ From 8a8f28f12dc8f0ba508d18fe22150ca71157b15a Mon Sep 17 00:00:00 2001 From: Yusuke Kuoka Date: Wed, 31 May 2023 00:50:30 +0000 Subject: [PATCH 2/3] fixup! Enhance ARC runner image dockerfiles for RunnerScaleSet compatibility --- runner/startup.sh | 130 +++++++++++++++++++++++----------------------- 1 file changed, 65 insertions(+), 65 deletions(-) diff --git a/runner/startup.sh b/runner/startup.sh index e0717ff2..05e2965f 100755 --- a/runner/startup.sh +++ b/runner/startup.sh @@ -16,61 +16,6 @@ if [ -n "${STARTUP_DELAY_IN_SECONDS}" ]; then sleep "${STARTUP_DELAY_IN_SECONDS}" fi -if [ -z "${GITHUB_URL}" ]; then - log.debug 'Working with public GitHub' - GITHUB_URL="https://github.com/" -else - length=${#GITHUB_URL} - last_char=${GITHUB_URL:length-1:1} - - [[ $last_char != "/" ]] && GITHUB_URL="$GITHUB_URL/"; : - log.debug "Github endpoint URL ${GITHUB_URL}" -fi - -if [ -z "${RUNNER_NAME}" ]; then - log.error 'RUNNER_NAME must be set' - exit 1 -fi - -if [ -n "${RUNNER_ORG}" ] && [ -n "${RUNNER_REPO}" ] && [ -n "${RUNNER_ENTERPRISE}" ]; then - ATTACH="${RUNNER_ORG}/${RUNNER_REPO}" -elif [ -n "${RUNNER_ORG}" ]; then - ATTACH="${RUNNER_ORG}" -elif [ -n "${RUNNER_REPO}" ]; then - ATTACH="${RUNNER_REPO}" -elif [ -n "${RUNNER_ENTERPRISE}" ]; then - ATTACH="enterprises/${RUNNER_ENTERPRISE}" -else - log.error 'At least one of RUNNER_ORG, RUNNER_REPO, or RUNNER_ENTERPRISE must be set' - exit 1 -fi - -if [ -z "${RUNNER_TOKEN}" ]; then - log.error 'RUNNER_TOKEN must be set' - exit 1 -fi - -if [ -z "${RUNNER_REPO}" ] && [ -n "${RUNNER_GROUP}" ];then - RUNNER_GROUPS=${RUNNER_GROUP} -fi - -# Hack due to https://github.com/actions/actions-runner-controller/issues/252#issuecomment-758338483 -if [ ! -d "${RUNNER_HOME}" ]; then - log.error "$RUNNER_HOME should be an emptyDir mount. Please fix the pod spec." - exit 1 -fi - -# if this is not a testing environment -if [[ "${UNITTEST:-}" == '' ]]; then - sudo chown -R runner:docker "$RUNNER_HOME" - # enable dotglob so we can copy a ".env" file to load in env vars as part of the service startup if one is provided - # loading a .env from the root of the service is part of the actions/runner logic - shopt -s dotglob - # use cp instead of mv to avoid issues when src and dst are on different devices - cp -r "$RUNNER_ASSETS_DIR"/* "$RUNNER_HOME"/ - shopt -u dotglob -fi - if ! cd "${RUNNER_HOME}"; then log.error "Failed to cd into ${RUNNER_HOME}" exit 1 @@ -78,21 +23,76 @@ fi # past that point, it's all relative pathes from /runner -config_args=() -if [ "${RUNNER_FEATURE_FLAG_ONCE:-}" != "true" ] && [ "${RUNNER_EPHEMERAL}" == "true" ]; then - config_args+=(--ephemeral) - log.debug 'Passing --ephemeral to config.sh to enable the ephemeral runner.' -fi -if [ "${DISABLE_RUNNER_UPDATE:-}" == "true" ]; then - config_args+=(--disableupdate) - log.debug 'Passing --disableupdate to config.sh to disable automatic runner updates.' -fi - # This is for registering ARC v0 runners. # ARC v1 runners do not need config.sh for registering themselves. # ARC v1 runners are supposed to given the ACTIONS_RUNNER_INPUT_JITCONFIG envvars # so we use it as the trigger to skip config.sh. if [ -z "${ACTIONS_RUNNER_INPUT_JITCONFIG:-}" ]; then + if [ -z "${GITHUB_URL}" ]; then + log.debug 'Working with public GitHub' + GITHUB_URL="https://github.com/" + else + length=${#GITHUB_URL} + last_char=${GITHUB_URL:length-1:1} + + [[ $last_char != "/" ]] && GITHUB_URL="$GITHUB_URL/"; : + log.debug "Github endpoint URL ${GITHUB_URL}" + fi + + if [ -z "${RUNNER_NAME}" ]; then + log.error 'RUNNER_NAME must be set' + exit 1 + fi + + if [ -n "${RUNNER_ORG}" ] && [ -n "${RUNNER_REPO}" ] && [ -n "${RUNNER_ENTERPRISE}" ]; then + ATTACH="${RUNNER_ORG}/${RUNNER_REPO}" + elif [ -n "${RUNNER_ORG}" ]; then + ATTACH="${RUNNER_ORG}" + elif [ -n "${RUNNER_REPO}" ]; then + ATTACH="${RUNNER_REPO}" + elif [ -n "${RUNNER_ENTERPRISE}" ]; then + ATTACH="enterprises/${RUNNER_ENTERPRISE}" + else + log.error 'At least one of RUNNER_ORG, RUNNER_REPO, or RUNNER_ENTERPRISE must be set' + exit 1 + fi + + if [ -z "${RUNNER_TOKEN}" ]; then + log.error 'RUNNER_TOKEN must be set' + exit 1 + fi + + if [ -z "${RUNNER_REPO}" ] && [ -n "${RUNNER_GROUP}" ];then + RUNNER_GROUPS=${RUNNER_GROUP} + fi + + # Hack due to https://github.com/actions/actions-runner-controller/issues/252#issuecomment-758338483 + if [ ! -d "${RUNNER_HOME}" ]; then + log.error "$RUNNER_HOME should be an emptyDir mount. Please fix the pod spec." + exit 1 + fi + + # if this is not a testing environment + if [[ "${UNITTEST:-}" == '' ]]; then + sudo chown -R runner:docker "$RUNNER_HOME" + # enable dotglob so we can copy a ".env" file to load in env vars as part of the service startup if one is provided + # loading a .env from the root of the service is part of the actions/runner logic + shopt -s dotglob + # use cp instead of mv to avoid issues when src and dst are on different devices + cp -r "$RUNNER_ASSETS_DIR"/* "$RUNNER_HOME"/ + shopt -u dotglob + fi + + config_args=() + if [ "${RUNNER_FEATURE_FLAG_ONCE:-}" != "true" ] && [ "${RUNNER_EPHEMERAL}" == "true" ]; then + config_args+=(--ephemeral) + log.debug 'Passing --ephemeral to config.sh to enable the ephemeral runner.' + fi + if [ "${DISABLE_RUNNER_UPDATE:-}" == "true" ]; then + config_args+=(--disableupdate) + log.debug 'Passing --disableupdate to config.sh to disable automatic runner updates.' + fi + update-status "Registering" retries_left=10 From fb1a7cce8bcba09ce1d744fdefdadd9d71fc119b Mon Sep 17 00:00:00 2001 From: Yusuke Kuoka Date: Wed, 31 May 2023 01:30:37 +0000 Subject: [PATCH 3/3] Fix runner startup.sh tests - `should_work_use_disable_once_switch` was failing since the support for --once has been removed a while ago. Removed the test. - Added `cd` before running `startup.sh` for access to the logger.sh library from within the script - Included the runner directory into `$PATH` for access to `update-status` from within the script --- test/startup/should_retry_configuring/test.sh | 6 +- .../startup/should_work_non_ephemeral/test.sh | 6 +- test/startup/should_work_normally/test.sh | 6 +- .../test.sh | 87 ------------------- 4 files changed, 12 insertions(+), 93 deletions(-) delete mode 100755 test/startup/should_work_use_disable_update_switch/test.sh diff --git a/test/startup/should_retry_configuring/test.sh b/test/startup/should_retry_configuring/test.sh index 82a2e6c3..4bddd4a7 100755 --- a/test/startup/should_retry_configuring/test.sh +++ b/test/startup/should_retry_configuring/test.sh @@ -15,7 +15,7 @@ startup_log() { } log "Setting up test area" -export RUNNER_HOME=testarea +export RUNNER_HOME=$(pwd)/testarea mkdir -p ${RUNNER_HOME} log "Setting up the test config" @@ -49,7 +49,9 @@ log "" # Run the runner startup script which as a final step runs this # unit tests run.sh as it was symlinked -../../../runner/startup.sh 2> >(startup_log) +cd ../../../runner +export PATH=${PATH}:$(pwd) +./startup.sh 2> >(startup_log) if [ "$?" != "2" ]; then error "=========================================" diff --git a/test/startup/should_work_non_ephemeral/test.sh b/test/startup/should_work_non_ephemeral/test.sh index ad99e4c8..9dddeea5 100755 --- a/test/startup/should_work_non_ephemeral/test.sh +++ b/test/startup/should_work_non_ephemeral/test.sh @@ -15,7 +15,7 @@ startup_log() { } log "Setting up test area" -export RUNNER_HOME=testarea +export RUNNER_HOME=$(pwd)/testarea mkdir -p ${RUNNER_HOME} log "Setting up the test" @@ -49,7 +49,9 @@ log "" # Run the runner entrypstartupoint script which as a final step runs this # unit tests run.sh as it was symlinked -../../../runner/startup.sh 2> >(startup_log) +cd ../../../runner +export PATH=${PATH}:$(pwd) +./startup.sh 2> >(startup_log) if [ "$?" != "0" ]; then error "===========================================" diff --git a/test/startup/should_work_normally/test.sh b/test/startup/should_work_normally/test.sh index ee45a876..4fbdfc5f 100755 --- a/test/startup/should_work_normally/test.sh +++ b/test/startup/should_work_normally/test.sh @@ -15,7 +15,7 @@ startup_log() { } log "Setting up test area" -export RUNNER_HOME=testarea +export RUNNER_HOME=$(pwd)/testarea mkdir -p ${RUNNER_HOME} log "Setting up the test" @@ -47,7 +47,9 @@ log "" # Run the runner startup script which as a final step runs this # unit tests run.sh as it was symlinked -../../../runner/startup.sh 2> >(startup_log) +cd ../../../runner +export PATH=${PATH}:$(pwd) +./startup.sh 2> >(startup_log) if [ "$?" != "0" ]; then error "==========================" diff --git a/test/startup/should_work_use_disable_update_switch/test.sh b/test/startup/should_work_use_disable_update_switch/test.sh deleted file mode 100755 index 0d981c09..00000000 --- a/test/startup/should_work_use_disable_update_switch/test.sh +++ /dev/null @@ -1,87 +0,0 @@ -#!/usr/bin/env bash - -# UNITTEST: should work disable update -# Will simulate a scneario where disableupdate=true. expects: -# - the configuration step to be run exactly once -# - the startup script to exit with no error -# - the config.sh script to run with the --disableupdate flag set to 'true'. - -source ../assets/logging.sh - -startup_log() { - while read I; do - printf "\tstartup.sh: $I\n" - done -} - -log "Setting up test area" -export RUNNER_HOME=testarea -mkdir -p ${RUNNER_HOME} - -log "Setting up the test" -export UNITTEST=true -export RUNNER_NAME="example_runner_name" -export RUNNER_REPO="myorg/myrepo" -export RUNNER_TOKEN="xxxxxxxxxxxxx" -export DISABLE_RUNNER_UPDATE="true" - -# run.sh and config.sh get used by the runner's real entrypoint.sh and are part of actions/runner. -# We change symlink dummy versions so the entrypoint.sh can run allowing us to test the real entrypoint.sh -log "Symlink dummy config.sh and run.sh" -ln -s ../../assets/config.sh ${RUNNER_HOME}/config.sh -ln -s ../../assets/run.sh ${RUNNER_HOME}/run.sh - -cleanup() { - rm -rf ${RUNNER_HOME} - unset UNITTEST - unset RUNNERHOME - unset RUNNER_NAME - unset RUNNER_REPO - unset RUNNER_TOKEN -} - -# Always run cleanup when test ends regardless of how it ends -trap cleanup SIGINT SIGTERM SIGQUIT EXIT - -log "Running the startup script" -log "" - -# run.sh and config.sh get used by the runner's real startup.sh and are part of actions/runner. -# We change symlink dummy versions so the startup.sh can run allowing us to test the real entrypoint.sh -../../../runner/startup.sh 2> >(startup_log) - -if [ "$?" != "0" ]; then - error "==========================" - error "FAIL | Test completed with errors" - exit 1 -fi - -log "Testing if the configuration step was run only once" -count=`cat ${RUNNER_HOME}/counter || echo "not_found"` -if [ ${count} != "1" ]; then - error "===============================================" - error "FAIL | The configuration step was not run exactly once" - exit 1 -fi -success "PASS | The configuration ran ${count} time(s)" - -log "Testing if the configuration included the --disableupdate flag" -if ! grep -q -- '--disableupdate' ${RUNNER_HOME}/runner_config; then - error "===============================================" - error "FAIL | The configuration should not include the --disableupdate flag" - exit 1 -fi - -success "PASS | The --disableupdate switch was included in the configuration" - -log "Testing if run.sh ran" -if [ ! -f "${RUNNER_HOME}/run_sh_ran" ]; then - error "==============================" - error "FAIL | The runner service has not run" - exit 1 -fi - -success "PASS | run.sh ran" -success "" -success "===========================" -success "Test completed successfully"