-
Notifications
You must be signed in to change notification settings - Fork 904
fix: return error if agent init script fails to download valid binary #13280
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6705c9e
Update bootstrap scripts to check for executable correctness
dannykopping d11c2d3
Add comment to more easily find string replacements
dannykopping b63b479
Appease shellcheck
dannykopping 5438b65
Make lint script more portable
dannykopping 8f08e00
Add tests
dannykopping 70e3091
Use more expressive error, double-quote output
dannykopping 3e121e0
Merge branch 'main' of github.com:/coder/coder into dk/verify-agent
dannykopping File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
dannykopping marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd still like to see stderr redirected here so we can give a sensible output. Thoughts?
|
||
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't recall now, but I worry if
${}
can be interpreted as a terraform variable here. This is good practice but I think we should avoid it in the bootstrap scripts.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a good call-out, but
BINARY_NAME
is not replaced by the provider, it seems:https://github.com/coder/terraform-provider-coder/blob/7815596401d6e69aebb4ceefe1e84369cb63c4ac/provider/agent.go#L345-L376
IMHO I think we should use a different template replacement syntax than Bash's variable expansion, to make it very clear that these are replaced by a script and not accepted into the script as env vars.