Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add system-info callback #15

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion runner/summerwind/my-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ fi

function call() {
PAYLOAD="$1"
curl --fail -s -v -X POST -d "${PAYLOAD}" -H 'Accept: application/json' -H "Authorization: Bearer ${BEARER_TOKEN}" "${CALLBACK_URL}" || { echo "failed to call home: exit code ($?)"; true; }
local cb_url=$CALLBACK_URL
# strip status from the callback url
[[ $cb_url =~ ^(.*)/status(/)?$ ]] || cb_url="${cb_url}/status" || true
curl --fail -s -v -X POST -d "${PAYLOAD}" -H 'Accept: application/json' -H "Authorization: Bearer ${BEARER_TOKEN}" "${cb_url}" || { echo "failed to call home: exit code ($?)"; true; }
}
function sendStatus() {
MSG="$1"
Expand All @@ -43,6 +46,22 @@ function fail() {
exit 1
}

function systemInfo() {
if [ -f "/etc/os-release" ];then
. /etc/os-release
fi

local cb_url=$CALLBACK_URL
OS_NAME=${NAME:-""}
OS_VERSION=${VERSION_ID:-""}
AGENT_ID=${1:-null}
# strip status from the callback url
[[ $cb_url =~ ^(.*)/status(/)?$ ]] && cb_url="${BASH_REMATCH[1]}" || true
SYSINFO_URL="${cb_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 check_runner {
echo "Checking runner health..."
RETRIES=0
Expand All @@ -57,6 +76,7 @@ function check_runner {
if [ -f /runner/.runner ]; then
AGENT_ID=$(grep "agentId" /runner/.runner | tr -d -c 0-9)
echo "Calling $CALLBACK_URL with $AGENT_ID"
systemInfo "$AGENT_ID"
success "runner successfully installed" "$AGENT_ID"
break
fi
Expand Down
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
28 changes: 21 additions & 7 deletions runner/upstream/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,24 @@ fi

function call() {
PAYLOAD="$1"
[[ $CALLBACK_URL =~ ^(.*)/status(/)?$ ]] || CALLBACK_URL="${CALLBACK_URL}/status"
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 ($?)"
local cb_url=$CALLBACK_URL
[[ $cb_url =~ ^(.*)/status(/)?$ ]] || cb_url="${cb_url}/status"
curl --retry 5 --retry-delay 5 --retry-connrefused --fail -s -X POST -d "${PAYLOAD}" -H 'Accept: application/json' -H "Authorization: Bearer ${BEARER_TOKEN}" "${cb_url}" || echo "failed to call home: exit code ($?)"
}

function systemInfo() {
if [ -f "/etc/os-release" ];then
. /etc/os-release
fi
local cb_url=$CALLBACK_URL
OS_NAME=${NAME:-""}
OS_VERSION=${VERSION_ID:-""}
Comment on lines +29 to +30
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just thinking about if we could set some meaningful default values for $NAME and $VERSION_ID maybe during build as ENV in the Dockerfile. Then a user could still overwrite these in their podTemplateSpec in the provdider config if needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of this stuff is strictly informational. It's nice to have, but not strictly necessary in terms of functionality. Simply put, it has no baring on functionality, but if a user does a:

garm-cli runner show <runner ID>

that command will show the real OS and version, not something we infer from the image itself.

This was always the way I hoped this information would be sent upstream (runners would send that info as part of their installation process), but only now got around to doing it.

The idea is that by default, it should be fine to have an empty string for this stuff. But if we can safely determine the OS and version , we should send that to garm.

The /etc/os-release file has been available for a very long time. So I expect it to be present in any container image that is based of any OS that;s not scratch.

AGENT_ID=${1:-null}
# strip status from the callback url
[[ $cb_url =~ ^(.*)/status(/)?$ ]] && cb_url="${BASH_REMATCH[1]}" || true
SYSINFO_URL="${cb_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() {
Expand All @@ -33,14 +49,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 +146,6 @@ if [ $JIT_CONFIG_ENABLED != "true" ]; then
set -e
fi

systemInfo $AGENT_ID || true
success "runner successfully installed" $AGENT_ID
./run.sh "$@"