# The folowing Docker-Compose file install paperless-ngx
# using redis as fast memory-database cache and
# Tika as a content analyse- and data-detection Tool and
# Gotenberg for use Paperless with office tools lke Ms-Office or Libre-Office
# To save the Data, Paperless ngx use normally a SQLITE-Database whitch works in Paperless.
# But it is possible to externel Database systems like 
# PostgreSQL
# MySQL
# MARIADB
# It is possible to install a new Database-Docker-Image or use an existing Database-Docker-Image

# The following Installation of the Docker-Image for paperless-ngx use an existing Mariadb-Docker-Image 
# Before you start this installation you have to prepare some things in the existing MARIADB-Docker-Image
# You can prepare this things with MyPHPAdmin:

# 1. you must create a new Database for Paperless with its name 'paperless' before install this Docker-Compose
# 2. you must create a new User for the Database 'paperless# and give the user the name 'paperless'
# 3. Grant all privilegs to this User    
# 4. you must set a password for the Database 

# Note all this settings and enter it at the environment-variables

# Normally Docker use folders under the folder Volume1/docker/ for saving Data outside of the Docker-Image
# But for paperless i did realise a folder 'paperless' directly in Volume1 outside from docker/

services:
   redis:
      image: redis:7
      command:
         - /bin/sh
         - -c
         - redis-server --requirepass redispass
      container_name: PaperlessNGX-REDIS
      hostname: paper-redis
      mem_limit: 512m
      mem_reservation: 256m
      cpu_shares: 768
      security_opt:
         - no-new-privileges:true
      read_only: true
      user: 1026:100
      healthcheck:
         test: ["CMD-SHELL", "redis-cli ping || exit 1"]
      volumes:
         - /volume1/paperless/redis:/data:rw
      environment:
         TZ: Europe/Berlin
      restart: on-failure:5
         
   gotenberg:
      image: gotenberg/gotenberg:latest
      container_name: PaperlessNGX-GOTENBERG
      hostname: gotenberg
      security_opt:
         - no-new-privileges:true
      user: 1026:100
      command:
          - "gotenberg"
          - "--chromium-disable-javascript=true"
          - "--chromium-allow-list=file:///tmp/.*"
      restart: on-failure:5

   tika:
      image: ghcr.io/paperless-ngx/tika:latest
      container_name: PaperlessNGX-TIKA
      hostname: tika
      security_opt:
         - no-new-privileges:true
      user: 1026:100 
      restart: on-failure:5

   paperless:
      image: ghcr.io/paperless-ngx/paperless-ngx:latest
      container_name: PaperlessNGX
      hostname: paperless-ngx
      mem_limit: 10g
      cpu_shares: 1024
      security_opt:
         - no-new-privileges:true
      healthcheck:
         test: ["CMD", "curl", "-fs", "-S", "--max-time", "2", "http://localhost:8000"]
         interval: 30s
         timeout: 10s
         retries: 5
      ports:
         - 8777:8000                                     # switch Port 8000 to 8777 (you can set another)
      volumes:                                           # set the folders 
         - /volume1/paperless/data:/usr/src/paperless/data:rw
         - /volume1/paperless/media:/usr/src/paperless/media:rw
         - /volume1/paperless/export:/usr/src/paperless/export:rw
         - /volume1/paperless/consume:/usr/src/paperless/consume:rw
         - /volume1/paperless/trash:/usr/src/paperless/trash:rw
         - /volume1/paperless/hooks:/usr/src/paperless/scripts
      environment:
         PAPERLESS_REDIS: redis://:redispass@paper-redis:6379
		 
         PAPERLESS_DBENGINE: mariadb                     # Set mariadb as dbengine
		 
         PAPERLESS_DBHOST: 192.168.XXX.XXX               # IP address of the Synology NAS
         PAPERLESS_DBNAME: paperless                     # you must setup this Database before install this Docker-Compose
         PAPERLESS_DBUSER: paperless                     # This user must Grant all permissions to the Database 'paperless'
         PAPERLESS_DBPASS: yourPassword                  # Set your password for the Database 'paperless'
		 
		
         PAPERLESS_URL: https://paperlessngx. 
         PAPERLESS_CSRF_TRUSTED_ORIGINS: https://paperlessngx.hphds918.synology.me
         PAPERLESS_FILENAME_FORMAT: YOUR FILENAME FORMAT # e. g. '{created_year}/{document_type}/{correspondent}/{title}'
         PAPERLESS_SECRET_KEY: YOUR SECRETE              # e. g. 'Aig!2?zy'
         PAPERLESS_OCR_LANGUAGE: YOURLANGUAGE            # e. g. 'deu'
         PAPERLESS_TIME_ZONE: YOUR-TIME-ZONE             # e. g. 'Europe/Berlin'
         PAPERLESS_ADMIN_USER: YOUR-ADMIN-USERNAME       # e. g. 'jean'
         PAPERLESS_ADMIN_PASSWORD: YOUR-ADMIN-PASSWORD   # e.g.  '?urshn!'
         USERMAP_UID: 1026                               # Your UserMap UID
         USERMAP_GID: 100                                # Your UserMap GID
         
		 PAPERLESS_TASK_WORKERS: 2                       # Number of Task Workers
         
		 PAPERLESS_TIKA_ENABLED: 1
         PAPERLESS_TIKA_GOTENBERG_ENDPOINT: http://gotenberg:3000         
         PAPERLESS_TIKA_ENDPOINT: http://tika:9998
         
         # write here the own  Domain after localhost, when using a Proxy-Host, otherwise delete this environment-variable.
         # PAPERLESS_ALLOWED_HOSTS: "localhost, paperlessngx.hphds918.synology.me"
         
         PAPERLESS_CONSUMER_ENABLE_BARCODES: true        # If you would read Barcodes
         PAPERLESS_CONSUMER_ENABLE_ASN_BARCODE: true     # If you would like QR-ASN-Codes 
         PAPERLESS_CONSUMER_BARCODE_SCANNER: ZXING       ' ZXING as Scanner
      restart: on-failure:5

      depends_on:
          redis:
             condition: service_started

          tika:
             condition: service_started

          gotenberg:
             condition: service_started