version: '3.7'

x-env: &patroni-env
  PATRONI_API_CONNECT_PORT: 8091
  REPLICATION_NAME: replicator
  REPLICATION_PASS: Wilnukr_23
  SU_NAME: postgres
  SU_PASS: Wilnukr_23
  POSTGRES_APP_ROLE_PASS: Wilnukr_23

services:
  dblb:
    image: dblb:latest
    hostname: dblb
    build:
      context: src/haproxy
      dockerfile: Dockerfile
    ports:
      - "7000:7000"
      - "65432:65432"
    volumes:
      - ${PWD}/conf/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg
    networks:
      - patroni
    restart: always

  zoo1:
    image: zookeeper:3.4
    hostname: zoo1
    environment:
      ZOO_MY_ID: 1
      ZOO_SERVERS: server.1=0.0.0.0:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888
    networks:
      - patroni

  zoo2:
    image: zookeeper:3.4
    hostname: zoo2
    environment:
      ZOO_MY_ID: 2
      ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=0.0.0.0:2888:3888 server.3=zoo3:2888:3888
    networks:
      - patroni

  zoo3:
    image: zookeeper:3.4
    hostname: zoo3
    environment:
      ZOO_MY_ID: 3
      ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=0.0.0.0:2888:3888
    networks:
      - patroni

  pat1:
    image: patroni:latest
    hostname: pat1
    build:
      context: src/patroni
      dockerfile: Dockerfile
    networks:
      - patroni
    volumes:
      - ${PWD}/conf/patroni.yml:/etc/patroni.yml
      - ${PWD}/data/pgsql1:/data/patroni
    environment:
      <<: *patroni-env
    restart: always

  pat2:
    image: patroni:latest
    hostname: pat2
    networks:
      - patroni
    volumes:
      - ${PWD}/conf/patroni.yml:/etc/patroni.yml
      - ${PWD}/data/pgsql2:/data/patroni
    environment:
      <<: *patroni-env
    restart: always

  pat3:
    image: patroni:latest
    hostname: pat3
    networks:
      - patroni
    volumes:
      - ${PWD}/conf/patroni.yml:/etc/patroni.yml
      - ${PWD}/data/pgsql3:/data/patroni
    environment:
      <<: *patroni-env
    restart: always

networks:
  patroni:
    name: patroni

