---
services:
  # This is needed for creating non-root data folders on host.
  # By default, if the folders don't exist when mounting, compose creates them with root as owner.
  # With root owner, accessing the WAL files from local tests will fail due to an unauthorized access error.
  init:
    image: 'docker.io/library/ubuntu:latest'
    user: root
    group_add:
      - '${GROUP_ID:-root}'
    volumes:
      - ${ETCD_ROBUSTNESS_DATA_PATH:-/tmp/etcddata}0:/var/etcddata0
      - ${ETCD_ROBUSTNESS_REPORT_PATH:-/tmp/etcdreport}:/var/report
    command:
      - /bin/sh
      - -c
      - |
        rm -rf /var/etcddata0/* /var/report/*
        chown -R ${USER_ID:-root}:${GROUP_ID:-root} /var/etcddata0 /var/report

  etcd0:
    image: 'etcd-server:${IMAGE_TAG:-latest}'
    container_name: etcd0
    hostname: etcd0
    environment:
      ETCD_NAME: "etcd0"
      ETCD_INITIAL_ADVERTISE_PEER_URLS: "http://etcd0:2380"
      ETCD_LISTEN_PEER_URLS: "http://0.0.0.0:2380"
      ETCD_LISTEN_CLIENT_URLS: "http://0.0.0.0:2379"
      ETCD_ADVERTISE_CLIENT_URLS: "http://etcd0.etcd:2379"
      ETCD_INITIAL_CLUSTER_TOKEN: "etcd-cluster-1"
      ETCD_INITIAL_CLUSTER: "etcd0=http://etcd0:2380"
      ETCD_INITIAL_CLUSTER_STATE: "new"
      ETCD_DATA_DIR: "/var/etcd/data"
      ETCD_SNAPSHOT_CATCHUP_ENTRIES: 100
      ETCD_SNAPSHOT_COUNT: 50
      ETCD_COMPACTION_BATCH_LIMIT: 10
      ETCD_VERIFY: "all"
    user: "${USER_ID:-root}:${GROUP_ID:-root}"
    depends_on:
      init:
        condition: service_completed_successfully
    ports:
      - 12379:2379
    volumes:
      - ${ETCD_ROBUSTNESS_DATA_PATH:-/tmp/etcddata}0:/var/etcd/data

  client:
    image: 'etcd-client:${IMAGE_TAG:-latest}'
    container_name: client
    entrypoint: ["/opt/antithesis/entrypoint/entrypoint"]
    user: "${USER_ID:-root}:${GROUP_ID:-root}"
    depends_on:
      etcd0:
        condition: service_started
    volumes:
      - ${ETCD_ROBUSTNESS_DATA_PATH:-/tmp/etcddata}0:/var/etcddata0
      - ${ETCD_ROBUSTNESS_REPORT_PATH:-/tmp/etcdreport}:/var/report
