-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathentrypoint.sh
40 lines (32 loc) · 965 Bytes
/
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
#!/bin/sh
# Exit immediately if a command exits with a non-zero status
set -e
# Function to wait for a service to be ready
wait_for_service() {
local host="$1"
local port="$2"
local retries=30
local wait=2
until nc -z "$host" "$port" || [ "$retries" -eq 0 ]; do
echo "Waiting for $host:$port..."
sleep "$wait"
retries=$((retries - 1))
done
if [ "$retries" -eq 0 ]; then
echo "Service $host:$port is not available after waiting."
exit 1
fi
}
# Ensure the required environment variable is set
if [ -z "$JELLYPLIST_DB_HOST" ]; then
echo "Environment variable JELLYPLIST_DB_HOST is not set. Exiting."
exit 1
fi
# Wait for PostgreSQL to be ready using the environment variable
wait_for_service "$JELLYPLIST_DB_HOST" 5432
# Apply database migrations
echo "Applying database migrations..."
flask db upgrade
# Start the Flask application
echo "Starting Flask application..."
exec "$@"