x-defaults: &defaults
  restart: unless-stopped
  logging:
    driver: json-file
    options:
      max-size: 100m
      max-file: '3'

services:
  mongo:
    <<: *defaults
    image: ${GLOBAL_REGISTRY:-}mongo:${MONGO_VERSION:-8.3.3}
    environment:
      TZ: ${TZ:-UTC}
      MONGO_INITDB_ROOT_USERNAME: ${MONGO_INITDB_ROOT_USERNAME:-root}
      MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD:-password}
      MONGO_INITDB_DATABASE: ${MONGO_INITDB_DATABASE:-admin}
    ports:
      - '${MONGO_PORT_OVERRIDE:-27017}:27017'
    volumes:
      - mongo_data:/data/db
      - mongo_configdb:/data/configdb
    healthcheck:
      test: [CMD, mongosh, --eval, "db.adminCommand('ping')"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 30s
    deploy:
      resources:
        limits:
          cpus: ${MONGO_CPU_LIMIT:-1.0}
          memory: ${MONGO_MEMORY_LIMIT:-2048M}
        reservations:
          cpus: ${MONGO_CPU_RESERVATION:-0.1}
          memory: ${MONGO_MEMORY_RESERVATION:-1024M}

volumes:
  mongo_data:
  mongo_configdb:
