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

# This docker-compose file contains optional Postgres and Postgres-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/postgres-writer/docker-compose.yml up
# from project root. PostgreSQL default port (5432) is exposed, so you can use various tools for database
# inspection and data visualization.

version: "3.7"

networks:
  docker_mainflux-base-net:
    external: true

volumes:
  mainflux-postgres-writer-volume:

services:
  postgres:
    image: postgres:10.2-alpine
    container_name: mainflux-postgres
    restart: on-failure
    environment:
      POSTGRES_USER: ${MF_POSTGRES_WRITER_DB_USER}
      POSTGRES_PASSWORD: ${MF_POSTGRES_WRITER_DB_PASS}
      POSTGRES_DB: ${MF_POSTGRES_WRITER_DB}
    networks:
      - docker_mainflux-base-net
    volumes:
      - mainflux-postgres-writer-volume:/var/lib/postgresql/data

  postgres-writer:
    image: mainflux/postgres-writer:latest
    container_name: mainflux-postgres-writer
    depends_on:
      - postgres
    restart: on-failure
    environment:
      MF_NATS_URL: ${MF_NATS_URL}
      MF_POSTGRES_WRITER_LOG_LEVEL: ${MF_POSTGRES_WRITER_LOG_LEVEL}
      MF_POSTGRES_WRITER_PORT: ${MF_POSTGRES_WRITER_PORT}
      MF_POSTGRES_WRITER_DB_HOST: postgres
      MF_POSTGRES_WRITER_DB_PORT: ${MF_POSTGRES_WRITER_DB_PORT}
      MF_POSTGRES_WRITER_DB_USER: ${MF_POSTGRES_WRITER_DB_USER}
      MF_POSTGRES_WRITER_DB_PASS: ${MF_POSTGRES_WRITER_DB_PASS}
      MF_POSTGRES_WRITER_DB: ${MF_POSTGRES_WRITER_DB}
      MF_POSTGRES_WRITER_DB_SSL_MODE: ${MF_POSTGRES_WRITER_DB_SSL_MODE}
      MF_POSTGRES_WRITER_DB_SSL_CERT: ${MF_POSTGRES_WRITER_DB_SSL_CERT}
      MF_POSTGRES_WRITER_DB_SSL_KEY: ${MF_POSTGRES_WRITER_DB_SSL_KEY}
      MF_POSTGRES_WRITER_DB_SSL_ROOT_CERT: ${MF_POSTGRES_WRITER_DB_SSL_ROOT_CERT}
    ports:
      - ${MF_POSTGRES_WRITER_PORT}:${MF_POSTGRES_WRITER_PORT}
    networks:
      - docker_mainflux-base-net
    volumes:
      - ./subjects.toml:/config/subjects.toml
