Skip to content

Commit e8fb213

Browse files
committed
feat: adding custom entrypoint logic for easier customization
1 parent 9567072 commit e8fb213

File tree

1 file changed

+46
-8
lines changed

1 file changed

+46
-8
lines changed

customizable_entrypoint.sh

+46-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,30 @@ set -ex
33

44
echo "Ready to start"
55

6+
# Function to run scripts
7+
run_script() {
8+
local script=$1
9+
case "$script" in
10+
*.sh)
11+
if [ -x "$script" ]; then
12+
"$script"
13+
else
14+
bash "$script"
15+
fi
16+
;;
17+
*.py)
18+
if [ -x "$script" ]; then
19+
"$script"
20+
else
21+
python3 "$script"
22+
fi
23+
;;
24+
*)
25+
echo "Unknown file type: $script" >&2
26+
;;
27+
esac
28+
}
29+
630
if [ "$CUSTOMIZE" = "true" ]; then
731
echo "Customization is enabled."
832
# Check if the base entry point script exists
@@ -12,18 +36,32 @@ if [ "$CUSTOMIZE" = "true" ]; then
1236
echo "Base entry point is running."
1337
# Wait for 10 seconds
1438
sleep 10
39+
else
40+
echo "Base entry point script not found: /usr/local/bin/base_entrypoint.sh" >&2
41+
exit 1
1542
fi
16-
echo "Customization can be added here. If no additional services are defined then the container will exit."
17-
echo "Running the custom entry point..."
1843

19-
# Custom logic or services can be added here
20-
# Example: Start a Python script
21-
# echo "Starting the Python script..."
22-
# python3 /app/your_python_script.py
44+
# Run all bash or Python scripts found inside custom entrypoints folder
45+
if [ -d "$CUSTOM_ENTRYPOINTS_DIR" ]; then
46+
for script in "$CUSTOM_ENTRYPOINTS_DIR"/*.{sh,py}; do
47+
if [ -f "$script" ]; then
48+
echo "Running custom entry point script: $script"
49+
run_script "$script"
50+
fi
51+
done
52+
else
53+
echo "Custom entrypoints directory not found: $CUSTOM_ENTRYPOINTS_DIR" >&2
54+
exit 1
55+
fi
2356

24-
#### ADD YOUR CUSTOM CODE HERE ####
57+
echo "Customization completed. If no additional services are defined then the container will exit."
2558

2659
else
2760
echo "Customization is disabled. Running the base entry point in the foreground..."
28-
exec /usr/local/bin/base_entrypoint.sh
61+
if [ -f /usr/local/bin/base_entrypoint.sh ]; then
62+
exec /usr/local/bin/base_entrypoint.sh
63+
else
64+
echo "Base entry point script not found: /usr/local/bin/base_entrypoint.sh" >&2
65+
exit 1
66+
fi
2967
fi

0 commit comments

Comments
 (0)