version: '3.7'

x-common-variables: &common-variables
    MAIN_CONN_STRING: >
        {
            "ConnectionName": "default",
            "ConnectionString": "Server=pyrus-postgresql;Port=5432;Username=pyrusadm;Password=pyruspwd;Database=pyrusdb;",
            "DatabaseEngine": "Postgres",
            "DatabaseType": "Data"
        }
    FILES_CONN_STRING: >
        {
            "ConnectionName": "files",
            "ConnectionString": "Server=pyrus-postgresql;Port=5432;Username=pyrusadm;Password=pyruspwd;Database=pyrusdb;",
            "DatabaseEngine": "Postgres",
            "DatabaseType": "Files"
        }
    PRIVATE_LOGS_CONN_STRING: >
        {
            "ConnectionName": "privateLogs",
            "ConnectionString": "Server=pyrus-logs-pgsql;Port=5432;Username=pyrusadm;Password=pyruspwd;Database=pyrus_logs;",
            "DatabaseEngine": "Postgres",
            "DatabaseType": "PrivateLogs"
        }
    PUBLIC_LOGS_CONN_STRING: >
        {
            "ConnectionName": "publicLogs",
            "ConnectionString": "Server=pyrus-logs-pgsql;Port=5432;Username=pyrusadm;Password=pyruspwd;Database=pyrus_logs;",
            "DatabaseEngine": "Postgres",
            "DatabaseType": "PublicLogs"
        }

services:
  postgres:
    image: cr.yandex/crpn0l4dp22f8mv5ln18/pyrus-pgsql-13:1.10.0
    restart: always
    container_name: pyrus-postgresql
    volumes:
      - pyrus_pgsql_data:/var/lib/postgresql/data
    networks:
      - pyrus-backend
    ports:
      - '5432:5432'

  logs:
    image: cr.yandex/crpn0l4dp22f8mv5ln18/pyrus-logs-pgsql:1.10.0
    restart: always
    container_name: pyrus-logs-pgsql
    volumes:
      - pyrus_logs_pgsql_data:/var/lib/postgresql/data
    networks:
      - pyrus-backend

  elastic:
    image: cr.yandex/crpn0l4dp22f8mv5ln18/elastic-selfhosted:7.17.10
    restart: always
    container_name: pyrus-elastic
    volumes:
      - pyrus_elastic_data:/usr/share/elasticsearch/data
    environment:
      <<: *common-variables
      ES_JAVA_OPTS: "-Xms2g -Xmx2g -Dlog4j.formatMsgNoLookups=true"
      APPLICATION_NAME: elastic
    networks:
      - pyrus-backend

  nginx:
    image: cr.yandex/crpn0l4dp22f8mv5ln18/pyrus-nginx:1.11.0
    restart: always
    container_name: pyrus-nginx
    depends_on:
      - web-api
      - files
    ports:
      - '80:80'
      - '443:443'
