From 9ed37bca4c950f17c38ad21964918ff1a686f993 Mon Sep 17 00:00:00 2001 From: Mark Young Date: Mon, 24 Feb 2025 10:59:25 -0600 Subject: [PATCH] Force DISABLE_AUTOMATIC_DEREGISTRATION to be true on reusable runners, add tests --- .github/workflows/base.yml | 6 ++++++ .github/workflows/deploy.yml | 39 +++++++++++++++++++++++++++++++++++ .github/workflows/test.yml | 40 +++++++++++++++++++++++++++++++++++- entrypoint.sh | 4 ++++ goss_reusage_fail.yaml | 9 ++++++++ install_actions.sh | 2 +- 6 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 goss_reusage_fail.yaml diff --git a/.github/workflows/base.yml b/.github/workflows/base.yml index e362ec79..57120d4c 100644 --- a/.github/workflows/base.yml +++ b/.github/workflows/base.yml @@ -72,6 +72,9 @@ jobs: echo "oscodename: ${{ matrix.release }}" >>goss_vars_${GH_RUNNER_IMAGE}.yaml echo "arch: ${{ matrix.platform }}" >>goss_vars_${GH_RUNNER_IMAGE}.yaml GOSS_VARS=goss_vars_${GH_RUNNER_IMAGE}.yaml GOSS_FILE=goss_base.yaml GOSS_SLEEP=1 dgoss run --entrypoint /usr/bin/sleep -e RUNNER_NAME=test -e DEBUG_ONLY=true ${GH_RUNNER_IMAGE} 10 + if [ $? -ne 0 ]; then + exit 1 + fi debian_base_tests: runs-on: ubuntu-latest @@ -133,6 +136,9 @@ jobs: echo "oscodename: ${{ matrix.release }}" >>goss_vars_${GH_RUNNER_IMAGE}.yaml echo "arch: ${{ matrix.platform }}" >>goss_vars_${GH_RUNNER_IMAGE}.yaml GOSS_VARS=goss_vars_${GH_RUNNER_IMAGE}.yaml GOSS_FILE=goss_base.yaml GOSS_SLEEP=1 dgoss run --entrypoint /usr/bin/sleep -e RUNNER_NAME=test -e DEBUG_ONLY=true ${GH_RUNNER_IMAGE} 10 + if [ $? -ne 0 ]; then + exit 1 + fi ubuntu_base_latest_deploy: diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 81d114de..8432cbb0 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -75,10 +75,31 @@ jobs: echo "os: ubuntu" >goss_vars_${GH_RUNNER_IMAGE}.yaml echo "oscodename: ${{ matrix.release }}" >>goss_vars_${GH_RUNNER_IMAGE}.yaml echo "arch: ${{ matrix.platform }}" >>goss_vars_${GH_RUNNER_IMAGE}.yaml + # test the edge case from deregistration on reusable runners + GOSS_VARS=goss_vars_${GH_RUNNER_IMAGE}.yaml GOSS_FILE=goss_reusage_fail.yaml GOSS_SLEEP=1 dgoss run --entrypoint /usr/bin/sleep \ + -e DEBUG_ONLY=true \ + -e ACCESS_TOKEN=notreal \ + -e LABELS=linux,x64 \ + -e REPO_URL=https://github.com/octokode/test1 \ + -e RUNNER_NAME=sustainjane-runner-1 \ + -e RUNNER_SCOPE=repo \ + -e RUNNER_WORKDIR=/tmp/runner/work \ + -e DISABLE_AUTOMATIC_DEREGISTRATION=false \ + -e CONFIGURED_ACTIONS_RUNNER_FILES_DIR=/runner/data \ + ${GH_RUNNER_IMAGE} 10 + if [ $? -ne 0 ]; then + exit 1 + fi # test the base GOSS_VARS=goss_vars_${GH_RUNNER_IMAGE}.yaml GOSS_FILE=goss_base.yaml GOSS_SLEEP=1 dgoss run --entrypoint /usr/bin/sleep -e RUNNER_NAME=test -e DEBUG_ONLY=true ${GH_RUNNER_IMAGE} 10 + if [ $? -ne 0 ]; then + exit 1 + fi # test the final image but with all defaults GOSS_VARS=goss_vars_${GH_RUNNER_IMAGE}.yaml GOSS_FILE=goss_full_defaults.yaml GOSS_SLEEP=1 dgoss run --entrypoint /usr/bin/sleep -e RUNNER_NAME=test -e DEBUG_ONLY=true ${GH_RUNNER_IMAGE} 10 + if [ $? -ne 0 ]; then + exit 1 + fi # test the final image but with non-default values GOSS_VARS=goss_vars_${GH_RUNNER_IMAGE}.yaml GOSS_FILE=goss_full.yaml GOSS_SLEEP=1 dgoss run --entrypoint /usr/bin/sleep \ -e DEBUG_ONLY=true \ @@ -102,6 +123,9 @@ jobs: -e EPHEMERAL=true \ -e DISABLE_AUTO_UPDATE=true \ ${GH_RUNNER_IMAGE} 10 + if [ $? -ne 0 ]; then + exit 1 + fi debian_tests: runs-on: ubuntu-latest @@ -163,6 +187,21 @@ jobs: echo "os: debian" >goss_vars_${GH_RUNNER_IMAGE}.yaml echo "oscodename: ${{ matrix.release }}" >>goss_vars_${GH_RUNNER_IMAGE}.yaml echo "arch: ${{ matrix.platform }}" >>goss_vars_${GH_RUNNER_IMAGE}.yaml + # test the edge case from deregistration on reusable runners + GOSS_VARS=goss_vars_${GH_RUNNER_IMAGE}.yaml GOSS_FILE=goss_reusage_fail.yaml GOSS_SLEEP=1 dgoss run --entrypoint /usr/bin/sleep \ + -e DEBUG_ONLY=true \ + -e ACCESS_TOKEN=notreal \ + -e LABELS=linux,x64 \ + -e REPO_URL=https://github.com/octokode/test1 \ + -e RUNNER_NAME=sustainjane-runner-1 \ + -e RUNNER_SCOPE=repo \ + -e RUNNER_WORKDIR=/tmp/runner/work \ + -e DISABLE_AUTOMATIC_DEREGISTRATION=false \ + -e CONFIGURED_ACTIONS_RUNNER_FILES_DIR=/runner/data \ + ${GH_RUNNER_IMAGE} 10 + if [ $? -ne 0 ]; then + exit 1 + fi # test the base GOSS_VARS=goss_vars_${GH_RUNNER_IMAGE}.yaml GOSS_FILE=goss_base.yaml GOSS_SLEEP=1 dgoss run --entrypoint /usr/bin/sleep -e RUNNER_NAME=test -e DEBUG_ONLY=true ${GH_RUNNER_IMAGE} 10 # test the final image but with all defaults diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cd439f35..de4c6bc9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -77,10 +77,31 @@ jobs: echo "os: ubuntu" >goss_vars_${GH_RUNNER_IMAGE}.yaml echo "oscodename: ${{ matrix.release }}" >>goss_vars_${GH_RUNNER_IMAGE}.yaml echo "arch: ${{ matrix.platform }}" >>goss_vars_${GH_RUNNER_IMAGE}.yaml + # test the edge case from deregistration on reusable runners + GOSS_VARS=goss_vars_${GH_RUNNER_IMAGE}.yaml GOSS_FILE=goss_reusage_fail.yaml GOSS_SLEEP=1 dgoss run --entrypoint /usr/bin/sleep \ + -e DEBUG_ONLY=true \ + -e ACCESS_TOKEN=notreal \ + -e LABELS=linux,x64 \ + -e REPO_URL=https://github.com/octokode/test1 \ + -e RUNNER_NAME=sustainjane-runner-1 \ + -e RUNNER_SCOPE=repo \ + -e RUNNER_WORKDIR=/tmp/runner/work \ + -e DISABLE_AUTOMATIC_DEREGISTRATION=false \ + -e CONFIGURED_ACTIONS_RUNNER_FILES_DIR=/runner/data \ + ${GH_RUNNER_IMAGE} 10 + if [ $? -ne 0 ]; then + exit 1 + fi # test the base GOSS_VARS=goss_vars_${GH_RUNNER_IMAGE}.yaml GOSS_FILE=goss_base.yaml GOSS_SLEEP=1 dgoss run --entrypoint /usr/bin/sleep -e RUNNER_NAME=test -e DEBUG_ONLY=true ${GH_RUNNER_IMAGE} 10 + if [ $? -ne 0 ]; then + exit 1 + fi # test the final image but with all defaults GOSS_VARS=goss_vars_${GH_RUNNER_IMAGE}.yaml GOSS_FILE=goss_full_defaults.yaml GOSS_SLEEP=1 dgoss run --entrypoint /usr/bin/sleep -e RUNNER_NAME=test -e DEBUG_ONLY=true ${GH_RUNNER_IMAGE} 10 + if [ $? -ne 0 ]; then + exit 1 + fi # test the final image but with non-default values GOSS_VARS=goss_vars_${GH_RUNNER_IMAGE}.yaml GOSS_FILE=goss_full.yaml GOSS_SLEEP=1 dgoss run --entrypoint /usr/bin/sleep \ -e DEBUG_ONLY=true \ @@ -104,7 +125,9 @@ jobs: -e EPHEMERAL=true \ -e DISABLE_AUTO_UPDATE=true \ ${GH_RUNNER_IMAGE} 10 - + if [ $? -ne 0 ]; then + exit 1 + fi debian_tests: runs-on: ubuntu-latest strategy: @@ -168,6 +191,21 @@ jobs: echo "os: debian" >goss_vars_${GH_RUNNER_IMAGE}.yaml echo "oscodename: ${{ matrix.release }}" >>goss_vars_${GH_RUNNER_IMAGE}.yaml echo "arch: ${{ matrix.platform }}" >>goss_vars_${GH_RUNNER_IMAGE}.yaml + # test the edge case from deregistration on reusable runners + GOSS_VARS=goss_vars_${GH_RUNNER_IMAGE}.yaml GOSS_FILE=goss_reusage_fail.yaml GOSS_SLEEP=1 dgoss run --entrypoint /usr/bin/sleep \ + -e DEBUG_ONLY=true \ + -e ACCESS_TOKEN=notreal \ + -e LABELS=linux,x64 \ + -e REPO_URL=https://github.com/octokode/test1 \ + -e RUNNER_NAME=sustainjane-runner-1 \ + -e RUNNER_SCOPE=repo \ + -e RUNNER_WORKDIR=/tmp/runner/work \ + -e DISABLE_AUTOMATIC_DEREGISTRATION=false \ + -e CONFIGURED_ACTIONS_RUNNER_FILES_DIR=/runner/data \ + ${GH_RUNNER_IMAGE} 10 + if [ $? -ne 0 ]; then + exit 1 + fi # test the base GOSS_VARS=goss_vars_${GH_RUNNER_IMAGE}.yaml GOSS_FILE=goss_base.yaml GOSS_SLEEP=1 dgoss run --entrypoint /usr/bin/sleep -e RUNNER_NAME=test -e DEBUG_ONLY=true ${GH_RUNNER_IMAGE} 10 # test the final image but with all defaults diff --git a/entrypoint.sh b/entrypoint.sh index 218eea29..0233cbfd 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -210,6 +210,10 @@ fi if [[ -n "${_CONFIGURED_ACTIONS_RUNNER_FILES_DIR}" ]]; then echo "Reusage is enabled. Storing data to ${_CONFIGURED_ACTIONS_RUNNER_FILES_DIR}" + if [[ ${_DISABLE_AUTOMATIC_DEREGISTRATION} == "false" ]]; then + echo "DISABLE_AUTOMATIC_DEREGISTRATION should be set to true to avoid issues with re-using a deregistered runner." + exit 1 + fi # Quoting (even with double-quotes) the regexp brokes the copying cp -p -r "/actions-runner/_diag" "/actions-runner/svc.sh" /actions-runner/.[^.]* "${_CONFIGURED_ACTIONS_RUNNER_FILES_DIR}" fi diff --git a/goss_reusage_fail.yaml b/goss_reusage_fail.yaml new file mode 100644 index 00000000..f0bee0f5 --- /dev/null +++ b/goss_reusage_fail.yaml @@ -0,0 +1,9 @@ +command: + /entrypoint.sh something: + exit-status: 1 + stdout: + - "Runner reusage is enabled" + - "Reusage is enabled. Storing data to /runner/data" + - "DISABLE_AUTOMATIC_DEREGISTRATION should be set to true to avoid issues with re-using a deregistered runner." + stderr: "" + timeout: 2000 diff --git a/install_actions.sh b/install_actions.sh index 10421a8b..ba19051c 100644 --- a/install_actions.sh +++ b/install_actions.sh @@ -10,4 +10,4 @@ curl -L "https://github.com/actions/runner/releases/download/v${GH_RUNNER_VERSIO tar -zxf actions.tar.gz rm -f actions.tar.gz ./bin/installdependencies.sh -mkdir /_work +mkdir -p /_work