x-no-proxy-env: &no-proxy-env
  HTTP_PROXY: ""
  HTTPS_PROXY: ""
  ALL_PROXY: ""
  http_proxy: ""
  https_proxy: ""
  all_proxy: ""
  NO_PROXY: localhost,127.0.0.1,::1,pd,minio,tikv-1,tikv-2,tikv-3,tikv-worker,copr-worker,tidb-system,tidb-normal
  no_proxy: localhost,127.0.0.1,::1,pd,minio,tikv-1,tikv-2,tikv-3,tikv-worker,copr-worker,tidb-system,tidb-normal

x-common-env: &common-env
  <<: *no-proxy-env
  AWS_ACCESS_KEY_ID: minioadmin
  AWS_SECRET_ACCESS_KEY: minioadmin
  AWS_REGION: us-west-2
  AWS_DEFAULT_REGION: us-west-2
  AWS_ENDPOINT_URL: http://minio:9000
  AWS_EC2_METADATA_DISABLED: "true"
  DFS_BACKEND: s3
  DFS_PREFIX: cse
  DFS_S3_BUCKET: tidbcloud-local-dfs
  DFS_S3_ENDPOINT: http://minio:9000
  DFS_S3_KEY_ID: minioadmin
  DFS_S3_SECRET_KEY: minioadmin
  DFS_S3_REGION: us-west-2
  DFS_REMOTE_COMPACTOR_ADDR: http://tikv-worker:19000/compact
  DFS_ALLOW_FALLBACK_LOCAL: "false"

x-service-limits: &service-limits
  cpus: "4.0"
  mem_limit: 8g
  deploy:
    resources:
      limits:
        cpus: "4.0"
        memory: 8G

