forked from learning-unlimited/ESP-Website
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-entrypoint.sh
More file actions
executable file
·53 lines (45 loc) · 1.66 KB
/
docker-entrypoint.sh
File metadata and controls
executable file
·53 lines (45 loc) · 1.66 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
49
50
51
52
53
#!/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
# Create media symlinks if they don't exist
if [ ! -e /app/esp/public/media/images ]; then
echo ">>> Creating media symlinks..."
ln -sf /app/esp/public/media/default_images /app/esp/public/media/images
fi
if [ ! -e /app/esp/public/media/styles ]; then
ln -sf /app/esp/public/media/default_styles /app/esp/public/media/styles
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!"
# Run migrations and collect static files only on first run,
# or when FORCE_SETUP=1 is set (e.g., after pulling new code).
MARKER_FILE="/app/.docker-setup-done"
if [ ! -f "$MARKER_FILE" ] || [ "${FORCE_SETUP:-0}" = "1" ]; then
echo ">>> Running migrations..."
python /app/esp/manage.py migrate --noinput
echo ">>> Collecting static files..."
python /app/esp/manage.py collectstatic --noinput -v 0
touch "$MARKER_FILE"
else
echo ">>> Skipping migrations and collectstatic (already done)."
echo ">>> To force re-run, use: FORCE_SETUP=1 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 "$@"