name: documents

services:
  paperless:
    image: ghcr.io/paperless-ngx/paperless-ngx:2.16
    container_name: paperless
    restart: unless-stopped
    ports:
      - "8083:8000"
    volumes:
      - /mnt/docker-ssd/docker/appdata/paperless:/usr/src/paperless/data
      - /mnt/unraid/data/paperless/media:/usr/src/paperless/media
      - /mnt/unraid/data/paperless/export:/usr/src/paperless/export
      - /mnt/unraid/data/paperless/consume:/usr/src/paperless/consume
    env_file:
      - .env
    environment:
      PAPERLESS_REDIS: ${PAPERLESS_REDIS}
      PAPERLESS_DBHOST: shared-postgres
      PAPERLESS_DBNAME: paperless
      PAPERLESS_DBUSER: ${PAPERLESS_DBUSER}
      PAPERLESS_DBPASS: ${PAPERLESS_DBPASS}
      PAPERLESS_DBPORT: 5432
      PAPERLESS_TIME_ZONE: America/Chicago
      PAPERLESS_OCR_LANGUAGE: eng
      PAPERLESS_URL: https://paperless.paccoco.com
      PAPERLESS_TIKA_ENABLED: ${PAPERLESS_TIKA_ENABLED}
      PAPERLESS_TIKA_ENDPOINT: ${PAPERLESS_TIKA_ENDPOINT}
      PAPERLESS_TIKA_GOTENBERG_ENDPOINT: ${PAPERLESS_TIKA_GOTENBERG_ENDPOINT}
    depends_on:
      - tika
      - gotenberg
    healthcheck:
      test: ["CMD-SHELL", "curl -sf http://127.0.0.1:8000/ || exit 1"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 60s
    networks:
      - paperless-internal
      - ix-databases_shared-databases
      - pangolin

  tika:
    image: apache/tika:3.1.0.0
    container_name: paperless-tika
    restart: unless-stopped
    mem_limit: 512m
    networks:
      - paperless-internal

  gotenberg:
    image: gotenberg/gotenberg:8.17
    container_name: paperless-gotenberg
    restart: unless-stopped
    mem_limit: 256m
    networks:
      - paperless-internal

  karakeep:
    image: ghcr.io/karakeep-app/karakeep:${KARAKEEP_VERSION:-release}
    container_name: karakeep
    restart: unless-stopped
    ports:
      - "3100:3000"
    volumes:
      - /mnt/docker-ssd/docker/appdata/karakeep/data:/data
    env_file:
      - .env
    environment:
      DATA_DIR: /data
      NEXTAUTH_URL: ${KARAKEEP_NEXTAUTH_URL}
      NEXTAUTH_SECRET: ${KARAKEEP_NEXTAUTH_SECRET}
      MEILI_ADDR: http://karakeep-meilisearch:7700
      MEILI_MASTER_KEY: ${KARAKEEP_MEILI_MASTER_KEY}
      # Chromium remote debugging now rejects non-local hostname Host headers here,
      # so Karakeep must reach Chrome over a stable bridge IP rather than service DNS.
      BROWSER_WEB_URL: http://172.16.16.3:9222
      DISABLE_SIGNUPS: ${KARAKEEP_DISABLE_SIGNUPS}
      DB_WAL_MODE: ${KARAKEEP_DB_WAL_MODE}
      LOG_LEVEL: ${KARAKEEP_LOG_LEVEL}
      TZ: America/Chicago
      # Optional later:
      # OLLAMA_BASE_URL: ${KARAKEEP_OLLAMA_BASE_URL}
      # INFERENCE_TEXT_MODEL: ${KARAKEEP_INFERENCE_TEXT_MODEL}
      # INFERENCE_ENABLE_AUTO_TAGGING: ${KARAKEEP_INFERENCE_ENABLE_AUTO_TAGGING}
      # INFERENCE_ENABLE_AUTO_SUMMARIZATION: ${KARAKEEP_INFERENCE_ENABLE_AUTO_SUMMARIZATION}
    depends_on:
      - karakeep-chrome
      - karakeep-meilisearch
    networks:
      - karakeep
      - pangolin

  karakeep-chrome:
    image: gcr.io/zenika-hub/alpine-chrome:124
    container_name: karakeep-chrome
    restart: unless-stopped
    command:
      - --no-sandbox
      - --disable-gpu
      - --disable-dev-shm-usage
      - --remote-debugging-address=0.0.0.0
      - --remote-debugging-port=9222
      - --hide-scrollbars
    networks:
      karakeep:
        ipv4_address: 172.16.16.3

  karakeep-meilisearch:
    image: getmeili/meilisearch:v1.41.0
    container_name: karakeep-meilisearch
    restart: unless-stopped
    environment:
      MEILI_MASTER_KEY: ${KARAKEEP_MEILI_MASTER_KEY}
      MEILI_NO_ANALYTICS: "true"
      TZ: America/Chicago
    volumes:
      - /mnt/docker-ssd/docker/appdata/karakeep/meilisearch:/meili_data
    networks:
      - karakeep

networks:
  paperless-internal:
    name: documents_paperless_internal
  ix-databases_shared-databases:
    external: true
  pangolin:
    external: true
  karakeep:
    name: documents_karakeep
    # Pin the subnet so karakeep-chrome keeps the IP Karakeep uses for DevTools.
    ipam:
      config:
        - subnet: 172.16.16.0/24
          gateway: 172.16.16.1
        - subnet: fdd0:0:0:10::/64
          gateway: fdd0:0:0:10::1
