version: '3'
services:

  mongodb:
    image: mongo:4.2.15
    container_name: mongo-pwndoc
    command: --wiredTigerCacheSizeGB 1 # 50% of (max RAM - 1GB) - minimum 0.25 (Modify it depending on defined RAM limits)
    deploy:
      resources:
        limits:
          memory: 3G # Maximum memory to allocate (Modify it depending on host ressources - leave at least 1GB free for host)
        reservations:
          memory: 1G # Minimum memory required
    volumes:
      - ./backend/mongo-data:/data/db
    restart: always
    environment:
      - MONGO_DB:pwndoc
    networks:
      - backend-internal

  pwndoc-backend:
    image: ghcr.io/pwndoc/pwndoc-backend:latest
    container_name: pwndoc-backend
    environment:
      - DB_SERVER=mongo-pwndoc
      - DB_NAME=pwndoc
    volumes:
      - ./backend/report-templates:/app/report-templates
      - ./backend/src/config:/app/src/config
      - ./backend/src/lib/custom:/app/src/lib/custom
      - ./backend/backup:/app/backup
    depends_on:
      - mongodb
    restart: always
    networks:
      - backend-internal
      - nginx-backend

  pwndoc-languagetools:
    build:
      context: ./languagetool/
      dockerfile: Dockerfile
    container_name: pwndoc-languagetools
    restart: always
    environment:
      - BACKEND_URL=https://pwndoc-backend:4242
    depends_on:
      - pwndoc-backend
    networks:
      - backend-internal

  nginx:
    build:
      context: ./frontend
      dockerfile: Dockerfile
    container_name: pwndoc-nginx
    restart: always
    ports:
      - ${APP_PORT:-8443}:8443
    depends_on:
      - pwndoc-backend
    networks:
      - nginx-backend

volumes:
  mongo-data:

networks:
  backend-internal:
    driver: bridge
    internal: false
  nginx-backend:
    driver: bridge
