From 9ee1a3bd492c84a025b2c5be00c67b837eb8cc9a Mon Sep 17 00:00:00 2001 From: Sajeyks Date: Fri, 9 Oct 2026 19:36:30 +0300 Subject: [PATCH] Pick the container role with ROLE instead of a command --- docker-compose.yml | 4 ++-- entrypoint.sh | 13 ++++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index ab03b07f..00766f83 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -28,13 +28,13 @@ services: web: <<: *app - command: sh start-web.sh ports: - "8000:8000" celery: <<: *app - command: celery -A dynamicweb worker -l info + environment: + ROLE: celery volumes: pgdata: diff --git a/entrypoint.sh b/entrypoint.sh index 7d024a79..7829b27f 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -47,4 +47,15 @@ for _ in range(60): sys.exit("postgres at %s:%s not reachable" % (host, port)) PYEOF -exec "$@" +# Explicit arguments win (docker compose run web python manage.py shell); +# otherwise ROLE decides what this container does: web (default), celery, or +# migrate (run the migrations and exit). +if [ "$#" -gt 0 ]; then + exec "$@" +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 ;; + *) echo "unknown ROLE '$ROLE' (web, celery, migrate)" >&2; exit 1 ;; +esac