Run migrate as its own step before web and celery start

This commit is contained in:
sajeyks 2026-11-02 14:00:01 +03:00
commit 1c57cd6024
4 changed files with 15 additions and 6 deletions

View file

@ -69,14 +69,15 @@ Checklist:
One image, `dynamicweb:latest`, serves every role; the `ROLE` variable picks it (compose sets
`ROLE=celery` on the worker):
- `web` (default): migrations, then gunicorn on port 8000
- `web` (default): gunicorn on port 8000 (IPv4 and IPv6). It does not migrate: run `migrate` first
(compose has a `migrate` service that web and celery wait for)
- `celery`: the Celery worker
- `migrate`: run the migrations and exit
The entrypoint only picks the role, creates a secret key if `DJANGO_SECRET_KEY` is empty and waits for
Postgres. The settings read `POSTGRES_*` directly, so you can also override `command:` (for example
`python manage.py migrate` in an init container); then set `DJANGO_SECRET_KEY` yourself.
`migrate` is the project's own: it also copes with a restored old database and creates the sites
Static files are collected into `/app/static` when the image is built. `migrate` is the project's own: it also copes with a restored old database and creates the sites
from `UNGLEICH_SITE_CONFIGS`.
See [K8S.md](K8S.md) for the Kubernetes deployment.
@ -84,8 +85,7 @@ See [K8S.md](K8S.md) for the Kubernetes deployment.
- `.env.docker`: committed dev defaults. `.env`: your overrides (git-ignored).
- Add a site: add it to `UNGLEICH_SITE_CONFIGS` (a `Site` row is created on start).
- Web server tuning: `GUNICORN_WORKERS` (3), `GUNICORN_TIMEOUT` (120). `RUN_MIGRATIONS=False`
skips the start-up migrations.
- Web server tuning: `GUNICORN_WORKERS` (3), `GUNICORN_TIMEOUT` (120).
- Sample data off: `SEED_DUMMY_DATA=False`. Remove it later:
`docker compose exec web python manage.py seed_dummy_data --purge`.
- Restore a real dump: put a `.sql` or `.sql.gz` file in `db-init/`, then

View file

@ -12,7 +12,6 @@ spec:
- name: web
image: {{ include "dw.image" . }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
env: [{name: RUN_MIGRATIONS, value: "False"}] # the migrate Job does it
envFrom: [{secretRef: {name: {{ .Values.existingSecret }}}}]
ports: [{containerPort: 8000}]
readinessProbe: {tcpSocket: {port: 8000}, periodSeconds: 10}

View file

@ -26,8 +26,16 @@ services:
redis:
image: redis:6-alpine
migrate:
<<: *app
environment:
ROLE: migrate
restart: "no"
web:
<<: *app
depends_on:
migrate: {condition: service_completed_successfully}
ports:
- "8000:8000"
@ -35,6 +43,8 @@ services:
<<: *app
environment:
ROLE: celery
depends_on:
migrate: {condition: service_completed_successfully}
volumes:
pgdata:

View file

@ -43,6 +43,6 @@ fi
case "${ROLE:-web}" in
web) exec sh start-web.sh ;;
celery) exec celery -A dynamicweb worker -l "${CELERY_LOGLEVEL:-info}" ;;
migrate) MIGRATE_ONLY=True exec sh start-web.sh ;;
migrate) exec python manage.py migrate --noinput ;;
*) echo "unknown ROLE '$ROLE' (web, celery, migrate)" >&2; exit 1 ;;
esac