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-dev:/data/db
    ports:
      - 127.0.0.1:27017:27017
    restart: always
    environment:
      - MONGO_DB:pwndoc
    networks:
      - backend-internal

  pwndoc-backend:
    build:
      context: ./backend/
      dockerfile: Dockerfile.dev
    environment:
      - DB_SERVER=mongo-pwndoc
      - DB_NAME=pwndoc
    volumes:
      - ./backend/src:/app/src
      - ./backend/ssl:/app/ssl
      - ./backend/report-templates:/app/report-templates
      - ./backend/backup:/app/backup
    depends_on:
      - mongodb
    restart: always
    ports:
      - 4242:4242
    networks:
      - backend-internal
      - nginx-backend

  pwndoc-frontend:
    build:
      context: ./frontend
      dockerfile: Dockerfile.dev
    volumes:
      - ./frontend/src:/app/src
      - ./frontend/ssl:/app/ssl
      - ./frontend/public:/app/public
      - ./frontend/index.html:/app/index.html
      - ./frontend/jsconfig.json:/app/jsconfig.json
      - ./frontend/postcss.config.js:/app/postcss.config.js
      - ./frontend/babel.config.js:/app/babel.config.js
      - ./frontend/quasar.config.js:/app/quasar.config.js
      - ./frontend/package.json:/app/package.json
      - ./frontend/package-lock.json:/app/package-lock.json
    restart: always
    ports:
      - 8081:8081
    depends_on:
      - pwndoc-backend
    networks:
      - nginx-backend

  pwndoc-languagetools:
    build:
      context: ./languagetool/
      dockerfile: Dockerfile
    restart: always
    ports:
      - 8010:8010
      - 8020:8020
    environment:
      - BACKEND_URL=https://pwndoc-backend:4242
    depends_on:
      - pwndoc-backend
    volumes:
      - ./languagetool/custom-rules:/LanguageTool/custom-rules
    networks:
      - backend-internal

  pwndoc-frontend-nginx:
    image: nginx:stable-alpine
    user: root
    volumes:
      - ./frontend/.docker/nginx/nginx.dev.conf:/etc/nginx/conf.d/default.conf
      - ./frontend/ssl:/etc/nginx/ssl/
      - ./frontend/.docker/nginx/snippets:/etc/nginx/snippets
    restart: always
    ports:
      - 8443:8443
    depends_on:
      - pwndoc-frontend
    networks:
      - nginx-backend

volumes:
  mongo-data-dev:

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