Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ To use the hooks triggered by the `entrypoint` script, either
- Added your script(s) to the individual of the hook folder(s), which are located at the path `/docker-entrypoint-hooks.d` in the container
- Use volume(s) if you want to use script from the host system inside the container, see example.

**Note:** Only the script(s) located in a hook folder (not sub-folders), ending with `.sh` and marked as executable, will be executed.
**Note:** Only the script(s) located in a hook folder (not sub-folders), ending with `.sh` will be executed.

**Example:** Mount using volumes
```yaml
Expand Down
29 changes: 16 additions & 13 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,29 @@ run_path() {
echo "=> Searching for scripts (*.sh) to run, located in the folder: ${hook_folder_path}"

if [ -z "$(ls -A "${hook_folder_path}")" ]; then
echo "==> but the hook folder \"$(basename "${hook_folder_path}")\" is empty, so nothing to do"
echo "==> but the hook folder \"$(basename "${hook_folder_path}")\" is empty, so nothing to do"
return 0
fi

(
for script_file_path in "${hook_folder_path}/"*.sh; do
if ! [ -x "${script_file_path}" ] && [ -f "${script_file_path}" ]; then
echo "==> The script \"${script_file_path}\" in the folder \"${hook_folder_path}\" was skipping, because it didn't have the executable flag"
continue
fi

echo "==> Running the script (cwd: $(pwd)): \"${script_file_path}\""

run_as "${script_file_path}" || return_code="$?"
if [ -f "${script_file_path}" ]; then
if [ -x "${script_file_path}" ]; then
echo "==> Running the script \"${script_file_path}\" (cwd: $(pwd))."
"${script_file_path}"
return_code="$?"
else
echo "==> Found the script \"${script_file_path}\", but it didn't have the executable flag,"
echo " So running the script as \`user=$user /bin/bash \"${script_file_path}\"\` (cwd: $(pwd))."
user=$user /bin/bash "${script_file_path}"
return_code="$?"
fi

if [ "${return_code}" -ne "0" ]; then
echo "==> Failed at executing \"${script_file_path}\". Exit code: ${return_code}"
exit 1
if [ "${return_code}" -ne "0" ]; then
echo "==> Failed at executing \"${script_file_path}\". Exit code: ${return_code}."
exit 1
fi
fi

echo "==> Finished the script: \"${script_file_path}\""
done
)
Expand Down