# Copyright (c) Mainflux
# SPDX-License-Identifier: Apache-2.0

# This docker-compose file contains optional MongoDB and MongoDB-writer services
# for Mainflux platform. Since these are optional, this file is dependent of docker-compose file
# from <project_root>/docker. In order to run these services, execute command:
# docker-compose -f docker/docker-compose.yml -f docker/addons/mongodb-writer/docker-compose.yml up
# from project root. MongoDB default port (27017) is exposed, so you can use various tools for database
# inspection and data visualization.

version: "3.7"

networks:
  mainflux-base-net:

volumes:
  mainflux-mongodb-db-volume:
  mainflux-mongodb-configdb-volume:

services:
  mongodb:
    image: mongo:4.4.6
    container_name: mainflux-mongodb
    restart: on-failure
    environment:
      MONGO_INITDB_DATABASE: ${MF_MONGO_NAME}
    ports:
      - ${MF_MONGO_PORT}:${MF_MONGO_PORT}
    networks:
      - mainflux-base-net
    volumes:
      - mainflux-mongodb-db-volume:/data/db
      - mainflux-mongodb-configdb-volume:/data/configdb

  mongodb-writer:
    image: mainflux/mongodb-writer:${MF_RELEASE_TAG}
    container_name: mainflux-mongodb-writer
    depends_on:
      - mongodb
    restart: on-failure
    environment:
      MF_MONGO_WRITER_LOG_LEVEL: ${MF_MONGO_WRITER_LOG_LEVEL}
      MF_MONGO_WRITER_CONFIG_PATH: ${MF_MONGO_WRITER_CONFIG_PATH}
      MF_MONGO_WRITER_HTTP_HOST: ${MF_MONGO_WRITER_HTTP_HOST}
      MF_MONGO_WRITER_HTTP_PORT: ${MF_MONGO_WRITER_HTTP_PORT}
      MF_MONGO_WRITER_HTTP_SERVER_CERT: ${MF_MONGO_WRITER_HTTP_SERVER_CERT}
      MF_MONGO_WRITER_HTTP_SERVER_KEY: ${MF_MONGO_WRITER_HTTP_SERVER_KEY}
      MF_MONGO_HOST: ${MF_MONGO_HOST}
      MF_MONGO_PORT: ${MF_MONGO_PORT}
      MF_MONGO_NAME: ${MF_MONGO_NAME}
      MF_MESSAGE_BROKER_URL: ${MF_MESSAGE_BROKER_URL}
      MF_JAEGER_URL: ${MF_JAEGER_URL}
      MF_JAEGER_TRACE_RATIO: ${MF_JAEGER_TRACE_RATIO}
      MF_SEND_TELEMETRY: ${MF_SEND_TELEMETRY}
      MF_MONGO_WRITER_INSTANCE_ID: ${MF_MONGO_WRITER_INSTANCE_ID}
    ports:
      - ${MF_MONGO_WRITER_HTTP_PORT}:${MF_MONGO_WRITER_HTTP_PORT}
    networks:
      - mainflux-base-net
    volumes:
      - ./config.toml:/config.toml
