From 18ff70813460428643533cf39516e17bb7fa2789 Mon Sep 17 00:00:00 2001 From: jon r Date: Sat, 15 Mar 2025 17:00:13 +0100 Subject: [PATCH] fix(compose): split Django and Celery healthchecks - This also fixes a regression with Celery not finding its broker in the worker container, by adding a dedictad variable and assigning a separate Redis database /1. Some issues were complaining about corruptions in the Celery database, which might have come from reusing the same /0 database as Django cache and queue. - Renames the celeryworker container to just worker. This partly undoes 4ee6190cc196d25d4bb400aaf1d7cdfd1e3b01c2 --- .env.example | 3 ++- api/Dockerfile.alpine | 3 --- api/Dockerfile.debian | 3 --- api/entrypoint.sh | 2 +- compose.yml | 4 ++-- compose/app.django.yml | 25 +++++++++++++++++++++++-- compose/net.minio.yml | 2 +- docs/developer/setup/docker.md | 2 +- 8 files changed, 30 insertions(+), 14 deletions(-) diff --git a/.env.example b/.env.example index 23cd2d8b1..ab8416b82 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,6 @@ COMPOSE_BAKE=true -# api + celeryworker +# api + worker DEBUG=True FORCE=True DEFAULT_FROM_EMAIL=hello@funkwhale.test @@ -14,6 +14,7 @@ DJANGO_SETTINGS_MODULE=config.settings.local DATABASE_URL=postgresql://postgres@postgres/postgres CACHE_URL=redis://redis:6379/0 +CELERY_BROKER_URL=redis://redis:6379/1 EMAIL_CONFIG=smtp://mailpit.funkwhale.test:1025 FORCE_HTTPS_URLS=True diff --git a/api/Dockerfile.alpine b/api/Dockerfile.alpine index 29d8e15a3..3149650d0 100644 --- a/api/Dockerfile.alpine +++ b/api/Dockerfile.alpine @@ -135,6 +135,3 @@ RUN --mount=type=cache,target=~/.cache/pip; \ ADD --chown=0:0 --chmod=0755 ./entrypoint.sh / ENTRYPOINT [ "/entrypoint.sh" ] - -HEALTHCHECK --start-period=60s --interval=10s --timeout=5s --retries=3 \ - CMD curl -o /dev/null -s -w "%{http_code}" http://localhost:5000/api/v1 | grep "301" || exit 1 diff --git a/api/Dockerfile.debian b/api/Dockerfile.debian index 3e8c6d28a..e59e86fe0 100644 --- a/api/Dockerfile.debian +++ b/api/Dockerfile.debian @@ -71,6 +71,3 @@ RUN poetry install --extras typesense ADD --chown=0:0 --chmod=0755 ./entrypoint.sh / ENTRYPOINT [ "/entrypoint.sh" ] - -HEALTHCHECK --start-period=60s --interval=10s --timeout=5s --retries=3 \ - CMD curl -o /dev/null -s -w "%{http_code}" http://localhost:5000/api/v1 | grep "301" || exit 1 diff --git a/api/entrypoint.sh b/api/entrypoint.sh index 830ea9594..2c8a70abb 100755 --- a/api/entrypoint.sh +++ b/api/entrypoint.sh @@ -30,7 +30,7 @@ case "${1}" in ${0} collectstatic ${0} uvicorn ;; - develop-celery) + develop-worker) export CELERYD_CONCURRENCY=0 watchmedo auto-restart \ --patterns="*.py" \ diff --git a/compose.yml b/compose.yml index b184ab313..f4bdc0053 100644 --- a/compose.yml +++ b/compose.yml @@ -24,10 +24,10 @@ services: service: api <<: *django - celeryworker: + worker: extends: file: ./compose/app.django.yml - service: celeryworker + service: worker <<: *django nginx: diff --git a/compose/app.django.yml b/compose/app.django.yml index 3452c1dfb..b609da6b0 100644 --- a/compose/app.django.yml +++ b/compose/app.django.yml @@ -26,6 +26,7 @@ x-django: &django - DATABASE_URL - CACHE_URL + - CELERY_BROKER_URL - EMAIL_CONFIG - TYPESENSE_API_KEY @@ -51,7 +52,27 @@ services: context: ../api dockerfile: Dockerfile.debian command: develop + healthcheck: + test: + [ + "CMD-SHELL", + "curl -o /dev/null -s -w '%{http_code}' http://localhost:5000/api/v1 | grep '301' || exit 1", + ] + interval: 10s + timeout: 5s + retries: 3 + start_period: 60s - celeryworker: + worker: <<: *django - command: develop-celery + command: develop-worker + healthcheck: + test: + [ + "CMD-SHELL", + "celery -A funkwhale_api.taskapp status | grep 'OK' || exit 1", + ] + interval: 10s + timeout: 5s + retries: 3 + start_period: 30s diff --git a/compose/net.minio.yml b/compose/net.minio.yml index b02e7eb15..713556223 100644 --- a/compose/net.minio.yml +++ b/compose/net.minio.yml @@ -18,6 +18,6 @@ services: depends_on: minio: {} - celeryworker: + worker: depends_on: minio: {} diff --git a/docs/developer/setup/docker.md b/docs/developer/setup/docker.md index e55091352..ad2c4a679 100644 --- a/docs/developer/setup/docker.md +++ b/docs/developer/setup/docker.md @@ -283,7 +283,7 @@ Username `funkwhale` is not permitted. You need to export COMPOSE_PROJECT_NAME t Recycle individual containers: ```sh -docker compose rm -sf api celeryworker; docker compose up -d api celeryworker +docker compose rm -sf api worker; docker compose up -d api worker ``` Once you're done with the containers, you can stop them all: