version: "3.7"

networks:
  mother:
    external: true
volumes:
  db-1-data:
  db-0-data:

services:
  pg-0:
    image: registry.vnfco.ir/library/bitnami/postgresql-repmgr:13.5.0-debian-10-r48
    environment:
     - REPMGR_PARTNER_NODES=pg-0,pg-1 
     - REPMGR_NODE_NAME=pg-0 
     - REPMGR_NODE_NETWORK_NAME=pg-0 
     - REPMGR_PRIMARY_HOST=pg-0 
     - REPMGR_PASSWORD=UjvGvyYXZZTvL1GsST7AJrtmQjqSV+LOihKQaEGyUUtdQAUGSA3BsFEi5B4KoRBF 
     - POSTGRESQL_PASSWORD=xHTpBf4wC+bBeNg2pL6Ga7VEWKFJx7VPEUpqxwPFfOc2YYTVwFQuHfsiqoVeT9+6 
    volumes:
      - db-0-data:/bitnami/postgresql
    ports:
      - "5432:5432"
    networks:
      - mother
    deploy:
      update_config:
        parallelism: 1
        delay: 10s
        order: stop-first
      restart_policy:
        condition: any
        delay: 5s
        max_attempts: 3
        window: 120s
      
  pg-1:
    image: registry.vnfco.ir/library/bitnami/postgresql-repmgr:13.5.0-debian-10-r48
    environment:
      - REPMGR_PARTNER_NODES=pg-0,pg-1 
      - REPMGR_NODE_NAME=pg-1 
      - REPMGR_NODE_NETWORK_NAME=pg-1 
      - REPMGR_PRIMARY_HOST=pg-0
      - REPMGR_PASSWORD=UjvGvyYXZZTvL1GsST7AJrtmQjqSV+LOihKQaEGyUUtdQAUGSA3BsFEi5B4KoRBF 
      - POSTGRESQL_PASSWORD=xHTpBf4wC+bBeNg2pL6Ga7VEWKFJx7VPEUpqxwPFfOc2YYTVwFQuHfsiqoVeT9+6 
    volumes:
      - db-1-data:/bitnami/postgresql
    ports:
      - "5433:5432"
    networks:
      - mother
    deploy:
      update_config:
        parallelism: 1
        delay: 10s
        order: start-first
      restart_policy:
        condition: any
        delay: 5s
        max_attempts: 3
        window: 120s

  # pgmaster:
  #   image: registry.vnfco.ir/library/crunchydata/crunchy-postgres:centos7-13.1-4.5.1
  #   volumes:
  #       - '/volume/pg:/bitnami/postgresql'
  #   environment:
  #     - POSTGRESQL_USERNAME=igarsonAgent
  #     - POSTGRESQL_PASSWORD=xHTpBf4wC+bBeNg2pL6Ga7VEWKFJx7VPEUpqxwPFfOc2YYTVwFQuHfsiqoVeT9+6
  #     - POSTGRESQL_DATABASE=igarsonDB
  #     - POSTGRESQL_REPLICATION_MODE=master
  #     - POSTGRESQL_REPLICATION_USER=pgreplicator
  #     - POSTGRESQL_REPLICATION_PASSWORD=ciXz6xmnEMZSO+0T8L6mGcFJrAvPzkTC04oh/WYIRi51gMQLPfW8tTEHALX6fhk4
  #   deploy:
  #     update_config:
  #       parallelism: 1
  #       delay: 10s
  #       order: start-first
  #     restart_policy:
  #       condition: any
  #       delay: 5s
  #       max_attempts: 3
  #       window: 120s
  #     resources:
  #       limits:
  #         cpus: '1'
  #         memory: 300M
  #     replicas: 1
  #     mode: replicated
  #     placement:
  #       constraints:
  #         - node.role == worker
  #   ports:
  #     - "5432:5432"
  #   networks:
  #     - mother

  # pgslave:
  #   image: registry.vnfco.ir/library/crunchydata/crunchy-postgres:centos7-13.1-4.5.1
  #   environment:
  #     - POSTGRESQL_REPLICATION_MODE=slave
  #     - POSTGRESQL_REPLICATION_USER=pgreplicator
  #     - POSTGRESQL_REPLICATION_PASSWORD=ciXz6xmnEMZSO+0T8L6mGcFJrAvPzkTC04oh/WYIRi51gMQLPfW8tTEHALX6fhk4
  #     - POSTGRESQL_MASTER_HOST=pgmaster
  #     - POSTGRESQL_PASSWORD=xHTpBf4wC+bBeNg2pL6Ga7VEWKFJx7VPEUpqxwPFfOc2YYTVwFQuHfsiqoVeT9+6
  #     - POSTGRESQL_MASTER_PORT_NUMBER=5432

  #   deploy:
  #     update_config:
  #       parallelism: 1
  #       delay: 10s
  #       order: start-first
  #     restart_policy:
  #       condition: any
  #       delay: 5s
  #       max_attempts: 3
  #       window: 120s
  #     resources:
  #       limits:
  #         cpus: '0.7'
  #         memory: 300M
  #     mode: replicated
  #     replicas: 1
  #     placement:
  #       constraints:
  #            - node.role == worker
  #   ports:
  #     - "5433:5432"
  #   networks:
  #     - mother
