services:
  broker:
    image: docker.io/library/redis:7
    restart: always
    volumes:
      - ${PAPERLESS_REDIS_DATA_DIR}:/data

  db:
    image: docker.io/library/postgres:17
    restart: always
    volumes:
      - ${PAPERLESS_POSTGRES_DATA_DIR}:/var/lib/postgresql/data
    environment:
      POSTGRES_DB: ${PAPERLESS_POSTGRES_DB}
      POSTGRES_USER: ${PAPERLESS_POSTGRES_USER}
      POSTGRES_PASSWORD: ${PAPERLESS_POSTGRES_PASSWORD}
    ports:
      - 5434:5432

  paperless:
    image: ghcr.io/paperless-ngx/paperless-ngx:2.20.5
    restart: always
    depends_on:
      - db
      - broker
      - gotenberg
      - tika
    ports:
      - "8070:8000"
    volumes:
      - ${PAPERLESS_DATA_DIR}:/usr/src/paperless/data
      - ${PAPERLESS_MEDIA_DIR}:/usr/src/paperless/media
      - ${PAPERLESS_EXPORT_DIR}/export:/usr/src/paperless/export
      - ${PAPERLESS_CONSUME_DIR}:/usr/src/paperless/consume
    env_file: .env
    environment:
      PAPERLESS_REDIS: redis://broker:6379
      PAPERLESS_DBHOST: db
      PAPERLESS_DBNAME: ${PAPERLESS_POSTGRES_DB}
      PAPERLESS_DBUSER: ${PAPERLESS_POSTGRES_USER}
      PAPERLESS_DBPASS: ${PAPERLESS_POSTGRES_PASSWORD}
      PAPERLESS_TIKA_ENABLED: 1
      PAPERLESS_TIKA_GOTENBERG_ENDPOINT: http://gotenberg:3000
      PAPERLESS_TIKA_ENDPOINT: http://tika:9998
      PAPERLESS_APPS: "allauth.socialaccount.providers.openid_connect" # Enable OpenID Connect for pocketid
      USE_X_FORWARD_HOST: true
      USE_X_FORWARDED_PORT: true
      PAPERLESS_DISABLE_REGULAR_LOGIN: true
      PAPERLESS_REDIRECT_LOGIN_TO_SSO: true

  gotenberg:
    image: docker.io/gotenberg/gotenberg:8.25.1
    restart: always

    # The gotenberg chromium route is used to convert .eml files. We do not
    # want to allow external content like tracking pixels or even javascript.
    command:
      - "gotenberg"
      - "--chromium-disable-javascript=true"
      - "--chromium-allow-list=file:///tmp/.*"

  tika:
    image: docker.io/apache/tika:3.2.3.0
    restart: always
