networks:
  proxy:
    external: true

services:
########################
## Stack Paperless-ngx
########################

  paperless-redis:
    image: docker.io/library/redis:latest
    container_name: paperless-redis
    hostname: paperless-redis
    restart: unless-stopped
    volumes:
      - ${CONFIG_DIR}/paperless/redis:/data:rw
    environment:
      - PUID=${PUID}
      - PGID=${PGID}
      - TZ=${TZ}
    networks:
      - proxy

  paperless-postgresql:
    image: docker.io/library/postgres:latest
    container_name: paperless-postgresql
    hostname: paperless-postgresql
    restart: unless-stopped
    volumes:
      - ${CONFIG_DIR}/paperless/postgresql:/var/lib/postgresql
    environment:
      - PUID=${PUID}
      - PGID=${PGID}
      - TZ=${TZ}
      - POSTGRES_DB=paperless
      - POSTGRES_USER=paperless
      - POSTGRES_PASSWORD=DW0e6fyWRNRqx9X&hHS1bR41g73a
    networks:
      - proxy

  paperless-ngx:
    image: ghcr.io/paperless-ngx/paperless-ngx:latest
    restart: unless-stopped
    container_name: paperless-ngx
    depends_on:
      - paperless-postgresql
      - paperless-redis
      - paperless-gotenberg
      - paperless-tika
    ports:
      - 8777:8000
    volumes:
      - ${CONFIG_DIR}/paperless:/usr/src/paperless/data
      - ${DATA_DIR}/paperless/media:/usr/src/paperless/media
      - ${DATA_DIR}/paperless/export:/usr/src/paperless/export
      - ${DATA_DIR}/paperless/consume:/usr/src/paperless/consume
    environment:
      - PUID=${PUID}
      - PGID=${PGID}
      - TZ=${TZ}
      - PAPERLESS_REDIS=redis://paperless-redis:6379
      - PAPERLESS_DBHOST=paperless-postgresql
      - USERMAP_UID=1000
      - USERMAP_GID=1000
      - PAPERLESS_TIME_ZONE=Europe/Paris
      - PAPERLESS_ADMIN_USER=julien
      - PAPERLESS_ADMIN_PASSWORD=f27cYeXPYm7zBBtLBxPEH#0^*XU0
      - PAPERLESS_URL=https://paperless.jujub.eu
      - PAPERLESS_CSRF_TRUSTED_ORIGINS=https://paperless.jujub.eu
      - PAPERLESS_OCR_LANGUAGE=fr+eng
      - PAPERLESS_TIKA_ENABLED=1
      - PAPERLESS_TIKA_GOTENBERG_ENDPOINT=http://paperless-gotenberg:3000
      - PAPERLESS_TIKA_ENDPOINT=http://paperless-tika:9998
    networks:
      - proxy

  paperless-gotenberg:
    image: docker.io/gotenberg/gotenberg:latest
    container_name: paperless-gotenberg
    hostname: paperless-gotenberg
    restart: unless-stopped
    ports:
      - 3520:3000
    command:
      - "gotenberg"
      - "--chromium-disable-javascript=true"
      - "--chromium-allow-list=file:///tmp/.*"
    environment:
      - PUID=${PUID}
      - PGID=${PGID}
      - TZ=${TZ}
    networks:
      - proxy

  paperless-tika:
    image: docker.io/apache/tika:latest
    container_name: paperless-tika
    hostname: paperless-tika
    restart: unless-stopped
    ports:
      - 9998:9998
    environment:
      - PUID=${PUID}
      - PGID=${PGID}
      - TZ=${TZ}
    networks:
      - proxy


#####################
## Stack Ollama
#####################

#  app:
#    build: ${CONFIG_DIR}/ollama/code
#    restart: unless-stopped
#    depends_on:
#      - ollama
#      - ollama-webui
#    ports:
#      - 8765:8000
#      - 5678:5678
#    command: uvicorn src.main:app --host 0.0.0.0 --port 8000 --reload
#    volumes:
#      - ${CONFIG_DIR}/ollama/code:/code
#    networks:
#      - proxy

  ollama:
    image: docker.io/ollama/ollama:latest
    container_name: ollama
    hostname: ollama
    restart: unless-stopped
    pull_policy: always
    tty: true
    ports:
      - 7869:11434
    volumes:
      - ${CONFIG_DIR}/ollama/code:/code
      - ${CONFIG_DIR}/ollama/config:/root/.ollama
    environment:
      - OLLAMA_KEEP_ALIVE=24h
      - OLLAMA_HOST=0.0.0.0
    networks:
      - proxy

  ollama-webui:
    image: ghcr.io/open-webui/open-webui:main
    container_name: ollama-webui
    hostname: ollama-webui
    restart: unless-stopped
    depends_on:
      - ollama
    ports:
      - 8585:8080
    volumes:
      - ${CONFIG_DIR}/ollama/webui:/app/backend/data
    environment:
      - OLLAMA_BASE_URLS=http://ollama:11434 #comma separated ollama hosts
      - ENV=dev
      - WEBUI_AUTH=False
      - WEBUI_NAME=valiantlynx AI
      - WEBUI_URL=https://ollama.jujub.eu
      - WEBUI_SECRET_KEY=0xwOd8iI1kZe4ehGxV5qbYOoxdkL
      - NO_PROXY=host.docker.internal
    extra_hosts:
      - host.docker.internal:host-gateway
    networks:
      - proxy
