version: "3.7"

networks:
  mother:
    external: true

volumes:
   db-01:
   db-02:
  
services:
  mongoprimary:
    image: registry.vnfco.ir/library/bitnami/mongodb:4.4.11-debian-10-r5
    volumes:
      - db-01:/bitnami/mongodb
    environment:
      - MONGODB_REPLICA_SET_MODE=primary
      - MONGODB_REPLICA_SET_NAME=igrep
      - MONGODB_ADVERTISED_HOSTNAME=mongoprimary
      - MONGODB_ROOT_PASSWORD=cWv1WQvWEp+LPdax9We/M6PeT7KgyTE9zKmC5y1ieqz4JtpLiVifJrQg0VHYhE6l
      - MONGODB_REPLICA_SET_KEY=keyissetforlocalreplica
    deploy:
      update_config:
        parallelism: 1
        delay: 10s
        order: start-first
      restart_policy:
        condition: any
        delay: 5s
        max_attempts: 3
        window: 120s 
      replicas: 1
      mode: replicated
    ports:
      - "27011:27017"
    networks:
      - mother
    healthcheck:
      test: ["CMD", "mongo", "--eval", "printjson(db.isMaster())" ]
      interval: 10s
      timeout: 5s
      retries: 3
      start_period: 5s
      

  mongosecondary:
    image: registry.vnfco.ir/library/bitnami/mongodb:4.4.11-debian-10-r5
    environment:
      - MONGODB_REPLICA_SET_MODE=secondary
      - MONGODB_REPLICA_SET_NAME=igrep
      - MONGODB_ADVERTISED_HOSTNAME=mongosecondary
      - MONGODB_INITIAL_PRIMARY_HOST=mongoprimary
      - MONGODB_INITIAL_PRIMARY_PORT_NUMBER=27017
      - MONGODB_INITIAL_PRIMARY_ROOT_PASSWORD=cWv1WQvWEp+LPdax9We/M6PeT7KgyTE9zKmC5y1ieqz4JtpLiVifJrQg0VHYhE6l
      - MONGODB_REPLICA_SET_KEY=keyissetforlocalreplica
    volumes:
      - db-02:/bitnami/mongodb
    deploy:
      update_config:
        parallelism: 1
        delay: 10s
        order: start-first
      restart_policy:
        condition: any
        delay: 5s
        max_attempts: 3
        window: 120s 
      mode: replicated
      replicas: 1
    ports:
      - "27012:27017"
    networks:
      - mother
    healthcheck:
      test: ["CMD", "mongo", "--eval", "printjson(db.isMaster())" ]
      interval: 10s
      timeout: 5s
      retries: 3
      start_period: 5s

      

  mongoarbiter:
    image: registry.vnfco.ir/library/bitnami/mongodb:4.4.11-debian-10-r5
    environment:
      - MONGODB_REPLICA_SET_MODE=arbiter
      - MONGODB_REPLICA_SET_NAME=igrep
      - MONGODB_ADVERTISED_HOSTNAME=mongoarbiter
      - MONGODB_INITIAL_PRIMARY_HOST=mongoprimary
      - MONGODB_INITIAL_PRIMARY_PORT_NUMBER=27017
      - MONGODB_INITIAL_PRIMARY_ROOT_PASSWORD=cWv1WQvWEp+LPdax9We/M6PeT7KgyTE9zKmC5y1ieqz4JtpLiVifJrQg0VHYhE6l
      - MONGODB_REPLICA_SET_KEY=keyissetforlocalreplica
    deploy:
      update_config:
        parallelism: 1
        delay: 10s
        order: start-first
      restart_policy:
        condition: any
        delay: 5s
        max_attempts: 3
        window: 120s 
      mode: replicated
      replicas: 1
    networks:
      - mother
    healthcheck:
      test: ["CMD", "mongo", "--eval", "printjson(db.isMaster())" ]
      interval: 10s
      timeout: 5s
      retries: 3
      start_period: 5s



