diff --git a/.github/runners/self-hosted/.env b/.github/runners/self-hosted/privileged/.env similarity index 100% rename from .github/runners/self-hosted/.env rename to .github/runners/self-hosted/privileged/.env diff --git a/.github/runners/self-hosted/actions-runner-hooks/job-completed.sh b/.github/runners/self-hosted/privileged/actions-runner-hooks/job-completed.sh similarity index 100% rename from .github/runners/self-hosted/actions-runner-hooks/job-completed.sh rename to .github/runners/self-hosted/privileged/actions-runner-hooks/job-completed.sh diff --git a/.github/runners/self-hosted/actions-runner-hooks/job-started.sh b/.github/runners/self-hosted/privileged/actions-runner-hooks/job-started.sh similarity index 100% rename from .github/runners/self-hosted/actions-runner-hooks/job-started.sh rename to .github/runners/self-hosted/privileged/actions-runner-hooks/job-started.sh diff --git a/.github/runners/self-hosted/unprivileged/.env b/.github/runners/self-hosted/unprivileged/.env new file mode 100644 index 0000000..c4ab3c5 --- /dev/null +++ b/.github/runners/self-hosted/unprivileged/.env @@ -0,0 +1,4 @@ +LANG=en_US.UTF-8 + +ACTIONS_RUNNER_HOOK_JOB_STARTED=/home/manager/actions-runner-hooks/job-started.sh +ACTIONS_RUNNER_HOOK_JOB_COMPLETED=/home/manager/actions-runner-hooks/job-completed.sh diff --git a/.github/runners/self-hosted/unprivileged/actions-runner-hooks/job-completed.sh b/.github/runners/self-hosted/unprivileged/actions-runner-hooks/job-completed.sh new file mode 100755 index 0000000..ed9de6d --- /dev/null +++ b/.github/runners/self-hosted/unprivileged/actions-runner-hooks/job-completed.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# cleanup the workspace +if [ -n "${GITHUB_WORKSPACE}" ]; then + if pushd "${GITHUB_WORKSPACE}"; then + echo "Cleaning up..." + find ! -name '.' ! -name '..' -delete + echo "...cleanup complete" + + popd + else + echo "ERROR: Failed to pushd to '${GITHUB_WORKSPACE}'" + exit 1 + fi +else + echo "ERROR: GITHUB_WORKSPACE is not defined" + exit 1 +fi diff --git a/.github/runners/self-hosted/unprivileged/actions-runner-hooks/job-started.sh b/.github/runners/self-hosted/unprivileged/actions-runner-hooks/job-started.sh new file mode 100755 index 0000000..aa5b274 --- /dev/null +++ b/.github/runners/self-hosted/unprivileged/actions-runner-hooks/job-started.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# cleanup the workspace +if [ -n "${GITHUB_WORKSPACE}" ]; then + if pushd "${GITHUB_WORKSPACE}"; then + echo "Cleaning up..." + find ! -name '.' ! -name '..' -delete + echo "...cleanup complete" + + popd + else + echo "ERROR: Failed to pushd to '${GITHUB_WORKSPACE}'" + exit 1 + fi +else + echo "ERROR: GITHUB_WORKSPACE is not defined" + exit 1 +fi diff --git a/.github/runners/self-hosted/update-runners.sh b/.github/runners/self-hosted/update-runners.sh index 4c2c36e..fe1faab 100755 --- a/.github/runners/self-hosted/update-runners.sh +++ b/.github/runners/self-hosted/update-runners.sh @@ -4,28 +4,40 @@ pushd $(dirname $0) > /dev/null runner_user="manager" -if [ ! -e runners.conf ]; then - echo "ERROR: Could not find runners.conf" - exit 1 -fi +for runner_type in "privileged" "unprivileged"; do + if pushd ${runner_type}; then + echo "runner_type=${runner_type}" -for runner_ip in $(cat runners.conf); do - echo "runner_ip=${runner_ip}" + if [ ! -e runners.conf ]; then + echo "ERROR: Could not find runners.conf" + exit 1 + fi - echo "syncing actions-runner-hooks:" - rsync -av --progress --stats --delete actions-runner-hooks ${runner_user}@${runner_ip}: + for runner_ip in $(cat runners.conf); do + echo "runner_ip=${runner_ip}" - echo "listing actions-runner-hooks:" - ssh ${runner_user}@${runner_ip} "ls -l ~/actions-runner-hooks" + echo "syncing actions-runner-hooks:" + rsync -av --progress --stats --delete actions-runner-hooks ${runner_user}@${runner_ip}: - echo "synching .env:" - rsync -av --progress --stats .env ${runner_user}@${runner_ip}:~/actions-runner/.env + echo "listing actions-runner-hooks:" + ssh ${runner_user}@${runner_ip} "ls -l ~/actions-runner-hooks" - echo "displaying .env:" - ssh ${runner_user}@${runner_ip} "cat ~/actions-runner/.env" + echo "synching .env:" + rsync -av --progress --stats .env ${runner_user}@${runner_ip}:~/actions-runner/.env - echo "restarting the runner:" - ssh ${runner_user}@${runner_ip} "sudo reboot" + echo "displaying .env:" + ssh ${runner_user}@${runner_ip} "cat ~/actions-runner/.env" - echo "##########################################################" + echo "restarting the runner:" + ssh ${runner_user}@${runner_ip} "sudo reboot" + + echo "##########################################################" + done + + popd + + echo "**********************************************************" + else + echo "ERROR: Failed to pushd to ${runner_type}" + fi done