version: '3.8'

services:
  mongo1:
    image: mongo:7.0
    command:
      [
        '--replSet',
        'rs0',
        '--bind_ip_all',
        '--port',
        '27017',
        '--keyFile',
        '/etc/mongo/mongodb-keyfile'
      ]
    ports:
      - 27017:27017
    # extra_hosts:
    #   - 'host.docker.internal:host-gateway'
    networks:
      - xpay
    environment:
      - MONGO_INITDB_ROOT_USERNAME=xpay
      - MONGO_INITDB_ROOT_PASSWORD=d26e449a031ea2a1d1197bbbd6905c24
    healthcheck:
      test: echo "try { rs.status() } catch (err) { rs.initiate({_id:'rs0',members:[{_id:0,host:'172.17.0.3:27017',priority:1}]}) }" | mongosh --port 27017 --quiet
      interval: 5s
      timeout: 30s
      start_period: 0s
      start_interval: 1s
      retries: 30
    volumes:
      - 'xpay1_data:/data/db'
      - 'xpay1_config:/data/configdb'
      - './mongodb-keyfile:/etc/mongo/mongodb-keyfile'

  test:
    image: test
    ports:
      - 8080:80
    extra_hosts:
      - 'host.docker.internal:host-gateway'
    networks:
      - xpay

  # mongo2:
  #   image: mongo:7.0
  #   command:
  #     [
  #       '--replSet',
  #       'rs0',
  #       '--bind_ip_all',
  #       '--port',
  #       '27018',
  #       '--keyFile',
  #       '/etc/mongo/mongodb-keyfile'
  #     ]
  #   ports:
  #     - 27018:27018
  #   extra_hosts:
  #     - 'host.docker.internal:host-gateway'
  #   environment:
  #     - MONGO_INITDB_ROOT_USERNAME=xpay
  #     - MONGO_INITDB_ROOT_PASSWORD=d26e449a031ea2a1d1197bbbd6905c24
  #   volumes:
  #     - 'xpay2_data:/data/db'
  #     - 'xpay2_config:/data/configdb'
  #     - './mongodb-keyfile:/etc/mongo/mongodb-keyfile'

  # mongo3:
  #   image: mongo:7.0
  #   command:
  #     [
  #       '--replSet',
  #       'rs0',
  #       '--bind_ip_all',
  #       '--port',
  #       '27019',
  #       '--keyFile',
  #       '/etc/mongo/mongodb-keyfile'
  #     ]
  #   ports:
  #     - 27019:27019
  #   extra_hosts:
  #     - 'host.docker.internal:host-gateway'
  #   environment:
  #     - MONGO_INITDB_ROOT_USERNAME=xpay
  #     - MONGO_INITDB_ROOT_PASSWORD=d26e449a031ea2a1d1197bbbd6905c24
  #   volumes:
  #     - 'xpay3_data:/data/db'
  #     - 'xpay3_config:/data/configdb'
  #     - './mongodb-keyfile:/etc/mongo/mongodb-keyfile'

volumes:
  xpay1_data:
  # xpay2_data:
  # xpay3_data:
  xpay1_config:
  # xpay2_config:
  # xpay3_config:

networks:
  xpay:
    driver: bridge