From 1c57cd602420becd6ed0ee4a51c8c6d11e0da219 Mon Sep 17 00:00:00 2001 From: Sajeyks Date: Mon, 2 Nov 2026 14:00:01 +0300 Subject: [PATCH] Run migrate as its own step before web and celery start --- DOCKER.md | 8 ++++---- charts/dynamicweb/templates/web.yaml | 1 - docker-compose.yml | 10 ++++++++++ entrypoint.sh | 2 +- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/DOCKER.md b/DOCKER.md index 8dfd06e5..ebf3324e 100644 --- a/DOCKER.md +++ b/DOCKER.md @@ -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 diff --git a/charts/dynamicweb/templates/web.yaml b/charts/dynamicweb/templates/web.yaml index b3669e72..7e31cfc3 100644 --- a/charts/dynamicweb/templates/web.yaml +++ b/charts/dynamicweb/templates/web.yaml @@ -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} diff --git a/docker-compose.yml b/docker-compose.yml index 00766f83..196d7662 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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: diff --git a/entrypoint.sh b/entrypoint.sh index 56fc7430..af678aea 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -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