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

# This docker-compose file contains optional InfluxDB and InfluxDB-writer services
# for the Mainflux platform. Since this services are optional, this file is dependent on the
# docker-compose.yml file from <project_root>/docker/. In order to run these services,
# core services, as well as the network from the core composition, should be already running.

version: "3.7"

networks:
  mainflux-base-net:

volumes:
  mainflux-smtp-notifier-volume:

services:
  smtp-notifier-db:
    image: postgres:10.2-alpine
    container_name: mainflux-smtp-notifier-db
    restart: on-failure
    environment:
      POSTGRES_USER: ${MF_SMTP_NOTIFIER_DB_USER}
      POSTGRES_PASSWORD: ${MF_SMTP_NOTIFIER_DB_PASS}
      POSTGRES_DB: ${MF_SMTP_NOTIFIER_DB_NAME}
    networks:
      - mainflux-base-net
    volumes:
      - mainflux-smtp-notifier-volume:/var/lib/postgresql/datab

  smtp-notifier:
    image: mainflux/smtp-notifier:latest
    container_name: mainflux-smtp-notifier
    depends_on:
      - smtp-notifier-db
    restart: on-failure
    environment:
      MF_SMTP_NOTIFIER_LOG_LEVEL: ${MF_SMTP_NOTIFIER_LOG_LEVEL}
      MF_SMTP_NOTIFIER_FROM_ADDR: ${MF_SMTP_NOTIFIER_FROM_ADDR}]
      MF_SMTP_NOTIFIER_CONFIG_PATH: ${MF_SMTP_NOTIFIER_CONFIG_PATH}
      MF_SMTP_NOTIFIER_HTTP_HOST: ${MF_SMTP_NOTIFIER_HTTP_HOST}
      MF_SMTP_NOTIFIER_HTTP_PORT: ${MF_SMTP_NOTIFIER_HTTP_PORT}
      MF_SMTP_NOTIFIER_HTTP_SERVER_CERT: ${MF_SMTP_NOTIFIER_HTTP_SERVER_CERT}
      MF_SMTP_NOTIFIER_HTTP_SERVER_KEY: ${MF_SMTP_NOTIFIER_HTTP_SERVER_KEY}
      MF_SMTP_NOTIFIER_DB_HOST: ${MF_SMTP_NOTIFIER_DB_HOST}
      MF_SMTP_NOTIFIER_DB_PORT: ${MF_SMTP_NOTIFIER_DB_PORT}
      MF_SMTP_NOTIFIER_DB_USER: ${MF_SMTP_NOTIFIER_DB_USER}
      MF_SMTP_NOTIFIER_DB_PASS: ${MF_SMTP_NOTIFIER_DB_PASS}
      MF_SMTP_NOTIFIER_DB_NAME: ${MF_SMTP_NOTIFIER_DB_NAME}
      MF_SMTP_NOTIFIER_DB_SSL_MODE: ${MF_SMTP_NOTIFIER_DB_SSL_MODE}
      MF_SMTP_NOTIFIER_DB_SSL_CERT: ${MF_SMTP_NOTIFIER_DB_SSL_CERT}
      MF_SMTP_NOTIFIER_DB_SSL_KEY: ${MF_SMTP_NOTIFIER_DB_SSL_KEY}
      MF_SMTP_NOTIFIER_DB_SSL_ROOT_CERT: ${MF_SMTP_NOTIFIER_DB_SSL_ROOT_CERT}
      MF_AUTH_GRPC_URL: ${MF_AUTH_GRPC_URL}
      MF_AUTH_GRPC_TIMEOUT: ${MF_AUTH_GRPC_TIMEOUT}
      MF_AUTH_GRPC_CLIENT_CERT: ${MF_AUTH_GRPC_CLIENT_CERT:+/users-grpc-client.crt}
      MF_AUTH_GRPC_CLIENT_KEY: ${MF_AUTH_GRPC_CLIENT_KEY:+/users-grpc-client.key}
      MF_AUTH_GRPC_SERVER_CA_CERTS: ${MF_AUTH_GRPC_SERVER_CA_CERTS:+/users-grpc-server-ca.crt}
      MF_EMAIL_USERNAME: ${MF_EMAIL_USERNAME}
      MF_EMAIL_PASSWORD: ${MF_EMAIL_PASSWORD}
      MF_EMAIL_HOST: ${MF_EMAIL_HOST}
      MF_EMAIL_PORT: ${MF_EMAIL_PORT}
      MF_EMAIL_FROM_ADDRESS: ${MF_EMAIL_FROM_ADDRESS}
      MF_EMAIL_FROM_NAME: ${MF_EMAIL_FROM_NAME}
      MF_EMAIL_TEMPLATE: ${MF_SMTP_NOTIFIER_EMAIL_TEMPLATE}
      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_SMTP_NOTIFIER_INSTANCE_ID: ${MF_SMTP_NOTIFIER_INSTANCE_ID}
    ports:
      - ${MF_SMTP_NOTIFIER_HTTP_PORT}:${MF_SMTP_NOTIFIER_HTTP_PORT}
    networks:
      - mainflux-base-net
    volumes:
      - ./config.toml:/config.toml
      - ../../templates/${MF_SMTP_NOTIFIER_EMAIL_TEMPLATE}:/${MF_SMTP_NOTIFIER_EMAIL_TEMPLATE}
      - type: bind
        source: ${MF_ADDONS_CERTS_PATH_PREFIX}${MF_USERS_GRPC_CLIENT_CERT:-./ssl/certs/dummy/client_cert}
        target: /users-grpc-client${MF_USERS_GRPC_CLIENT_CERT:+.crt}
        bind:
          create_host_path: true
      - type: bind
        source: ${MF_ADDONS_CERTS_PATH_PREFIX}${MF_USERS_GRPC_CLIENT_KEY:-./ssl/certs/dummy/client_key}
        target: /users-grpc-client${MF_USERS_GRPC_CLIENT_KEY:+.key}
        bind:
          create_host_path: true
      - type: bind
        source: ${MF_ADDONS_CERTS_PATH_PREFIX}${MF_USERS_GRPC_SERVER_CA_CERTS:-./ssl/certs/dummy/server_ca}
        target: /users-grpc-server-ca${MF_USERS_GRPC_SERVER_CA_CERTS:+.crt}
        bind:
          create_host_path: true
