services:
  rocketchat:
    volumes:
      - ${COVERAGE_DIR:-/tmp/coverage}:${COVERAGE_DIR:-/tmp/coverage}
    build:
      dockerfile: ${GITHUB_WORKSPACE:-}/apps/meteor/.docker/Dockerfile.alpine
      context: /tmp/build
      x-bake:
        platforms:
          - linux/amd64
          - linux/arm64
      args:
        DENO_VERSION: ${DENO_VERSION:-}
    image: ghcr.io/${LOWERCASE_REPOSITORY}/rocket.chat:${DOCKER_TAG}${DOCKER_TAG_SUFFIX_ROCKETCHAT:-}
    environment:
      - TEST_MODE=true
      - DEBUG=${DEBUG:-}
      - EXIT_UNHANDLEDPROMISEREJECTION=true
      - MONGO_URL=mongodb://mongo:27017/rocketchat?replicaSet=rs0
      - 'MONGO_OPLOG_URL=${MONGO_OPLOG_URL:-}'
      - 'TRANSPORTER=${TRANSPORTER:-}'
      - MOLECULER_LOG_LEVEL=info
      - 'ROCKETCHAT_LICENSE=${ENTERPRISE_LICENSE:-}'
      - 'COVERAGE_DIR=${COVERAGE_DIR:-}'
      - 'COVERAGE_REPORTER=${COVERAGE_REPORTER:-}'
      - 'COVERAGE_FILE_NAME=${COVERAGE_FILE_NAME:-}'
      - OVERWRITE_SETTING_Log_Level=${DEBUG_LOG_LEVEL:-0}
      - Federation_Service_Enabled=true
      - 'Federation_Service_Domain=rc.host'
      - HEAP_USAGE_PERCENT=99
    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(`/`)
      traefik.http.middlewares.test-retry.retry.attempts: 4
    healthcheck:
      interval: 2s
      timeout: 5s
      retries: 5
      start_period: 60s
      test: wget --no-verbose --tries=1 --spider http://127.0.0.1:3000/livez || exit 1

  authorization-service:
    build:
      dockerfile: ee/apps/authorization-service/Dockerfile
      context: .
      x-bake:
        platforms:
          - linux/amd64
          - linux/arm64
      args:
        SERVICE: authorization-service
    image: ghcr.io/${LOWERCASE_REPOSITORY}/authorization-service:${DOCKER_TAG}
    environment:
      - MONGO_URL=mongodb://mongo:27017/rocketchat?replicaSet=rs0
      - 'TRANSPORTER=${TRANSPORTER:-}'
      - MOLECULER_LOG_LEVEL=info
    extra_hosts:
      - 'host.docker.internal:host-gateway'
    depends_on:
      - nats

  account-service:
    build:
      dockerfile: ee/apps/account-service/Dockerfile
      context: .
      x-bake:
        platforms:
          - linux/amd64
          - linux/arm64
      args:
        SERVICE: account-service
    image: ghcr.io/${LOWERCASE_REPOSITORY}/account-service:${DOCKER_TAG}
    environment:
      - MONGO_URL=mongodb://mongo:27017/rocketchat?replicaSet=rs0
      - 'TRANSPORTER=${TRANSPORTER:-}'
      - MOLECULER_LOG_LEVEL=info
    extra_hosts:
      - 'host.docker.internal:host-gateway'
    depends_on:
      - nats

  presence-service:
    build:
      dockerfile: ee/apps/presence-service/Dockerfile
      context: .
      x-bake:
        platforms:
          - linux/amd64
          - linux/arm64
      args:
        SERVICE: presence-service
    image: ghcr.io/${LOWERCASE_REPOSITORY}/presence-service:${DOCKER_TAG}
    environment:
      - MONGO_URL=mongodb://mongo:27017/rocketchat?replicaSet=rs0
      - 'TRANSPORTER=${TRANSPORTER:-}'
      - MOLECULER_LOG_LEVEL=info
    extra_hosts:
      - 'host.docker.internal:host-gateway'
    depends_on:
      - nats

  ddp-streamer-service:
    build:
      dockerfile: ee/apps/ddp-streamer/Dockerfile
      context: .
      x-bake:
        platforms:
          - linux/amd64
          - linux/arm64
      args:
        SERVICE: ddp-streamer
    image: ghcr.io/${LOWERCASE_REPOSITORY}/ddp-streamer-service:${DOCKER_TAG}
    environment:
      - MONGO_URL=mongodb://mongo:27017/rocketchat?replicaSet=rs0
      - '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:
    build:
      dockerfile: ee/apps/queue-worker/Dockerfile
      context: .
      x-bake:
        platforms:
          - linux/amd64
          - linux/arm64
      args:
        SERVICE: queue-worker
    image: ghcr.io/${LOWERCASE_REPOSITORY}/queue-worker-service:${DOCKER_TAG}
    environment:
      - MONGO_URL=mongodb://mongo:27017/rocketchat?replicaSet=rs0
      - 'TRANSPORTER=${TRANSPORTER:-}'
      - MOLECULER_LOG_LEVEL=info
    extra_hosts:
      - 'host.docker.internal:host-gateway'
    depends_on:
      - nats

  omnichannel-transcript-service:
    build:
      dockerfile: ee/apps/omnichannel-transcript/Dockerfile
      context: .
      x-bake:
        platforms:
          - linux/amd64
          - linux/arm64
      args:
        SERVICE: omnichannel-transcript
    image: ghcr.io/${LOWERCASE_REPOSITORY}/omnichannel-transcript-service:${DOCKER_TAG}
    environment:
      - TEST_MODE=true
      - MONGO_URL=mongodb://mongo:27017/rocketchat?replicaSet=rs0
      - 'TRANSPORTER=${TRANSPORTER:-}'
      - MOLECULER_LOG_LEVEL=info
    extra_hosts:
      - 'host.docker.internal:host-gateway'
    depends_on:
      - nats

  nats:
    image: nats:2.6-alpine

  mongo:
    image: mongodb/mongodb-community-server:${MONGODB_VERSION:-8.0}-ubi8
    container_name: mongo
    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"

  httpbin:
    image: kong/httpbin

  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

  openldap:
    image: bitnamilegacy/openldap:latest
    volumes:
      - ./development/ldap:/opt/bitnami/openldap/data/
    environment:
      - LDAP_ADMIN_USERNAME=admin
      - LDAP_ADMIN_PASSWORD=adminpassword
      - LDAP_ROOT=dc=space,dc=air
      - LDAP_ADMIN_DN=cn=admin,dc=space,dc=air
      - LDAP_CUSTOM_LDIF_DIR=/opt/bitnami/openldap/data
      - LDAP_LOGLEVEL=-1
      - BITNAMI_DEBUG=false
    ports:
      - 1389:1389
      - 1636:1636
