version: '3'
services:
  
  chatplus:
    image: foxsystem/metafox-chatplus:latest
    command: >
      bash -c
        "for i in `seq 1 30`; do
          node main.js &&
          s=$$? && break || s=$$?;
          echo \"Tried $$i times. Waiting 5 secs...\";
          sleep 5;
        done; (exit $$s)"
    restart: unless-stopped
    volumes:
      - ./uploads:/app/uploads
    env_file:
      - ./chatplus.env
    environment:
      - MONGO_OPLOG_URL=mongodb://chatplusdb:27017/local
    depends_on:
      - chatplusdb
    ports:
      - 3000:3000
    networks:
      - "mf-chatplus-tier"

  chatplusdb:
    image: mongo:4.4
    restart: unless-stopped
    volumes:
      - ./data:/data/db
    command: mongod --oplogSize 128 --replSet rs0 --storageEngine=wiredTiger
    networks:
      - "mf-chatplus-tier"

  # this container's job is just run the command to initialize the replica set.
  # it will run the command and remove himself (it will not stay running)
  chatplusdb-init-replica:
    image: mongo:4.4
    command: >
      bash -c
        "for i in `seq 1 30`; do
          mongo chatplusdb/rocketchat --eval \"
            rs.initiate({
              _id: 'rs0',
              members: [ { _id: 0, host: 'localhost:27017' } ]})\" &&
          s=$$? && break || s=$$?;
          echo \"Tried $$i times. Waiting 5 secs...\";
          sleep 5;
        done; (exit $$s)"
    depends_on:
      - chatplusdb
    networks:
      - "mf-chatplus-tier"
networks:
  mf-chatplus-tier:
    driver: bridge
