Skip to content

Commit

Permalink
fix(runner): align entrypoint scripts, retrieve agent_id if configure…
Browse files Browse the repository at this point in the history
…d via JIT (#66)

If runner was configured via JIT, the file under `/runner/.runner` which
contains the `agent_id` has a different format compared to registering
the runner via registration token, so the agent_id reported back to
`garm` was `null`. This has been addressed now.
Also check_runner did not continue until `max_retry` on non-zero exit or
pipefail.
  • Loading branch information
rafalgalaw authored Aug 12, 2024
1 parent 43b1c55 commit dc28c86
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
8 changes: 5 additions & 3 deletions runner/summerwind/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ FROM summerwind/actions-runner:ubuntu-22.04

USER root

COPY my-entrypoint.sh /usr/local/bin/
RUN apt-get update && apt-get install -y curl && apt-get clean

RUN chmod +x /usr/local/bin/my-entrypoint.sh
COPY entrypoint.sh /usr/local/bin/

RUN chmod +x /usr/local/bin/entrypoint.sh

USER 1001

ENTRYPOINT ["/usr/local/bin/my-entrypoint.sh"]
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ function getRunnerFile() {
}

function check_runner {
set +e
echo "Checking runner health..."
RETRIES=0
MAX_RETRIES=15
Expand All @@ -84,8 +85,14 @@ function check_runner {
fail "failed to start runner"
fi

AGENT_ID=""
if [ -f "$RUNNER_HOME"/.runner ]; then
AGENT_ID=$(grep "agentId" "$RUNNER_HOME"/.runner | tr -d -c 0-9)

AGENT_ID=$(grep -io '"[aA]gent[iI]d": [0-9]*' "$RUNNER_HOME"/.runner | sed 's/.*[aA]gent[iI]d": \([0-9]*\).*/\1/')
if [ "$JIT_CONFIG_ENABLED" == "true" ];then
AGENT_ID=$(grep -ioE '"[aA]gent[iI]d":"?[0-9]+"?' "$RUNNER_HOME"/.runner | sed -E 's/.*[aA]gent[iI]d"?: ?"([0-9]+)".*/\1/')
fi

echo "Calling $CALLBACK_URL with $AGENT_ID"
systemInfo "$AGENT_ID"
success "runner successfully installed" "$AGENT_ID"
Expand All @@ -96,20 +103,21 @@ function check_runner {
echo "RETRIES: $RETRIES"
sleep 10
done
set -e
}

pushd "$RUNNER_HOME"

shopt -s dotglob
cp -r "$RUNNER_ASSETS_DIR"/* "$RUNNER_HOME"/
shopt -u dotglob

pushd "$RUNNER_HOME"

sendStatus "configuring runner"
if [ "$JIT_CONFIG_ENABLED" == "true" ]; then
sendStatus "downloading JIT credentials"
getRunnerFile "credentials/runner" "/home/runner/.runner" || fail "failed to get runner file"
getRunnerFile "credentials/credentials" "/home/runner/.credentials" || fail "failed to get credentials file"
getRunnerFile "credentials/credentials_rsaparams" "/home/runner/.credentials_rsaparams" || fail "failed to get credentials_rsaparams file"
getRunnerFile "credentials/runner" "$RUNNER_HOME/.runner" || fail "failed to get runner file"
getRunnerFile "credentials/credentials" "$RUNNER_HOME/.credentials" || fail "failed to get credentials file"
getRunnerFile "credentials/credentials_rsaparams" "$RUNNER_HOME/.credentials_rsaparams" || fail "failed to get credentials_rsaparams file"
else
if [ -n "${RUNNER_ORG}" ] && [ -n "${RUNNER_REPO}" ]; then
ATTACH="${RUNNER_ORG}/${RUNNER_REPO}"
Expand Down Expand Up @@ -178,10 +186,6 @@ else
set -e
fi

if [ "$JIT_CONFIG_ENABLED" != "true" ]; then
set +e
check_runner
set -e
fi
check_runner &

./run.sh "$@"
17 changes: 9 additions & 8 deletions runner/upstream/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ function getRunnerFile() {
}

function check_runner {
set +e
echo "Checking runner health..."
RETRIES=0
MAX_RETRIES=15
Expand All @@ -84,15 +85,14 @@ function check_runner {
fail "failed to start runner"
fi

AGENT_ID=""
if [ "$JIT_CONFIG_ENABLED" == "true" ];then
systemInfo "$AGENT_ID"
success "runner successfully installed" "$AGENT_ID"
break
fi

AGENT_ID=""
if [ -f "$RUNNER_HOME"/.runner ]; then
AGENT_ID=$(grep "agentId" "$RUNNER_HOME"/.runner | tr -d -c 0-9)

AGENT_ID=$(grep -io '"[aA]gent[iI]d": [0-9]*' "$RUNNER_HOME"/.runner | sed 's/.*[aA]gent[iI]d": \([0-9]*\).*/\1/')
if [ "$JIT_CONFIG_ENABLED" == "true" ];then
AGENT_ID=$(grep -ioE '"[aA]gent[iI]d":"?[0-9]+"?' "$RUNNER_HOME"/.runner | sed -E 's/.*[aA]gent[iI]d"?: ?"([0-9]+)".*/\1/')
fi

echo "Calling $CALLBACK_URL with $AGENT_ID"
systemInfo "$AGENT_ID"
success "runner successfully installed" "$AGENT_ID"
Expand All @@ -103,6 +103,7 @@ function check_runner {
echo "RETRIES: $RETRIES"
sleep 10
done
set -e
}

shopt -s dotglob
Expand Down

0 comments on commit dc28c86

Please sign in to comment.