-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve error handling and log output of
{pre,post}_compile
hooks (#…
…1667) * If the hooks fail, there is now an explicit error message (plus metrics event). * The build log step now references the full script location to aid. with understanding of what's happening. * Any output of the hooks is now indented to aid readability. * The hooks implementation has been refactored and moved to `lib/` as part of the overall buildpack reorganisation/refactoring. * Test coverage has been added for the failing hooks cases (previously only the successful hooks scenario was tested). (This is one step towards ensuring all buildpack failure cases have an explicit error message and a metrics `failure_reason`.) GUS-W-8059892.
- Loading branch information
Showing
13 changed files
with
217 additions
and
136 deletions.
There are no files selected for viewing
This file contains 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 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/usr/bin/env bash | ||
|
||
# This is technically redundant, since all consumers of this lib will have enabled these, | ||
# however, it helps Shellcheck realise the options under which these functions will run. | ||
set -euo pipefail | ||
|
||
# Used to run the `bin/pre_compile` and `bin/post_compile`s scripts if found in the app source, | ||
# allowing for build customisation. | ||
function hooks::run_hook() { | ||
local hook_name="${1}" | ||
local script_path="bin/${hook_name}" | ||
|
||
if [[ -f "${script_path}" ]]; then | ||
local hook_start_time | ||
hook_start_time=$(nowms) | ||
output::step "Running ${script_path} hook" | ||
meta_set "${hook_name}_hook" "true" | ||
chmod +x "${script_path}" | ||
|
||
# shellcheck disable=SC2310 # This function is invoked in an 'if' condition so set -e will be disabled. | ||
if ! sub_env "${script_path}" |& output::indent; then | ||
output::error <<-EOF | ||
Error: Failed to run the ${script_path} script. | ||
We found a '${script_path}' script in your app source, so ran | ||
it to allow for customisation of the build process. | ||
However, this script exited with a non-zero exit status. | ||
Fix any errors output by your script above, or remove/rename | ||
the script to prevent it from being run during the build. | ||
EOF | ||
meta_set "failure_reason" "hooks::${hook_name}" | ||
exit 1 | ||
fi | ||
|
||
meta_time "${hook_name}_hook_duration" "${hook_start_time}" | ||
else | ||
meta_set "${hook_name}_hook" "false" | ||
fi | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
echo 'Some post_compile error!' >&2 | ||
exit 1 |
Empty file.
This file contains 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
echo 'Some pre_compile error!' >&2 | ||
exit 1 |
Empty file.
This file contains 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 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 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.