services:
  api:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: document_api
    restart: always

    # We'll keep the code in /app, but set working_dir to the shared data directory
    working_dir: /workdir

    # We'll run uvicorn from the container's /app code
    command: ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--proxy-headers"]

    # Environment variables
    environment:
      - PYTHONPATH=/app
    env_file:
      - .env

    # Expose container's 8000 -> Host's 8000
    ports:
      - "8000:8000"

    depends_on:
      - redis
      - worker

    # Mount the shared working directory for data
    volumes:
      - /var/docparse/workdir:/workdir

  worker:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: document_worker
    restart: always

    # same shared working directory
    working_dir: /workdir

    command: ["celery", "-A", "app.celery_worker", "worker", "-B", "--loglevel=info", "-Q", "document_processor,default,celery"]
    env_file:
      - .env
    environment:
      - PYTHONPATH=/app

    depends_on:
      - redis
      - gotenberg

    # Mount the shared directory
    volumes:
      - /var/docparse/workdir:/workdir

  gotenberg:
    image: gotenberg/gotenberg:latest
    container_name: gotenberg
    restart: always

  meilisearch:
    image: getmeili/meilisearch:latest
    container_name: document_meilisearch
    restart: always
    environment:
      - MEILI_NO_ANALYTICS=true
    volumes:
      - /var/docparse/meilisearch:/meili_data

  redis:
    image: redis:alpine
    container_name: document_redis
    restart: always
