Skip to content

Commit b36cfa6

Browse files
fix(hooks): make the output more uniform and delineated (#2343)
* fix(hooks): Consistent logging + skip when empty too - Use "Searching for scripts [...] located in [...]" consistently (i.e. for each hook_folder_path instead of only for some / under some conditions) - Skip early if a given hook folder is empty too (not just nonexistent) - Add feature name (hooks) to all messaging for clarity Signed-off-by: Josh <[email protected]> * fix(hooks): Clear state delineation / consistent output Signed-off-by: Josh <[email protected]> --------- Signed-off-by: Josh <[email protected]>
1 parent 6e8f484 commit b36cfa6

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

docker-entrypoint.sh

+17-10
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,39 @@ run_as() {
2323
run_path() {
2424
local hook_folder_path="/docker-entrypoint-hooks.d/$1"
2525
local return_code=0
26+
local found=0
2627

27-
if ! [ -d "${hook_folder_path}" ]; then
28-
echo "=> Skipping the folder \"${hook_folder_path}\", because it doesn't exist"
28+
echo "=> Searching for hook scripts (*.sh) to run, located in the folder \"${hook_folder_path}\""
29+
30+
if ! [ -d "${hook_folder_path}" ] || directory_empty "${hook_folder_path}"; then
31+
echo "==> Skipped: the \"$1\" folder is empty (or does not exist)"
2932
return 0
3033
fi
3134

32-
echo "=> Searching for scripts (*.sh) to run, located in the folder: ${hook_folder_path}"
33-
34-
(
35-
find "${hook_folder_path}" -maxdepth 1 -iname '*.sh' '(' -type f -o -type l ')' -print | sort | while read -r script_file_path; do
35+
find "${hook_folder_path}" -maxdepth 1 -iname '*.sh' '(' -type f -o -type l ')' -print | sort | (
36+
while read -r script_file_path; do
3637
if ! [ -x "${script_file_path}" ]; then
37-
echo "==> The script \"${script_file_path}\" was skipped, because it didn't have the executable flag"
38+
echo "==> The script \"${script_file_path}\" was skipped, because it lacks the executable flag"
39+
found=$((found-1))
3840
continue
3941
fi
4042

4143
echo "==> Running the script (cwd: $(pwd)): \"${script_file_path}\""
42-
44+
found=$((found+1))
4345
run_as "${script_file_path}" || return_code="$?"
4446

4547
if [ "${return_code}" -ne "0" ]; then
46-
echo "==> Failed at executing \"${script_file_path}\". Exit code: ${return_code}"
48+
echo "==> Failed at executing script \"${script_file_path}\". Exit code: ${return_code}"
4749
exit 1
4850
fi
4951

50-
echo "==> Finished the script: \"${script_file_path}\""
52+
echo "==> Finished executing the script: \"${script_file_path}\""
5153
done
54+
if [ "$found" -lt "1" ]; then
55+
echo "==> Skipped: the \"$1\" folder does not contain any valid scripts"
56+
else
57+
echo "=> Completed executing scripts in the \"$1\" folder"
58+
fi
5259
)
5360
}
5461

0 commit comments

Comments
 (0)