services:
  etcd:
    image: harbor.cqt.com:11000/docker/patroni:4.0.6-latest
    container_name: etcd${CURRENT_NODE_NAME}
    restart: always
    command:
      - etcd
      - --quota-backend-bytes=4294967296
      - --auto-compaction-retention=12h
      - --snapshot-count=100000
      - --max-request-bytes=10485760
      - --max-txn-ops=4096
    environment:
      - ETCD_HEARTBEAT_INTERVAL=500
      - ETCD_ELECTION_TIMEOUT=5000
      - ALLOW_NONE_AUTHENTICATION=yes
      - ETCD_INITIAL_CLUSTER_STATE=new
      - ETCD_NAME=etcd${CURRENT_NODE_NAME}
      - ETCD_DATA_DIR=/etcd-data
      - ETCD_ADVERTISE_CLIENT_URLS=${LOCAL_ADDRESS}:2379
      - ETCD_LISTEN_CLIENT_URLS=http://0.0.0.0:2379
      - ETCD_INITIAL_ADVERTISE_PEER_URLS=http://${LOCAL_ADDRESS}:2380
      - ETCD_LISTEN_PEER_URLS=http://0.0.0.0:2380
      - ETCD_INITIAL_CLUSTER_TOKEN=etcd-cluster
      - ETCD_INITIAL_CLUSTER=etcd1=http://${PATRONI1}:2380,etcd2=http://${PATRONI2}:2380,etcd3=http://${PATRONI3}:2380
    volumes:
      - /home/postgresql_cluster/etcd-data:/etcd-data
    #      - /home/postgresql_cluster/etcd-init.sh:/etcd-init.sh
    ports:
      - "2379:2379"
      - "2380:2380"

  patroni:
    image: harbor.cqt.com:11000/docker/patroni:4.0.6-latest
    container_name: patroni${CURRENT_NODE_NAME}
    restart: always
    command: patroni /etc/patroni/patroni.yml
    environment:
      PATRONI_NAME: patroni${CURRENT_NODE_NAME}
      PATRONI_SCOPE: patroni
      ETCDCTL_ENDPOINTS: http://${PATRONI1}:2379,http://${PATRONI2}:2379,http://${PATRONI3}:2379
      PATRONI_ETCD3_HOSTS: ${PATRONI1}:2379,${PATRONI2}:2379,${PATRONI3}:2379
      # etcd 认证
      #      PATRONI_ETCD3_USERNAME: patroni
      #      PATRONI_ETCD3_PASSWORD: patroni@2020
      PATRONI_POSTGRESQL_CONNECT_ADDRESS: ${LOCAL_ADDRESS}:5432
      PATRONI_RESTAPI_CONNECT_ADDRESS: ${LOCAL_ADDRESS}:8008
    ports:
      - "5432:5432"
      - "8008:8008"
    volumes:
      - /home/postgresql_cluster/postgres/data:/home/postgres/data
      - /home/postgresql_cluster/postgres/tablespace/cqt:/home/postgres/tablespace/cqt
      - /home/postgresql_cluster/patroni.yml:/etc/patroni/patroni.yml
      - /home/postgresql_cluster/post_bootstrap.sh:/docker-entrypoint-initdb.d/post_bootstrap.sh
        # volumes:
        #   - /home/postgresql_cluster/postgres/data:/home/postgres/data
        #   - /home/postgresql_cluster/postgres/tablespace/cqt:/home/postgres/tablespace/cqt
        #   - /home/postgresql_cluster/patroni.yml:/home/postgres/postgres0.yml
        #   - /home/postgresql_cluster/post_bootstrap.sh:/docker-entrypoint-initdb.d/post_bootstrap.sh

  haproxy:
    image: harbor.cqt.com:11000/docker/patroni:4.0.6-latest
    container_name: haproxy${CURRENT_NODE_NAME}
    restart: always
    command: haproxy
    environment:
      ETCDCTL_ENDPOINTS: http://${PATRONI1}:2379,http://${PATRONI2}:2379,http://${PATRONI3}:2379
      PATRONI_ETCD3_HOSTS: "'${PATRONI1}:2379','${PATRONI2}:2379','${PATRONI3}:2379'"
      # etcd 认证
      #      PATRONI_ETCD3_USERNAME: patroni
      #      PATRONI_ETCD3_PASSWORD: patroni@2020
      PATRONI_SCOPE: patroni
    ports:
      - "5000:5000"
      - "5001:5001"
      - "8404:8404"
