services:
  rocketchat:
    platform: linux/amd64
    image: ghcr.io/${LOWERCASE_REPOSITORY}/rocket.chat:${DOCKER_TAG}
    environment:
      - TEST_MODE=true
      - EXIT_UNHANDLEDPROMISEREJECTION=true
      - 'MONGO_URL=${MONGO_URL}'
      - 'MONGO_OPLOG_URL=${MONGO_OPLOG_URL}'
      - 'TRANSPORTER=${TRANSPORTER}'
      - MOLECULER_LOG_LEVEL=info
      - 'ROCKETCHAT_LICENSE=${ENTERPRISE_LICENSE}'
      - OVERWRITE_SETTING_Log_Level=2
    extra_hosts:
      - 'host.docker.internal:host-gateway'
    depends_on:
      - traefik
      - mongo
    labels:
      traefik.enable: true
      traefik.http.services.rocketchat.loadbalancer.server.port: 3000
      traefik.http.routers.rocketchat.service: rocketchat
      traefik.http.routers.rocketchat.rule: PathPrefix(`/`)

  authorization-service:
    platform: linux/amd64
    image: ghcr.io/${LOWERCASE_REPOSITORY}/authorization-service:${DOCKER_TAG}
    environment:
      - 'MONGO_URL=${MONGO_URL}'
      - 'TRANSPORTER=${TRANSPORTER}'
      - MOLECULER_LOG_LEVEL=info
    extra_hosts:
      - 'host.docker.internal:host-gateway'
    depends_on:
      - nats

  account-service:
    platform: linux/amd64
    image: ghcr.io/${LOWERCASE_REPOSITORY}/account-service:${DOCKER_TAG}
    environment:
      - MONGO_URL=${MONGO_URL}
      - 'TRANSPORTER=${TRANSPORTER}'
      - MOLECULER_LOG_LEVEL=info
    extra_hosts:
      - 'host.docker.internal:host-gateway'
    depends_on:
      - nats

  presence-service:
    platform: linux/amd64
    image: ghcr.io/${LOWERCASE_REPOSITORY}/presence-service:${DOCKER_TAG}
    environment:
      - MONGO_URL=${MONGO_URL}
      - 'TRANSPORTER=${TRANSPORTER}'
      - MOLECULER_LOG_LEVEL=info
    extra_hosts:
      - 'host.docker.internal:host-gateway'
    depends_on:
      - nats

  ddp-streamer-service:
    platform: linux/amd64
    image: ghcr.io/${LOWERCASE_REPOSITORY}/ddp-streamer-service:${DOCKER_TAG}
    environment:
      - MONGO_URL=${MONGO_URL}
      - 'TRANSPORTER=${TRANSPORTER}'
      - MOLECULER_LOG_LEVEL=info
    extra_hosts:
      - 'host.docker.internal:host-gateway'
    depends_on:
      - nats
      - traefik
    labels:
      traefik.enable: true
      traefik.http.services.ddp-streamer-service.loadbalancer.server.port: 3000
      traefik.http.routers.ddp-streamer-service.service: ddp-streamer-service
      traefik.http.routers.ddp-streamer-service.rule: PathPrefix(`/websocket`) || PathPrefix(`/sockjs`)

  queue-worker-service:
    platform: linux/amd64
    image: ghcr.io/${LOWERCASE_REPOSITORY}/queue-worker-service:${DOCKER_TAG}
    environment:
      - MONGO_URL=${MONGO_URL}
      - 'TRANSPORTER=${TRANSPORTER}'
      - MOLECULER_LOG_LEVEL=info
    extra_hosts:
      - 'host.docker.internal:host-gateway'
    depends_on:
      - nats

  omnichannel-transcript-service:
    platform: linux/amd64
    image: ghcr.io/${LOWERCASE_REPOSITORY}/omnichannel-transcript-service:${DOCKER_TAG}
    environment:
      - MONGO_URL=${MONGO_URL}
      - 'TRANSPORTER=${TRANSPORTER}'
      - MOLECULER_LOG_LEVEL=info
    extra_hosts:
      - 'host.docker.internal:host-gateway'
    depends_on:
      - nats

  mongo:
    image: mongodb/mongodb-community-server:${MONGODB_VERSION:-8.0}-ubi8
    restart: on-failure
    ports:
      - 27017:27017
    environment:
      MONGODB_REPLICA_SET_NAME: ${MONGODB_REPLICA_SET_NAME:-rs0}
      MONGODB_PORT_NUMBER: ${MONGODB_PORT_NUMBER:-27017}
      MONGODB_INITIAL_PRIMARY_HOST: ${MONGODB_INITIAL_PRIMARY_HOST:-mongo}
    entrypoint: |
      bash -c
        "mongod --replSet $$MONGODB_REPLICA_SET_NAME --bind_ip_all &
          sleep 2;
          until mongosh --eval \"db.adminCommand('ping')\"; do
            echo '=====> Waiting for Mongo...';
            sleep 1;
          done;
          echo \"=====> Initiating ReplSet $$MONGODB_REPLICA_SET_NAME at $$MONGODB_INITIAL_PRIMARY_HOST:$$MONGODB_PORT_NUMBER...\";
          mongosh --eval \"rs.initiate({_id: '$$MONGODB_REPLICA_SET_NAME', members: [{ _id: 0, host: '$$MONGODB_INITIAL_PRIMARY_HOST:$$MONGODB_PORT_NUMBER' }]})\";
          echo '=====> Initiating ReplSet done...';
        wait"

  nats:
    image: nats:2.6-alpine

  traefik:
    image: traefik:v3.6.6
    command:
      - --providers.docker=true
      - '--serverstransport.maxidleconnsperhost=-1'
    ports:
      - 3000:80
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
