version: "3.9"

services:
  mongo:
    image: mongo:7.0
    container_name: ludo-mongo
    restart: unless-stopped
    networks:
      - ludo-net
    volumes:
      - ludo-mongo-data:/data/db
      - ./mongo-keyfile:/etc/mongo-keyfile:ro
      # - ./mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro
    command:
      - bash
      - -c
      - |
        cp /etc/mongo-keyfile /data/db/keyfile &&
        chown mongodb:mongodb /data/db/keyfile &&
        chmod 400 /data/db/keyfile &&
        exec mongod --replSet rs0 --keyFile /data/db/keyfile --bind_ip_all
    ports:
      - "27017:27017"

  app:
    build: .
    container_name: mern-ludo-app
    restart: unless-stopped
    networks:
      - ludo-net
    env_file:
      - .env
    ports:
      - "18081:${PORT}"   # Host:Container mapping
    depends_on:
      - mongo

networks:
  ludo-net:

volumes:
  ludo-mongo-data: