Skip to content

Commit

Permalink
feat: add system-info callback
Browse files Browse the repository at this point in the history
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 cloudbase/garm#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 <[email protected]>
  • Loading branch information
gabriel-samfira committed Jan 4, 2024
1 parent dedd9bf commit e770fb0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
2 changes: 2 additions & 0 deletions runner/upstream/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 17 additions & 5 deletions runner/upstream/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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\"}"
Expand All @@ -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}"
}

Expand Down Expand Up @@ -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 "$@"

0 comments on commit e770fb0

Please sign in to comment.