fix: return error if agent init script fails to download valid binary (#13280)

This commit is contained in:
Danny Kopping
2024-05-30 13:33:00 +02:00
committed by GitHub
parent e176867d77
commit 59ab5053b1
6 changed files with 154 additions and 30 deletions
+10 -2
View File
@@ -4,7 +4,7 @@ set -eux
# This is to allow folks to exec into a failed workspace and poke around to
# troubleshoot.
waitonexit() {
echo "=== Agent script exited with non-zero code. Sleeping 24h to preserve logs..."
echo "=== Agent script exited with non-zero code ($?). Sleeping 24h to preserve logs..."
sleep 86400
}
trap waitonexit EXIT
@@ -86,4 +86,12 @@ fi
export CODER_AGENT_AUTH="${AUTH_TYPE}"
export CODER_AGENT_URL="${ACCESS_URL}"
exec ./$BINARY_NAME agent
output=$(./${BINARY_NAME} --version | head -n1)
if ! echo "${output}" | grep -q Coder; then
echo >&2 "ERROR: Downloaded agent binary returned unexpected version output"
echo >&2 "${BINARY_NAME} --version output: \"${output}\""
exit 2
fi
exec ./${BINARY_NAME} agent