services:
  minio:
    image: hub.pingcap.net/test-infra/minio:latest
    command: ["server", "/data", "--console-address", ":9001"]
    environment:
      <<: *no-proxy-env
      MINIO_ROOT_USER: minioadmin
      MINIO_ROOT_PASSWORD: minioadmin
      MINIO_REGION: us-west-2
      MINIO_REGION_NAME: us-west-2
    ports:
      - "9000:9000"
      - "9001:9001"
    volumes:
      - minio-data:/data
    healthcheck:
      test: ["CMD-SHELL", "curl -fsS http://127.0.0.1:9000/minio/health/live >/dev/null || wget -q -O - http://127.0.0.1:9000/minio/health/live >/dev/null"]
      interval: 5s
      timeout: 3s
      retries: 60

  minio-init:
    image: hub.pingcap.net/test-infra/minio:latest
    entrypoint: ["/bin/sh"]
    depends_on:
      minio:
        condition: service_healthy
    environment:
      <<: *no-proxy-env
      MINIO_ROOT_USER: minioadmin
      MINIO_ROOT_PASSWORD: minioadmin
      MINIO_ENDPOINT: http://minio:9000
      MINIO_REGION: us-west-2
      MINIO_REGION_NAME: us-west-2
      MINIO_BUCKETS: "tidbcloud-local-dfs tidbcloud-local-global-sort tidbcloud-local-metering"
    volumes:
      - minio-data:/data
      - ./bootstrap/init-minio.sh:/bootstrap/init-minio.sh:ro
    command: ["/bootstrap/init-minio.sh"]
    restart: "no"

  pd:
    <<: *service-limits
    image: hub-zot.pingcap.net/mirrors/tidbx/tikv/pd/image:release-nextgen-202603
    entrypoint: ["/bin/sh"]
    command: ["-ec", "mkdir -p /var/log/pd && exec /pd-server --config /etc/pd/pd.toml"]
    ports:
      - "2379:2379"
      - "2380:2380"
    volumes:
      - pd-data:/var/lib/pd
      - ./configs/pd.toml:/etc/pd/pd.toml:ro
    environment: *no-proxy-env
    healthcheck:
      test: ["CMD-SHELL", "/pd-ctl -u http://127.0.0.1:2379 member >/dev/null"]
      interval: 5s
      timeout: 5s
      retries: 60

  create-keyspace:
    image: hub-zot.pingcap.net/mirrors/tidbx/tikv/pd/image:release-nextgen-202603
    entrypoint: ["/bin/sh"]
    depends_on:
      pd:
        condition: service_healthy
    environment:
      <<: *no-proxy-env
      PD_ENDPOINT: http://pd:2379
      KEYSPACE_NAME: local_normal
    volumes:
      - ./bootstrap/create-keyspace.sh:/bootstrap/create-keyspace.sh:ro
    command: ["/bootstrap/create-keyspace.sh"]
    restart: "no"

  tikv-1:
    <<: *service-limits
    image: ${TIKV_COMPOSE_IMAGE:-hub-zot.pingcap.net/mirrors/tidbx/tikv/tikv/image:release-nextgen-202603}
    entrypoint: ["/bin/sh"]
    command: ["-ec", "mkdir -p /var/lib/tikv /var/lib/raft/data /var/log/tikv && exec /tikv-server --config /etc/tikv/tikv.toml"]
    environment: *common-env
    depends_on:
      pd:
        condition: service_healthy
      minio:
        condition: service_healthy
    ports:
      - "20181:20180"
    volumes:
      - tikv-1-data:/var/lib/tikv
      - tikv-1-raft:/var/lib/raft
      - ./configs/tikv-1.toml:/etc/tikv/tikv.toml:ro
    healthcheck:
      test: ["CMD-SHELL", "curl -fsS http://127.0.0.1:20180/status >/dev/null || wget -q -O - http://127.0.0.1:20180/status >/dev/null"]
      interval: 5s
      timeout: 5s
      retries: 60

  tikv-2:
    <<: *service-limits
    image: ${TIKV_COMPOSE_IMAGE:-hub-zot.pingcap.net/mirrors/tidbx/tikv/tikv/image:release-nextgen-202603}
    entrypoint: ["/bin/sh"]
    command: ["-ec", "mkdir -p /var/lib/tikv /var/lib/raft/data /var/log/tikv && exec /tikv-server --config /etc/tikv/tikv.toml"]
    environment: *common-env
    depends_on:
      pd:
        condition: service_healthy
      minio:
        condition: service_healthy
    ports:
      - "20182:20180"
    volumes:
      - tikv-2-data:/var/lib/tikv
      - tikv-2-raft:/var/lib/raft
      - ./configs/tikv-2.toml:/etc/tikv/tikv.toml:ro
    healthcheck:
      test: ["CMD-SHELL", "curl -fsS http://127.0.0.1:20180/status >/dev/null || wget -q -O - http://127.0.0.1:20180/status >/dev/null"]
      interval: 5s
      timeout: 5s
      retries: 60

  tikv-3:
    <<: *service-limits
    image: ${TIKV_COMPOSE_IMAGE:-hub-zot.pingcap.net/mirrors/tidbx/tikv/tikv/image:release-nextgen-202603}
    entrypoint: ["/bin/sh"]
    command: ["-ec", "mkdir -p /var/lib/tikv /var/lib/raft/data /var/log/tikv && exec /tikv-server --config /etc/tikv/tikv.toml"]
    environment: *common-env
    depends_on:
      pd:
        condition: service_healthy
      minio:
        condition: service_healthy
    ports:
      - "20183:20180"
    volumes:
      - tikv-3-data:/var/lib/tikv
      - tikv-3-raft:/var/lib/raft
      - ./configs/tikv-3.toml:/etc/tikv/tikv.toml:ro
    healthcheck:
      test: ["CMD-SHELL", "curl -fsS http://127.0.0.1:20180/status >/dev/null || wget -q -O - http://127.0.0.1:20180/status >/dev/null"]
      interval: 5s
      timeout: 5s
      retries: 60

  tikv-worker:
    <<: *service-limits
    image: ${TIKV_COMPOSE_IMAGE:-hub-zot.pingcap.net/mirrors/tidbx/tikv/tikv/image:release-nextgen-202603}
    entrypoint: ["/bin/sh"]
    command: ["-ec", "mkdir -p /var/lib/tikv-worker /var/log/tikv-worker && exec /tikv-worker --config /etc/tikv-worker/config.toml --log-file /var/log/tikv-worker/tikv-worker.log"]
    environment: *common-env
    depends_on:
      pd:
        condition: service_healthy
      minio:
        condition: service_healthy
    volumes:
      - tikv-worker-data:/var/lib/tikv-worker
      - ./configs/tikv-worker.toml:/etc/tikv-worker/config.toml:ro
    healthcheck:
      test: ["CMD-SHELL", "curl -fsS http://127.0.0.1:19000/metrics >/dev/null || wget -q -O - http://127.0.0.1:19000/metrics >/dev/null"]
      interval: 5s
      timeout: 5s
      retries: 60

  copr-worker:
    <<: *service-limits
    image: ${TIKV_COMPOSE_IMAGE:-hub-zot.pingcap.net/mirrors/tidbx/tikv/tikv/image:release-nextgen-202603}
    entrypoint: ["/bin/sh"]
    command: ["-ec", "mkdir -p /var/lib/tikv-worker /var/log/tikv-worker && exec /tikv-worker --config /etc/tikv-worker/config.toml --log-file /var/log/tikv-worker/copr-worker.log"]
    environment: *common-env
    depends_on:
      pd:
        condition: service_healthy
      minio:
        condition: service_healthy
    volumes:
      - copr-worker-data:/var/lib/tikv-worker
      - ./configs/copr-worker.toml:/etc/tikv-worker/config.toml:ro
    healthcheck:
      test: ["CMD-SHELL", "curl -fsS http://127.0.0.1:19000/metrics >/dev/null || wget -q -O - http://127.0.0.1:19000/metrics >/dev/null"]
      interval: 5s
      timeout: 5s
      retries: 60

  tidb-system:
    <<: *service-limits
    image: hub-zot.pingcap.net/mirrors/tidbx/pingcap/tidb/images/tidb-server:release-nextgen-202603
    entrypoint: ["/bin/sh"]
    command: ["-ec", "mkdir -p /var/log/tidb /tmp/tidb_tmp && exec /tidb-server --config /etc/tidb/tidb.toml"]
    environment: *common-env
    depends_on:
      pd:
        condition: service_healthy
      tikv-1:
        condition: service_healthy
      tikv-2:
        condition: service_healthy
      tikv-3:
        condition: service_healthy
      tikv-worker:
        condition: service_healthy
      copr-worker:
        condition: service_healthy
    ports:
      - "4000:4000"
      - "10080:10080"
    volumes:
      - ./configs/tidb-system.toml:/etc/tidb/tidb.toml:ro
      - ./bootstrap/bootstrap-system.sql:/etc/tidb-bootstrap/bootstrap.sql:ro
    healthcheck:
      test: ["CMD-SHELL", "curl -fsS http://127.0.0.1:10080/status >/dev/null || wget -q -O - http://127.0.0.1:10080/status >/dev/null"]
      interval: 5s
      timeout: 5s
      retries: 120

  tidb-normal:
    <<: *service-limits
    image: hub-zot.pingcap.net/mirrors/tidbx/pingcap/tidb/images/tidb-server:release-nextgen-202603
    entrypoint: ["/bin/sh"]
    command: ["-ec", "mkdir -p /var/log/auditlog /tmp/tidb_tmp && exec /tidb-server --config /etc/tidb/tidb.toml"]
    environment: *common-env
    depends_on:
      create-keyspace:
        condition: service_completed_successfully
      tidb-system:
        condition: service_healthy
      tikv-1:
        condition: service_healthy
      tikv-2:
        condition: service_healthy
      tikv-3:
        condition: service_healthy
      tikv-worker:
        condition: service_healthy
      copr-worker:
        condition: service_healthy
    ports:
      - "4001:4000"
      - "10081:10080"
    volumes:
      - ./configs/tidb-normal.toml:/etc/tidb/tidb.toml:ro
      - ./bootstrap/bootstrap-normal.sql:/etc/tidb-bootstrap/bootstrap.sql:ro
    healthcheck:
      test: ["CMD-SHELL", "curl -fsS http://127.0.0.1:10080/status >/dev/null || wget -q -O - http://127.0.0.1:10080/status >/dev/null"]
      interval: 5s
      timeout: 5s
      retries: 120

volumes:
  pd-data:
  tikv-1-data:
  tikv-2-data:
  tikv-3-data:
  tikv-1-raft:
  tikv-2-raft:
  tikv-3-raft:
  tikv-worker-data:
  copr-worker-data:
  minio-data:
