-
Notifications
You must be signed in to change notification settings - Fork 9
/
customizable_entrypoint.sh
71 lines (65 loc) · 2.09 KB
/
customizable_entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
set -e
echo "Ready to start"
# Function to run scripts
run_script() {
local script=$1
case "$script" in
*.sh)
if [ -x "$script" ]; then
"$script"
else
bash "$script"
fi
;;
*.py)
if [ -x "$script" ]; then
"$script"
else
python3 "$script"
fi
;;
*)
echo "Unknown file type: $script" >&2
;;
esac
}
if [ "$CUSTOMIZE" = "true" ]; then
echo "Customization is enabled."
# Check if the base entry point script exists
if [ -f /usr/local/bin/base_entrypoint.sh ]; then
echo "Running the base entry point in the background..."
/usr/local/bin/base_entrypoint.sh &
echo "Base entry point is running."
# Wait for 10 seconds
sleep 10
else
echo "Base entry point script not found: /usr/local/bin/base_entrypoint.sh" >&2
exit 1
fi
# Run all bash or Python scripts found inside custom entrypoints folder
echo "Looking for custom entry point scripts..."
if [ -d "$CUSTOM_ENTRYPOINTS_DIR" ]; then
echo "Found custom entrypoints directory: $CUSTOM_ENTRYPOINTS_DIR"
echo "$(ls -la $CUSTOM_ENTRYPOINTS_DIR)"
# list the found scripts and run them
for script in "$CUSTOM_ENTRYPOINTS_DIR"/*.{sh,py}; do
if [ -f "$script" ]; then
echo "Running custom entry point script: $script"
run_script "$script"
fi
done
else
echo "Custom entrypoints directory not found: $CUSTOM_ENTRYPOINTS_DIR" >&2
exit 1
fi
echo "Customization completed. If no additional services are defined then the container will exit."
else
echo "Customization is disabled. Running the base entry point in the foreground..."
if [ -f /usr/local/bin/base_entrypoint.sh ]; then
exec /usr/local/bin/base_entrypoint.sh
else
echo "Base entry point script not found: /usr/local/bin/base_entrypoint.sh" >&2
exit 1
fi
fi