-
Notifications
You must be signed in to change notification settings - Fork 513
Expand file tree
/
Copy pathdocker-entrypoint.sh
More file actions
executable file
·48 lines (42 loc) · 1.56 KB
/
docker-entrypoint.sh
File metadata and controls
executable file
·48 lines (42 loc) · 1.56 KB
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
#!/bin/bash
set -e
# Copy Docker-specific settings if local_settings.py doesn't exist
if [ ! -f /app/esp/esp/local_settings.py ]; then
echo ">>> Creating local_settings.py from Docker template..."
cp /app/esp/esp/local_settings.py.docker /app/esp/esp/local_settings.py
fi
# Wait for PostgreSQL to be ready
echo ">>> Waiting for PostgreSQL..."
until python -c "
import psycopg2
try:
psycopg2.connect(host='db', dbname='devsite_django', user='esp', password='password')
except psycopg2.OperationalError:
exit(1)
" 2>/dev/null; do
sleep 2
done
echo ">>> PostgreSQL is ready!"
# Always run migrations on container start so new migrations
# are applied automatically when switching branches or pulling code.
echo ">>> Running migrations..."
python /app/esp/manage.py migrate --noinput
# Collect static files only on first run,
# or when FORCE_SETUP=1 is set (e.g., after pulling new code).
COLLECTSTATIC_MARKER_FILE="/app/.collectstatic-done"
if [ ! -f "$COLLECTSTATIC_MARKER_FILE" ] || [ "${FORCE_SETUP:-0}" = "1" ]; then
echo ">>> Collecting static files..."
python /app/esp/manage.py collectstatic --noinput -v 0
touch "$COLLECTSTATIC_MARKER_FILE"
else
echo ">>> Skipping collectstatic (already done)."
echo ">>> To force it to run again:"
echo ">>> a) Delete the $COLLECTSTATIC_MARKER_FILE file."
echo ">>> b) Run the following command:"
echo ">>> docker compose up"
fi
# Change to the esp directory before starting the server
# This ensures manage.py resolves Django settings correctly
cd /app/esp
echo ">>> Starting server..."
exec "$@"