#    volumes:
#      - /path/to/cert:/etc/nginx/ssl/cert.crt
#      - /path/to/key:/etc/nginx/ssl/key.key
    networks:
      - pyrus-backend

  nats:
    image: cr.yandex/crpn0l4dp22f8mv5ln18/pyrus-nats
    restart: always
    container_name: pyrus-nats
    command: "-c /etc/nats/nats.conf"
    networks:
      - pyrus-backend

  preview:
    image: cr.yandex/crpn0l4dp22f8mv5ln18/pyrus-preview-generator:1.10.0
    depends_on:
      - postgres
      - elastic
      - nats
      - logs
    restart: always
    container_name: pyrus-preview-generator
    environment:
      <<: *common-variables
      APPLICATION_NAME: preview-generator
    networks:
      - pyrus-backend

  identity-server:
    image: cr.yandex/crpn0l4dp22f8mv5ln18/pyrus-identity-server:1.10.0
    container_name: pyrus-identity-server
    depends_on:
      - postgres
    restart: always
    environment:
      <<: *common-variables
      APPLICATION_NAME: identity-server
    networks:
      - pyrus-backend

  web-api:
    image: cr.yandex/crpn0l4dp22f8mv5ln18/pyrus-web-api:1.10.0
    depends_on:
      - postgres
      - elastic
      - nats
      - logs
      - identity-server
    restart: always
    container_name: pyrus-web-api
    environment:
      <<: *common-variables
      APPLICATION_NAME: web-api
    networks:
      - pyrus-backend

  files:
    image: cr.yandex/crpn0l4dp22f8mv5ln18/pyrus-file-service:1.10.0
    depends_on:
      - postgres
      - elastic
      - nats
      - logs
      - identity-server
    restart: always
    container_name: pyrus-file-service
    environment:
      <<: *common-variables
      APPLICATION_NAME: file-service
    networks:
      - pyrus-backend

  bind:
    image: cr.yandex/crpn0l4dp22f8mv5ln18/pyrus-bind-service:1.10.0
    restart: always
    container_name: pyrus-bind-service
    depends_on:
        - postgres
        - logs
        - nats
    environment:
      <<: *common-variables
      APPLICATION_NAME: bind-service
      HOST: bind
    networks:
      - pyrus-backend

  mail-reader:
    image: cr.yandex/crpn0l4dp22f8mv5ln18/pyrus-mail-reader:1.10.0
    depends_on:
      - postgres
      - elastic
      - nats
      - logs
    restart: always
    container_name: pyrus-mail-reader
    environment:
      <<: *common-variables
      APPLICATION_NAME: mail-reader
      MAILREADER_ENVIRONMENT: Production
    networks:
      - pyrus-backend
    volumes:
      - /etc/ssl/certs:/etc/ssl/certs

  mail-sender:
    image: cr.yandex/crpn0l4dp22f8mv5ln18/pyrus-mail-sender:1.10.0
    depends_on:
      - postgres
      - elastic
      - nats
      - logs
    restart: always
    container_name: pyrus-mail-sender
    environment:
      <<: *common-variables
      APPLICATION_NAME: mail-sender
    networks:
      - pyrus-backend

  async-worker:
    image: cr.yandex/crpn0l4dp22f8mv5ln18/pyrus-async-worker:1.10.0
    depends_on:
      - postgres
      - elastic
      - nats
      - logs
    restart: always
    container_name: pyrus-async-worker
    environment:
      <<: *common-variables
      APPLICATION_NAME: async-worker
    networks:
      - pyrus-backend

  notification-service:
    image: cr.yandex/crpn0l4dp22f8mv5ln18/pyrus-notification-service:1.10.0
    container_name: pyrus-notification-service
    depends_on:
      - postgres
    restart: always
    environment:
      <<: *common-variables
      APPLICATION_NAME: notification-service
    networks:
      - pyrus-backend

  pyrus-schedule-to-today:
    image: cr.yandex/crpn0l4dp22f8mv5ln18/pyrus-schedule-to-today:1.10.0
    depends_on:
      - postgres
      - elastic
      - logs
    entrypoint: ["./wait-for-it.sh", "-s", "-t", "20", "pyrus-elastic:9200", "--", "dotnet", "Pyrus.ScheduleToToday.Core.dll"]
    restart: always
    container_name: pyrus-schedule-to-today
    environment:
      <<: *common-variables
      APPLICATION_NAME: schedule-to-today
    networks:
      - pyrus-backend

  minio:
    image: cr.yandex/crpn0l4dp22f8mv5ln18/minio:latest
    restart: always
    container_name: pyrus-minio
    command: server --console-address ":9001" /data/
    ports:
      - "9000:9000"
      - "9001:9001"
    environment:
      MINIO_ROOT_USER: admin
      MINIO_ROOT_PASSWORD: admin123
    volumes:
      - pyrus_minio_data:/data
    networks:
      - pyrus-backend

  pyrus-setup:
    image: cr.yandex/crpn0l4dp22f8mv5ln18/pyrus-setup:1.10.0
    profiles: ["all"]
    pull_policy: always
    depends_on:
      - postgres
    container_name: pyrus-setup
    environment:
      <<: *common-variables
      APPLICATION_NAME: pyrus-setup
    networks:
      - pyrus-backend

  elastic-console:
    image: cr.yandex/crpn0l4dp22f8mv5ln18/pyrus-elastic-console:1.10.0
    profiles: ["all"]
    pull_policy: always
    depends_on:
      - postgres
      - elastic
    container_name: pyrus-elastic-console
    environment:
      <<: *common-variables
      APPLICATION_NAME: pyrus-elastic-console
    networks:
      - pyrus-backend

volumes:
  pyrus_pgsql_data:
  pyrus_elastic_data:
  pyrus_logs_pgsql_data:
  pyrus_minio_data:

networks:
  pyrus-backend:
    name: pyrus-backend
    driver: bridge
