version: "3.9"

services:
  etcd-1:
    image: quay.io/coreos/etcd:v3.5.15
    container_name: etcd-1
    hostname: etcd-1
    command:
      - /usr/local/bin/etcd
      - --name=etcd-1
      - --data-dir=/etcd-data
      - --listen-client-urls=http://0.0.0.0:2379
      - --advertise-client-urls=http://etcd-1:2379
      - --listen-peer-urls=http://0.0.0.0:2380
      - --initial-advertise-peer-urls=http://etcd-1:2380
      - --initial-cluster=etcd-1=http://etcd-1:2380,etcd-2=http://etcd-2:2380,etcd-3=http://etcd-3:2380
      - --initial-cluster-state=new
      - --initial-cluster-token=kv-store-prod
    ports:
      - "2379:2379"
    volumes:
      - etcd-1-data:/etcd-data
    networks:
      - kv-net
    healthcheck:
      test: ["CMD", "etcdctl", "endpoint", "health"]
      interval: 10s
      timeout: 5s
      retries: 5

  etcd-2:
    image: quay.io/coreos/etcd:v3.5.15
    container_name: etcd-2
    hostname: etcd-2
    command:
      - /usr/local/bin/etcd
      - --name=etcd-2
      - --data-dir=/etcd-data
      - --listen-client-urls=http://0.0.0.0:2379
      - --advertise-client-urls=http://etcd-2:2379
      - --listen-peer-urls=http://0.0.0.0:2380
      - --initial-advertise-peer-urls=http://etcd-2:2380
      - --initial-cluster=etcd-1=http://etcd-1:2380,etcd-2=http://etcd-2:2380,etcd-3=http://etcd-3:2380
      - --initial-cluster-state=new
      - --initial-cluster-token=kv-store-prod
    volumes:
      - etcd-2-data:/etcd-data
    networks:
      - kv-net
    healthcheck:
      test: ["CMD", "etcdctl", "endpoint", "health"]
      interval: 10s
      timeout: 5s
      retries: 5

  etcd-3:
    image: quay.io/coreos/etcd:v3.5.15
    container_name: etcd-3
    hostname: etcd-3
    command:
      - /usr/local/bin/etcd
      - --name=etcd-3
      - --data-dir=/etcd-data
      - --listen-client-urls=http://0.0.0.0:2379
      - --advertise-client-urls=http://etcd-3:2379
      - --listen-peer-urls=http://0.0.0.0:2380
      - --initial-advertise-peer-urls=http://etcd-3:2380
      - --initial-cluster=etcd-1=http://etcd-1:2380,etcd-2=http://etcd-2:2380,etcd-3=http://etcd-3:2380
      - --initial-cluster-state=new
      - --initial-cluster-token=kv-store-prod
    volumes:
      - etcd-3-data:/etcd-data
    networks:
      - kv-net
    healthcheck:
      test: ["CMD", "etcdctl", "endpoint", "health"]
      interval: 10s
      timeout: 5s
      retries: 5

networks:
  kv-net:
    driver: bridge

volumes:
  etcd-1-data:
  etcd-2-data:
  etcd-3-data: