feat: allow to discover runner statuses (#1268)
* feat: allow to discover runner statuses * fix manifests * Bump runner version to 2.289.1 which includes the hooks support * Add feedback from review * Update reference to newRunnerPod * Fix TestNewRunnerPodFromRunnerController and make hooks file names job specific * Fix additional TestNewRunnerPod test * Cover additional feedback from review * fix rbac manager role * Add permissions to service account for container mode if not provided * Rename flag to runner.statusUpdateHook.enabled and fix needsServiceAccount Co-authored-by: Yusuke Kuoka <ykuoka@gmail.com>
This commit is contained in:
committed by
GitHub
parent
10b88bf070
commit
11cb9b7882
@@ -116,7 +116,10 @@ RUN mkdir /opt/hostedtoolcache \
|
||||
|
||||
# We place the scripts in `/usr/bin` so that users who extend this image can
|
||||
# override them with scripts of the same name placed in `/usr/local/bin`.
|
||||
COPY entrypoint.sh logger.bash /usr/bin/
|
||||
COPY entrypoint.sh logger.bash update-status /usr/bin/
|
||||
|
||||
# Configure hooks folder structure.
|
||||
COPY hooks /etc/arc/hooks/
|
||||
|
||||
ENV HOME=/home/runner
|
||||
# Add the Python "User Script Directory" to the PATH
|
||||
|
||||
@@ -4,6 +4,13 @@ source logger.bash
|
||||
RUNNER_ASSETS_DIR=${RUNNER_ASSETS_DIR:-/runnertmp}
|
||||
RUNNER_HOME=${RUNNER_HOME:-/runner}
|
||||
|
||||
# Let GitHub runner execute these hooks. These environment variables are used by GitHub's Runner as described here
|
||||
# https://github.com/actions/runner/blob/main/docs/adrs/1751-runner-job-hooks.md
|
||||
# Scripts referenced in the ACTIONS_RUNNER_HOOK_ environment variables must end in .sh or .ps1
|
||||
# for it to become a valid hook script, otherwise GitHub will fail to run the hook
|
||||
export ACTIONS_RUNNER_HOOK_JOB_STARTED=/etc/arc/hooks/job-started.sh
|
||||
export ACTIONS_RUNNER_HOOK_JOB_COMPLETED=/etc/arc/hooks/job-completed.sh
|
||||
|
||||
if [ ! -z "${STARTUP_DELAY_IN_SECONDS}" ]; then
|
||||
log.notice "Delaying startup by ${STARTUP_DELAY_IN_SECONDS} seconds"
|
||||
sleep ${STARTUP_DELAY_IN_SECONDS}
|
||||
@@ -77,6 +84,8 @@ if [ "${DISABLE_RUNNER_UPDATE:-}" == "true" ]; then
|
||||
log.debug 'Passing --disableupdate to config.sh to disable automatic runner updates.'
|
||||
fi
|
||||
|
||||
update-status "Registering"
|
||||
|
||||
retries_left=10
|
||||
while [[ ${retries_left} -gt 0 ]]; do
|
||||
log.debug 'Configuring the runner.'
|
||||
@@ -155,4 +164,5 @@ unset RUNNER_NAME RUNNER_REPO RUNNER_TOKEN STARTUP_DELAY_IN_SECONDS DISABLE_WAIT
|
||||
if [ -z "${UNITTEST:-}" ]; then
|
||||
mapfile -t env </etc/environment
|
||||
fi
|
||||
update-status "Idle"
|
||||
exec env -- "${env[@]}" ./run.sh
|
||||
|
||||
4
runner/hooks/job-completed.d/update-status
Executable file
4
runner/hooks/job-completed.d/update-status
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
set -u
|
||||
|
||||
exec update-status Idle
|
||||
12
runner/hooks/job-completed.sh
Executable file
12
runner/hooks/job-completed.sh
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/usr/bin/env bash
|
||||
set -Eeuo pipefail
|
||||
|
||||
# shellcheck source=runner/logger.bash
|
||||
source logger.bash
|
||||
|
||||
log.debug "Running ARC Job Completed Hooks"
|
||||
|
||||
for hook in /etc/arc/hooks/job-completed.d/*; do
|
||||
log.debug "Running hook: $hook"
|
||||
"$hook" "$@"
|
||||
done
|
||||
4
runner/hooks/job-started.d/update-status
Executable file
4
runner/hooks/job-started.d/update-status
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
set -u
|
||||
|
||||
exec update-status Running "Run $GITHUB_RUN_ID from $GITHUB_REPOSITORY"
|
||||
12
runner/hooks/job-started.sh
Normal file
12
runner/hooks/job-started.sh
Normal file
@@ -0,0 +1,12 @@
|
||||
#!/usr/bin/env bash
|
||||
set -Eeuo pipefail
|
||||
|
||||
# shellcheck source=runner/logger.bash
|
||||
source logger.bash
|
||||
|
||||
log.debug "Running ARC Job Started Hooks"
|
||||
|
||||
for hook in /etc/arc/hooks/job-started.d/*; do
|
||||
log.debug "Running hook: $hook"
|
||||
"$hook" "$@"
|
||||
done
|
||||
31
runner/update-status
Executable file
31
runner/update-status
Executable file
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env bash
|
||||
set -Eeuo pipefail
|
||||
|
||||
if [[ ${1:-} == '' ]]; then
|
||||
# shellcheck source=runner/logger.bash
|
||||
source logger.bash
|
||||
log.error "Missing required argument -- '<phase>'"
|
||||
exit 64
|
||||
fi
|
||||
|
||||
if [[ ${RUNNER_STATUS_UPDATE_HOOK:-false} == true ]]; then
|
||||
|
||||
apiserver=https://${KUBERNETES_SERVICE_HOST}:${KUBERNETES_SERVICE_PORT_HTTPS}
|
||||
serviceaccount=/var/run/secrets/kubernetes.io/serviceaccount
|
||||
namespace=$(cat ${serviceaccount}/namespace)
|
||||
token=$(cat ${serviceaccount}/token)
|
||||
phase=$1
|
||||
shift
|
||||
|
||||
jq -n --arg phase "$phase" --arg message "${*:-}" '.status.phase = $phase | .status.message = $message' | curl \
|
||||
--cacert ${serviceaccount}/ca.crt \
|
||||
--data @- \
|
||||
--noproxy '*' \
|
||||
--header "Content-Type: application/merge-patch+json" \
|
||||
--header "Authorization: Bearer ${token}" \
|
||||
--show-error \
|
||||
--silent \
|
||||
--request PATCH \
|
||||
"${apiserver}/apis/actions.summerwind.dev/v1alpha1/namespaces/${namespace}/runners/${HOSTNAME}/status"
|
||||
1>&-
|
||||
fi
|
||||
Reference in New Issue
Block a user