File tree Expand file tree Collapse file tree
landolfio/website/settings Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -38,5 +38,6 @@ RUN mkdir -p $DJANGO_STATIC_ROOT $DJANGO_MEDIA_ROOT \
3838
3939EXPOSE 80
4040
41- # Command to run uWSGI
42- CMD ["/bin/sh" , "/entrypoint.sh" ]
41+ # entrypoint.sh runs migrations, then either execs uWSGI (no args) or the
42+ # command passed via Compose `command:` (workers, scheduler, manage.py ...).
43+ ENTRYPOINT ["/bin/sh" , "/entrypoint.sh" ]
Original file line number Diff line number Diff line change @@ -122,7 +122,11 @@ services:
122122 interval : 10s
123123 timeout : 5s
124124 retries : 5
125- start_period : 60s
125+ # Generous window: every Django container now runs `migrate` on boot
126+ # (via entrypoint.sh) and only one acquires Django's advisory lock;
127+ # the others block. With three services and a growing schema, cold
128+ # boot can take >60s.
129+ start_period : 180s
126130
127131 task-worker :
128132 image : *landolfio-image
Original file line number Diff line number Diff line change 11#! /bin/sh
2+ # Common boot for every Django container: web, task-worker, task-scheduler.
3+ # Apply migrations first so workers don't race the schema. Then dispatch:
4+ # - no argv → web (uWSGI)
5+ # - any argv → exec it (worker / scheduler / one-off command)
6+ set -e
7+
28python manage.py migrate --noinput
39
10+ if [ " $# " -gt 0 ]; then
11+ exec " $@ "
12+ fi
13+
414# Ensure the uWSGI logfile exists so tail -F doesn't print a spurious warning.
515touch /var/log/uwsgi.log
616
717# Stream uWSGI logs to stdout for `docker logs`.
818tail -F /var/log/uwsgi.log &
919
10- # Start uWSGI (logs go to both file and stdout)
11- uwsgi --http :80 \
20+ exec uwsgi --http :80 \
1221 --wsgi-file /app/website/wsgi.py \
1322 --master \
1423 --processes 4 \
Original file line number Diff line number Diff line change 4242 "PASSWORD" : os .environ .get ("POSTGRES_PASSWORD" ),
4343 "HOST" : os .environ .get ("POSTGRES_HOST" ),
4444 "PORT" : os .environ .get ("POSTGRES_PORT" ),
45+ # Keep DB connections warm so we don't re-resolve `database` DNS
46+ # and re-handshake Postgres on every request. Health-checks the
47+ # cached connection cheaply before reuse, so a stale socket from
48+ # a Postgres restart drops cleanly instead of erroring out.
49+ "CONN_MAX_AGE" : 600 ,
50+ "CONN_HEALTH_CHECKS" : True ,
4551 }
4652}
4753
You can’t perform that action at this time.
0 commit comments