From e770fb07f5a6f4942a023f302c5bca2ffa099704 Mon Sep 17 00:00:00 2001 From: Gabriel Adrian Samfira Date: Thu, 4 Jan 2024 15:54:51 +0000 Subject: [PATCH] feat: add system-info callback A new callback is available in garm which allows runners to send info about themselves from userdata. This new callback allows instances to report their os_name, os_version and the GH agent_id. See https://github.com/cloudbase/garm/pull/200 This change allso makes sure that curl is installed in the image, otherwise the userdata will never work. Signed-off-by: Gabriel Adrian Samfira --- runner/upstream/Dockerfile | 2 ++ runner/upstream/entrypoint.sh | 22 +++++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/runner/upstream/Dockerfile b/runner/upstream/Dockerfile index 7b06df6..3822d39 100644 --- a/runner/upstream/Dockerfile +++ b/runner/upstream/Dockerfile @@ -4,6 +4,8 @@ FROM ghcr.io/actions/actions-runner:2.311.0 USER root +RUN apt-get update && apt-get install -y curl && apt-get clean + COPY entrypoint.sh /usr/local/bin/ RUN chmod +x /usr/local/bin/entrypoint.sh diff --git a/runner/upstream/entrypoint.sh b/runner/upstream/entrypoint.sh index f8ecd33..f7dcfcb 100644 --- a/runner/upstream/entrypoint.sh +++ b/runner/upstream/entrypoint.sh @@ -20,6 +20,20 @@ function call() { curl --retry 5 --retry-delay 5 --retry-connrefused --fail -s -X POST -d "${PAYLOAD}" -H 'Accept: application/json' -H "Authorization: Bearer ${BEARER_TOKEN}" "${CALLBACK_URL}" || echo "failed to call home: exit code ($?)" } +function systemInfo() { + if [ -f "/etc/os-release" ];then + . /etc/os-release + fi + OS_NAME=${NAME:-""} + OS_VERSION=${VERSION_ID:-""} + AGENT_ID=${1:-null} + # strip status from the callback url + [[ $CALLBACK_URL =~ ^(.*)/status(/)?$ ]] && CALLBACK_URL="${BASH_REMATCH[1]}" || true + SYSINFO_URL="${CALLBACK_URL}/system-info/" + PAYLOAD="{\"os_name\": \"$OS_NAME\", \"os_version\": \"$OS_VERSION\", \"agent_id\": $AGENT_ID}" + curl --retry 5 --retry-delay 5 --retry-connrefused --fail -s -X POST -d "${PAYLOAD}" -H 'Accept: application/json' -H "Authorization: Bearer ${BEARER_TOKEN}" "${SYSINFO_URL}" || true +} + function sendStatus() { MSG="$1" call "{\"status\": \"installing\", \"message\": \"$MSG\"}" @@ -33,14 +47,11 @@ function fail() { function success() { MSG="$1" - ID=$2 - if [ $JIT_CONFIG_ENABLED != "true" ] && [ -z "$ID" ]; then + ID=${2:-null} + if [ $JIT_CONFIG_ENABLED != "true" ] && [ $ID == "null" ]; then fail "agent ID is required when JIT_CONFIG_ENABLED is not true" fi - if [ -z "$ID" ]; then - ID="null" - fi call "{\"status\": \"idle\", \"message\": \"$MSG\", \"agent_id\": $ID}" } @@ -133,5 +144,6 @@ if [ $JIT_CONFIG_ENABLED != "true" ]; then set -e fi +systemInfo $AGENT_ID || true success "runner successfully installed" $AGENT_ID ./run.sh "$@"