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

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

networks:
  supermq-base-net:
    name: supermq-base-net
    external: true

volumes:
  supermq-journal-volume:


services:
  journal-db:
    image: postgres:16.2-alpine
    container_name: supermq-journal-db
    restart: on-failure
    command: postgres -c "max_connections=${SMQ_POSTGRES_MAX_CONNECTIONS}"
    environment:
      POSTGRES_USER: ${SMQ_JOURNAL_DB_USER}
      POSTGRES_PASSWORD: ${SMQ_JOURNAL_DB_PASS}
      POSTGRES_DB: ${SMQ_JOURNAL_DB_NAME}
      SMQ_POSTGRES_MAX_CONNECTIONS: ${SMQ_POSTGRES_MAX_CONNECTIONS}
    networks:
      - supermq-base-net
    volumes:
      - supermq-journal-volume:/var/lib/postgresql/data

  journal:
    image: supermq/journal:${SMQ_RELEASE_TAG}
    container_name: supermq-journal
    depends_on:
      - journal-db
    restart: on-failure
    environment:
      SMQ_JOURNAL_LOG_LEVEL: ${SMQ_JOURNAL_LOG_LEVEL}
      SMQ_JOURNAL_HTTP_HOST: ${SMQ_JOURNAL_HTTP_HOST}
      SMQ_JOURNAL_HTTP_PORT: ${SMQ_JOURNAL_HTTP_PORT}
      SMQ_JOURNAL_HTTP_SERVER_CERT: ${SMQ_JOURNAL_HTTP_SERVER_CERT}
      SMQ_JOURNAL_HTTP_SERVER_KEY: ${SMQ_JOURNAL_HTTP_SERVER_KEY}
      SMQ_JOURNAL_DB_HOST: ${SMQ_JOURNAL_DB_HOST}
      SMQ_JOURNAL_DB_PORT: ${SMQ_JOURNAL_DB_PORT}
      SMQ_JOURNAL_DB_USER: ${SMQ_JOURNAL_DB_USER}
      SMQ_JOURNAL_DB_PASS: ${SMQ_JOURNAL_DB_PASS}
      SMQ_JOURNAL_DB_NAME: ${SMQ_JOURNAL_DB_NAME}
      SMQ_JOURNAL_DB_SSL_MODE: ${SMQ_JOURNAL_DB_SSL_MODE}
      SMQ_JOURNAL_DB_SSL_CERT: ${SMQ_JOURNAL_DB_SSL_CERT}
      SMQ_JOURNAL_DB_SSL_KEY: ${SMQ_JOURNAL_DB_SSL_KEY}
      SMQ_JOURNAL_DB_SSL_ROOT_CERT: ${SMQ_JOURNAL_DB_SSL_ROOT_CERT}
      SMQ_AUTH_GRPC_URL: ${SMQ_AUTH_GRPC_URL}
      SMQ_AUTH_GRPC_TIMEOUT: ${SMQ_AUTH_GRPC_TIMEOUT}
      SMQ_AUTH_GRPC_CLIENT_CERT: ${SMQ_AUTH_GRPC_CLIENT_CERT:+/auth-grpc-client.crt}
      SMQ_AUTH_GRPC_CLIENT_KEY: ${SMQ_AUTH_GRPC_CLIENT_KEY:+/auth-grpc-client.key}
      SMQ_AUTH_GRPC_SERVER_CA_CERTS: ${SMQ_AUTH_GRPC_SERVER_CA_CERTS:+/auth-grpc-server-ca.crt}
      SMQ_AUTH_KEYS_ALGORITHM: ${SMQ_AUTH_KEYS_ALGORITHM}
      SMQ_ES_URL: ${SMQ_ES_URL}
      SMQ_JAEGER_URL: ${SMQ_JAEGER_URL}
      SMQ_JAEGER_TRACE_RATIO: ${SMQ_JAEGER_TRACE_RATIO}
      SMQ_SEND_TELEMETRY: ${SMQ_SEND_TELEMETRY}
      SMQ_JOURNAL_INSTANCE_ID: ${SMQ_JOURNAL_INSTANCE_ID}
      SMQ_DOMAINS_GRPC_URL: ${SMQ_DOMAINS_GRPC_URL}
      SMQ_DOMAINS_GRPC_TIMEOUT: ${SMQ_DOMAINS_GRPC_TIMEOUT}
      SMQ_DOMAINS_GRPC_CLIENT_CERT: ${SMQ_DOMAINS_GRPC_CLIENT_CERT:+/domains-grpc-client.crt}
      SMQ_DOMAINS_GRPC_CLIENT_KEY: ${SMQ_DOMAINS_GRPC_CLIENT_KEY:+/domains-grpc-client.key}
      SMQ_DOMAINS_GRPC_SERVER_CA_CERTS: ${SMQ_DOMAINS_GRPC_SERVER_CA_CERTS:+/domains-grpc-server-ca.crt}
      SMQ_ALLOW_UNVERIFIED_USER: ${SMQ_ALLOW_UNVERIFIED_USER}
    ports:
      - ${SMQ_JOURNAL_HTTP_PORT}:${SMQ_JOURNAL_HTTP_PORT}
    networks:
      - supermq-base-net
