# Rocket.Chat + MongoDB – für Live-Betrieb (app.j-jn.com)
# Alle Werte in .env (siehe .env.example) – nur dort anpassen.
# Start: docker compose up -d

volumes:
  mongodb_data:
    driver: local

services:
  rocketchat:
    image: registry.rocket.chat/rocketchat/rocket.chat:latest
    restart: unless-stopped
    environment:
      MONGO_URL: mongodb://mongodb:27017/rocketchat?replicaSet=rs0
      ROOT_URL: ${ROOT_URL:-https://app.j-jn.com/server}
      PORT: 3000
      DEPLOY_METHOD: docker
    depends_on:
      mongodb:
        condition: service_healthy
    ports:
      - "${HOST_PORT:-3000}:3000"

  mongodb:
    image: mongodb/mongodb-community-server:8.2-ubi8
    restart: unless-stopped
    volumes:
      - mongodb_data:/data/db
    environment:
      MONGODB_REPLICA_SET_NAME: rs0
      MONGODB_PORT_NUMBER: 27017
      MONGODB_INITIAL_PRIMARY_HOST: mongodb
    healthcheck:
      test: ["CMD", "mongosh", "admin", "--eval", "db.adminCommand('ping').ok"]
      interval: 10s
      timeout: 10s
      retries: 10
      start_period: 60s
    entrypoint: |
      bash -c "
      mongod --replSet rs0 --bind_ip_all &
      sleep 5;
      until mongosh admin --eval \"db.adminCommand('ping')\" 2>/dev/null; do echo 'Waiting for Mongo...'; sleep 2; done;
      mongosh --eval \"rs.initiate({_id: 'rs0', members: [{ _id: 0, host: 'mongodb:27017' }]})\" || true;
      wait
      "
