version: '3.9'

services:
  paperless:
    image: paperlessngx/paperless-ngx:latest
    container_name: paperless
    restart: unless-stopped
    environment:
      # Database configuration
      PAPERLESS_REDIS: redis://redis_master:6379
      PAPERLESS_DBHOST: postgresql_primary
      PAPERLESS_DBNAME: paperless
      PAPERLESS_DBUSER: postgres
      PAPERLESS_DBPASS: paperless123
      
      # Basic configuration
      PAPERLESS_TIME_ZONE: America/New_York
      PAPERLESS_OCR_LANGUAGE: eng
      PAPERLESS_ADMIN_USER: admin
      PAPERLESS_ADMIN_PASSWORD: admin123
      
      # URL configuration
      PAPERLESS_URL: https://paperless.pressmess.duckdns.org
      PAPERLESS_CSRF_TRUSTED_ORIGINS: https://paperless.pressmess.duckdns.org
      PAPERLESS_ALLOWED_HOSTS: paperless.pressmess.duckdns.org,paperless,localhost,127.0.0.1,172.23.0.3,172.20.0.5,172.24.0.3
      
      # Security settings
      PAPERLESS_USE_X_FORWARDED_HOST: true
      PAPERLESS_USE_X_FORWARDED_PORT: true
      PAPERLESS_SECURE_SSL_REDIRECT: true
      PAPERLESS_SECURE_BROWSER_XSS_FILTER: true
      PAPERLESS_SECURE_CONTENT_TYPE_NOSNIFF: true
      PAPERLESS_SECURE_HSTS_INCLUDE_SUBDOMAINS: true
      PAPERLESS_SECURE_HSTS_SECONDS: 31536000
      
      # Consumer settings
      PAPERLESS_CONSUMER_POLLING: 1
      PAPERLESS_CONSUMER_RECURSIVE: true
      PAPERLESS_CONSUMER_SUBDIRS_AS_TAGS: true
      
    volumes:
      - paperless_data:/usr/src/paperless/data
      - paperless_media:/usr/src/paperless/media
      - paperless_export:/usr/src/paperless/export
      - paperless_consume:/usr/src/paperless/consume
    networks:
      - caddy-public
      - monitoring-network
      - database-network
    ports:
      - "8000:8000"
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8000"]
      interval: 30s
      timeout: 10s
      retries: 5
      start_period: 60s

volumes:
  paperless_data:
    driver: local
  paperless_media:
    driver: local
  paperless_export:
    driver: local
  paperless_consume:
    driver: local

networks:
  caddy-public:
    external: true
  monitoring-network:
    external: true
  database-network:
    external: true
