name: pg-replica-cluster

x-node-env: &node-env
  PGDATA: "/var/lib/postgresql/data"
  RAFT_PORT: "7400"
  PEERS: "1@node1:7400,2@node2:7400,3@node3:7400"
  PG_ADDRS: "1@node1:5432,2@node2:5432,3@node3:5432"
  SEED_HOST: "node1"
  SU_PASSWORD: "${SU_PASSWORD:-pgr_super_pw}"
  REPL_PASSWORD: "${REPL_PASSWORD:-pgr_repl_pw}"
  APP_USER: "${APP_USER:-weido}"
  APP_PASSWORD: "${APP_PASSWORD:-weido_test_pw}"
  APP_DB: "${APP_DB:-weido}"
  SYNCHRONOUS: "${SYNCHRONOUS:-on}"

services:
  node1:
    build:
      context: ..
      dockerfile: docker/Dockerfile
    image: pg-replica-paradedb:local
    container_name: pgr-node1
    environment:
      <<: *node-env
      NODE_ID: "1"
    volumes: [node1data:/var/lib/postgresql/data]
    ports: ["5432:5432"]
    networks: [pgr]
    restart: unless-stopped

  node2:
    image: pg-replica-paradedb:local
    container_name: pgr-node2
    depends_on: [node1]
    environment:
      <<: *node-env
      NODE_ID: "2"
    volumes: [node2data:/var/lib/postgresql/data]
    ports: ["5433:5432"]
    networks: [pgr]
    restart: unless-stopped

  node3:
    image: pg-replica-paradedb:local
    container_name: pgr-node3
    depends_on: [node1]
    environment:
      <<: *node-env
      NODE_ID: "3"
    volumes: [node3data:/var/lib/postgresql/data]
    ports: ["5434:5432"]
    networks: [pgr]
    restart: unless-stopped

  dozzle:
    image: amir20/dozzle:v10.5.2
    container_name: pgr-dozzle
    environment:
      DOZZLE_NO_ANALYTICS: "true"
      DOZZLE_LEVEL: info
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
    ports: ["8888:8080"]
    networks: [pgr]
    restart: unless-stopped
    mem_limit: 128m

volumes:
  node1data:
  node2data:
  node3data:

networks:
  pgr:
    driver: bridge
