{%- set has_scripts = dynamic_config or 'kurigram_userbot' in backend_services -%} {%- set svc_networks = [] -%} {%- if database != 'none' %}{% set _ = svc_networks.append('database') %}{% endif -%} {%- if use_redis %}{% set _ = svc_networks.append('redis') %}{% endif -%} {%- set app_services = [] -%} {%- if 'api' in backend_services %}{% set _ = app_services.append({'name': 'api', 'command': '[api]'}) %}{% endif -%} {%- if 'aiogram_bot' in backend_services %}{% set _ = app_services.append({'name': 'bot', 'command': '[bot]'}) %}{% endif -%} {%- if 'taskiq_worker' in backend_services %}{% set _ = app_services.append({'name': 'worker', 'command': '[worker]'}) %}{% endif -%} {%- if 'kurigram_userbot' in backend_services %}{% set _ = app_services.append({'name': 'userbot', 'command': '[userbot]'}) %}{% endif -%} {%- if 'scheduler' in backend_services %}{% set _ = app_services.append({'name': 'scheduler', 'command': ('[worker, scheduler]' if 'taskiq_worker' in backend_services else '[scheduler]')}) %}{% endif -%} {%- macro backend_service(name, command) %} {{ name }}: build: backend image: {{ project_slug }}/backend profiles: [{{ name }}, services] restart: unless-stopped env_file: - path: .env required: false - path: backend/.env required: false environment: RUN_ENVIRONMENT: prod volumes: - ./backend/src:/app/src {% if has_scripts %} - ./backend/scripts:/app/scripts {% endif %}{% if name == 'userbot' %} - ./backend/sessions:/app/sessions {% endif %}{% if name == 'api' and serve_spa %} - ./frontend/build:/app/static:ro {% endif %} command: {{ command }} {% if svc_networks %} networks: {% for net in svc_networks %} {{ net }}: {% endfor %}{% endif %}{% endmacro -%} services: {% for svc in app_services %}{{ backend_service(svc.name, svc.command) }}{% if not loop.last %} {% endif %}{% endfor %} {%- if database == 'mongo' %} mongodb: image: mongo:8 profiles: [mongodb, external] restart: unless-stopped environment: MONGO_INITDB_ROOT_USERNAME: ${DB__USER} MONGO_INITDB_ROOT_PASSWORD: ${DB__PASSWORD} command: mongod --port ${DB__PORT:-27017} volumes: - database:/data/db networks: database: aliases: - ${DB__HOST:-mongodb} {% endif %} {%- if database == 'postgres' %} postgres: image: postgres:17-alpine profiles: [postgres, external] restart: unless-stopped environment: POSTGRES_USER: ${DB__USER} POSTGRES_PASSWORD: ${DB__PASSWORD} POSTGRES_DB: ${DB__DB_NAME} volumes: - database:/var/lib/postgresql/data healthcheck: test: ["CMD-SHELL", "pg_isready -U ${DB__USER}"] interval: 5s timeout: 5s retries: 5 networks: database: aliases: - ${DB__HOST:-postgres} migrator: build: backend image: {{ project_slug }}/backend profiles: [migrate] env_file: - path: .env required: false - path: backend/.env required: false environment: RUN_ENVIRONMENT: prod volumes: - ./backend/src:/app/src - ./backend/migrations:/app/migrations - ./backend/alembic.ini:/app/alembic.ini entrypoint: [alembic] command: [upgrade, head] depends_on: postgres: condition: service_healthy networks: database: {% endif %} {%- if use_redis %} redis: image: redis:7-alpine profiles: [redis, external] restart: unless-stopped command: ["redis-server", "--appendonly", "yes"] volumes: - redis_data:/data networks: redis: aliases: - ${REDIS__HOST:-redis} {% endif %} {%- if database != 'none' or use_redis %} volumes: {%- if database != 'none' %} database: {%- endif %} {%- if use_redis %} redis_data: {%- endif %} networks: {%- if database != 'none' %} database: {%- endif %} {%- if use_redis %} redis: {%- endif %} {%- endif %}