version: "3.8"

services:
  rocketchat:
    image: registry.rocket.chat/rocketchat/rocket.chat:8.2.1
    container_name: rocketchat
    restart: unless-stopped
    environment:
      MONGO_URL: mongodb://rocketchat-mongo:27017/rocketchat?replicaSet=rs0
      MONGO_OPLOG_URL: mongodb://rocketchat-mongo:27017/local?replicaSet=rs0
      ROOT_URL: https://chat.njts.co.jp
      PORT: 3000
    depends_on:
      - mongo
    networks:
      - chat

  mongo:
    image: mongo:8.0.13
    container_name: rocketchat-mongo
    restart: unless-stopped
    command: mongod --replSet rs0 --oplogSize 128
    volumes:
      - mongo-data:/data/db
    networks:
      - chat

  mongo-init:
    image: mongo:8.0.13
    restart: "no"
    depends_on:
      - mongo
    command: >
      mongosh --host mongo:27017 --eval
      "rs.initiate({_id:'rs0',members:[{_id:0,host:'mongo:27017'}]})"
    networks:
      - chat

  caddy:
    image: caddy:2
    container_name: caddy
    restart: unless-stopped
    ports:
      - "2015:2015"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile:ro
      - /etc/caddy/certs:/certs:ro
      - caddy_data:/data
      - caddy_config:/config
    networks:
      - chat
      - shared_net

volumes:
  mongo-data:
  caddy_data:
  caddy_config:

networks:
  chat:
  shared_net:
    external: true