# documentation: https://github.com/RocketChat/Rocket.Chat
# slogan: Self-hosted, secure and highly customizable open-source communication platform for organizations with sophisticated security and privacy concerns.
# category: messaging
# tags: rocketchat,chat,communication,privacy,mongodb,open,source
# logo: svgs/rocketchat.svg
# port: 3000

services:
  rocketchat:
    image: 'registry.rocket.chat/rocketchat/rocket.chat:8.0.1'
    environment:
      - SERVICE_URL_ROCKETCHAT_3000
      - 'MONGO_URL=mongodb://${MONGODB_ADVERTISED_HOSTNAME:-mongodb}:${MONGODB_INITIAL_PRIMARY_PORT_NUMBER:-27017}/${MONGODB_DATABASE:-rocketchat}?replicaSet=${MONGODB_REPLICA_SET_NAME:-rs0}'
      - 'MONGO_OPLOG_URL=mongodb://${MONGODB_ADVERTISED_HOSTNAME:-mongodb}:${MONGODB_INITIAL_PRIMARY_PORT_NUMBER:-27017}/local?replicaSet=${MONGODB_REPLICA_SET_NAME:-rs0}'
      - ROOT_URL=$SERVICE_URL_ROCKETCHAT
      - DEPLOY_METHOD=docker
      - REG_TOKEN=$REG_TOKEN
      - 'MAIL_URL=${MAIL_URL:-test@example.com}'
    depends_on:
      mongodb:
        condition: service_healthy
    healthcheck:
      test:
        - CMD
        - node
        - '--eval'
        - "const http = require('http'); const options = { host: '0.0.0.0', port: 3000, timeout: 2000, path: '/health' }; const healthCheck = http.request(options, (res) => { console.log('HEALTHCHECK STATUS:', res.statusCode); if (res.statusCode == 200) { process.exit(0); } else { process.exit(1); } }); healthCheck.on('error', function (err) { console.error('ERROR'); process.exit(1); }); healthCheck.end();"
      interval: 2s
      timeout: 10s
      retries: 15
  mongodb:
    image: 'mongo:7'
    volumes:
      - 'mongodb_data:/data/db'
    command: "sh -c \"\n  mongod --replSet ${MONGODB_REPLICA_SET_NAME:-rs0} --bind_ip_all &\n  sleep 5 &&\n  mongosh --eval 'rs.initiate({_id:\\\"${MONGODB_REPLICA_SET_NAME:-rs0}\\\", members:[{_id:0, host:\\\"mongodb:27017\\\"}]})' ||\n  true &&\n  wait\n\"\n"
    healthcheck:
      test:
        - CMD
        - mongosh
        - '--quiet'
        - '--eval'
        - "db.adminCommand('ping')"
      interval: 2s
      timeout: 10s
      retries: 15
