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"
        }   
    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-init:
    restart: "no"
    image: simplygoodsoftware/pyrus-pgsql-16:1.25.0
    environment: 
      - DISABLE_SCHEMA_INIT=1
    container_name: pyrus-postgresql-init
    volumes:
      - pyrus_pgsql_data:/var/lib/postgresql/data-old
      - pyrus_pgsql_data_16:/var/lib/postgresql/data
      - pyrus_pgsql_logs:/var/log/postgresql

  postgres-migration:
    restart: "no"
    image: simplygoodsoftware/pyrus-pgsql-migrator:13-to-16
    container_name: pyrus-postgresql-migration
    depends_on:
      postgres-init: 
        condition: service_completed_successfully
    volumes:
      - pyrus_pgsql_data:/var/lib/postgresql/data
      - pyrus_pgsql_data_16:/var/lib/postgresql/data-new
      - pyrus_pgsql_logs:/var/log/postgresql

  postgres:
    image: simplygoodsoftware/pyrus-pgsql-16:1.25.0
    restart: always
    container_name: pyrus-postgresql
    hostname: pyrus-postgresql
    depends_on:
      postgres-migration: 
        condition: service_completed_successfully
    volumes:
      - pyrus_pgsql_data_16:/var/lib/postgresql/data
      - pyrus_pgsql_logs:/var/log/postgresql
    networks:
      - pyrus-backend

  logs-init:
    restart: "no"
    image: simplygoodsoftware/pyrus-logs-pgsql-16:1.25.0
    environment: 
      - DISABLE_SCHEMA_INIT=1
    container_name: logs-init
    volumes:
      - pyrus_logs_pgsql_data:/var/lib/postgresql/data-old
      - pyrus_logs_pgsql_data_16:/var/lib/postgresql/data
      - pyrus_logs_pgsql_logs:/var/log/postgresql

  logs-migration:
    restart: "no"
    image: simplygoodsoftware/pyrus-pgsql-migrator:13-to-16
    container_name: logs-migration
    depends_on:
      logs-init: 
        condition: service_completed_successfully
    volumes:
      - pyrus_logs_pgsql_data:/var/lib/postgresql/data
      - pyrus_logs_pgsql_data_16:/var/lib/postgresql/data-new
      - pyrus_logs_pgsql_logs:/var/log/postgresql

  logs:
    image: simplygoodsoftware/pyrus-logs-pgsql-16:1.25.0
    restart: always
    container_name: pyrus-logs-pgsql
    hostname: pyrus-logs-pgsql
    depends_on:
      logs-migration: 
        condition: service_completed_successfully
    volumes:
      - pyrus_logs_pgsql_data_16:/var/lib/postgresql/data
      - pyrus_logs_pgsql_logs:/var/log/postgresql
    networks:
      - pyrus-backend

  elastic:
    image: simplygoodsoftware/elastic-selfhosted:1.25.0
    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: simplygoodsoftware/pyrus-nginx:1.25.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: simplygoodsoftware/pyrus-nats:1.25.0
    restart: always
    container_name: pyrus-nats
    command: "-c /etc/nats/nats.conf"
    networks:
      - pyrus-backend
    volumes:
      - pyrus_nats_data:/data

  preview:
    image: simplygoodsoftware/pyrus-preview-generator:1.25.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: simplygoodsoftware/pyrus-identity-server:1.25.0
    container_name: pyrus-identity-server
    depends_on:
      - postgres
    restart: always
    environment:
      <<: *common-variables
      APPLICATION_NAME: identity-server
    networks:
      - pyrus-backend

  web-api:
    image: simplygoodsoftware/pyrus-web-api:1.25.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

  hocus:
    image: simplygoodsoftware/pyrus-hocus:1.25.0
    depends_on:
      - postgres
      - web-api
    restart: always
    container_name: pyrus-hocus
    environment:
      <<: *common-variables
      APPLICATION_NAME: hocus
    networks:
      - pyrus-backend

  files:
    image: simplygoodsoftware/pyrus-file-service:1.25.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: simplygoodsoftware/pyrus-bind-service:1.25.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: simplygoodsoftware/pyrus-mail-reader:1.25.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

  mail-sender:
    image: simplygoodsoftware/pyrus-mail-sender:1.25.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: simplygoodsoftware/pyrus-async-worker:1.25.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: simplygoodsoftware/pyrus-notification-service:1.25.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: simplygoodsoftware/pyrus-schedule-to-today:1.25.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

  familiar:
    image: simplygoodsoftware/pyrus-familiar-service:1.25.0
    restart: always
    container_name: pyrus-familiar-service
    depends_on:
        - postgres
        - logs
        - nats
    environment:
      <<: *common-variables
      APPLICATION_NAME: familiar-service
    networks:
      - pyrus-backend

  minio:
    image: minio/minio
    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: simplygoodsoftware/pyrus-setup:1.25.0
    profiles: ["all"]
    pull_policy: always
    depends_on:
      - postgres
    container_name: pyrus-setup
#    volumes:
#      - /path/to/cert/you_want_to_check:/tmp/cert.crt
    environment:
      <<: *common-variables
      APPLICATION_NAME: pyrus-setup
    networks:
      - pyrus-backend

  elastic-console:
    image: simplygoodsoftware/pyrus-elastic-console:1.25.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_pgsql_data_16:
  pyrus_elastic_data:
  pyrus_logs_pgsql_data:
  pyrus_logs_pgsql_data_16:
  pyrus_minio_data:
  pyrus_nats_data:
  pyrus_pgsql_logs:
  pyrus_logs_pgsql_logs:

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