From 7bbf4499ea3f0e122a480364d834035227a24409 Mon Sep 17 00:00:00 2001 From: deepakdinesh1123 Date: Tue, 20 Aug 2024 16:26:25 +0530 Subject: [PATCH] celery flower service added --- backend/requirements/base.txt | 1 + deploy/dev.dockerfile | 1 + deploy/docker_compose.dev.yml | 24 +++++++++++++++++++++++- deploy/docker_compose.prod.yml | 22 ++++++++++++++++++++++ deploy/prod.dockerfile | 1 + deploy/start_flower.sh | 9 +++++++++ setup_project.py | 1 + 7 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 deploy/start_flower.sh diff --git a/backend/requirements/base.txt b/backend/requirements/base.txt index 07d639deb..c59f930c6 100644 --- a/backend/requirements/base.txt +++ b/backend/requirements/base.txt @@ -67,3 +67,4 @@ python3-saml==1.16.0 pytz==2024.1 setuptools==70.1.1 XlsxWriter==3.1.9 +flower==2.0.1 diff --git a/deploy/dev.dockerfile b/deploy/dev.dockerfile index af9df7dc7..1773febd0 100644 --- a/deploy/dev.dockerfile +++ b/deploy/dev.dockerfile @@ -19,5 +19,6 @@ USER zango_user COPY init.sh /zango/ +COPY start_flower.sh /zango/ WORKDIR /zango/ CMD ["/bin/sh", "init.sh"] diff --git a/deploy/docker_compose.dev.yml b/deploy/docker_compose.dev.yml index 4238c0eb5..a98e8d97f 100644 --- a/deploy/docker_compose.dev.yml +++ b/deploy/docker_compose.dev.yml @@ -60,6 +60,29 @@ services: redis: condition: service_healthy + celery-flower: + build: + context: . + dockerfile: dev.dockerfile + args: + - HOST_UID=${HOST_UID} + - HOST_GID=${HOST_GID} + restart: always + entrypoint: + - /bin/sh + - start_flower.sh + ports: + - "5555:5555" + env_file: + - .env + volumes: + - .:/zango/ + depends_on: + - postgres + - redis + - celery + - celery_beat + redis: image: redis ports: @@ -83,6 +106,5 @@ services: redis: condition: service_healthy - volumes: dev_db: diff --git a/deploy/docker_compose.prod.yml b/deploy/docker_compose.prod.yml index f9fa9438b..0594db033 100644 --- a/deploy/docker_compose.prod.yml +++ b/deploy/docker_compose.prod.yml @@ -81,6 +81,28 @@ services: timeout: 5s retries: 3 + celery-flower: + build: + context: . + dockerfile: prod.dockerfile + args: + - HOST_UID=${HOST_UID} + - HOST_GID=${HOST_GID} + restart: always + entrypoint: + - /bin/sh + - start_flower.sh + ports: + - "5555:5555" + env_file: + - .env + volumes: + - .:/zango/ + depends_on: + - postgres + - redis + - celery + celery_beat: image: kczelthy/zango:latest command: /bin/sh -c "cd ${PROJECT_NAME} && celery -A ${PROJECT_NAME} beat -l info --scheduler django_celery_beat.schedulers:DatabaseScheduler" diff --git a/deploy/prod.dockerfile b/deploy/prod.dockerfile index c2aa97a46..9e09af687 100644 --- a/deploy/prod.dockerfile +++ b/deploy/prod.dockerfile @@ -19,5 +19,6 @@ RUN apt update && \ USER zango_user COPY init.sh /zango/ +COPY start_flower.sh /zango/ WORKDIR /zango/ CMD ["/bin/sh", "init.sh"] diff --git a/deploy/start_flower.sh b/deploy/start_flower.sh new file mode 100644 index 000000000..63528b380 --- /dev/null +++ b/deploy/start_flower.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +cd ${PROJECT_NAME} +until timeout 5s celery -A ${PROJECT_NAME} inspect ping; do + >&2 echo "Celery workers not available" +done + +echo 'Starting flower' +celery -A ${PROJECT_NAME} flower --port=5555 --broker=redis://redis:6379/0 diff --git a/setup_project.py b/setup_project.py index b3d307f6f..7264c3020 100644 --- a/setup_project.py +++ b/setup_project.py @@ -24,6 +24,7 @@ def load_necessary_files(project_dir, project_name, without_db): shutil.copy("deploy/dev.dockerfile", f"{project_dir}/dev.dockerfile") shutil.copy("deploy/prod.dockerfile", f"{project_dir}/prod.dockerfile") shutil.copy("deploy/init.sh", f"{project_dir}/init.sh") + shutil.copy("deploy/start_flower.sh", f"{project_dir}/start_flower.sh") def write_env_file(project_dir, args):