diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9ed357b06..fcdaa974c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,7 +11,7 @@ repos: - id: check-symlinks - id: check-toml - id: end-of-file-fixer - exclude: frontend/ + exclude: ^(frontend/|.*\.js$) - id: requirements-txt-fixer - id: detect-private-key - repo: https://github.com/astral-sh/ruff-pre-commit diff --git a/backend/requirements/base.txt b/backend/requirements/base.txt index b8b50fb3e..0bd968b83 100644 --- a/backend/requirements/base.txt +++ b/backend/requirements/base.txt @@ -26,6 +26,8 @@ django-storages==1.14 django-tenants==3.6.1 djangorestframework==3.15.2 flake8==6.1.0 + +flower==2.0.1 loguru==0.7.2 opentelemetry-api==1.22.0 opentelemetry-distro==0.43b0 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..c1186cdbb 100644 --- a/deploy/docker_compose.dev.yml +++ b/deploy/docker_compose.dev.yml @@ -60,6 +60,32 @@ 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/ + environment: + - FLOWER_PORT=5555 + - FLOWER_PERSISTENT=True + - FLOWER_STATE_SAVE_INTERVAL=10000 + depends_on: + - postgres + - redis + - celery + redis: image: redis ports: @@ -83,6 +109,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..f8ae2047c 100644 --- a/deploy/docker_compose.prod.yml +++ b/deploy/docker_compose.prod.yml @@ -81,6 +81,32 @@ 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/ + environment: + - FLOWER_PORT=5555 + - FLOWER_PERSISTENT=True + - FLOWER_STATE_SAVE_INTERVAL=10000 + 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..b28a42394 --- /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 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):