name: 'reth'

services:
  reth:
    restart: unless-stopped
    image: ghcr.io/paradigmxyz/reth
    ports:
      - '9001:9001' # metrics
      - '30303:30303' # eth/66 peering
      - '8545:8545' # rpc
      - '8551:8551' # engine
    volumes:
      - mainnet_data:/root/.local/share/reth/mainnet
      - sepolia_data:/root/.local/share/reth/sepolia
      - holesky_data:/root/.local/share/reth/holesky
      - logs:/root/logs
      - ./jwttoken:/root/jwt:ro
    # https://paradigmxyz.github.io/reth/run/troubleshooting.html#concurrent-database-access-error-using-containersdocker
    pid: host
    # For Sepolia, replace `--chain mainnet` with `--chain sepolia`
    # For Holesky, replace `--chain mainnet` with `--chain holesky`
    command: >
      node
      --chain mainnet
      --metrics 0.0.0.0:9001
      --log.file.directory /root/logs
      --authrpc.addr 0.0.0.0
      --authrpc.port 8551
      --authrpc.jwtsecret /root/jwt/jwt.hex
      --http --http.addr 0.0.0.0 --http.port 8545
      --http.api "eth,net,web3"

  prometheus:
    restart: unless-stopped
    image: prom/prometheus
    depends_on:
      - reth
    ports:
      - 9090:9090
    volumes:
      - ./prometheus/:/etc/prometheus/
      - prometheusdata:/prometheus
    command:
      - --config.file=/etc/prometheus/prometheus.yml
      - --storage.tsdb.path=/prometheus

  grafana:
    restart: unless-stopped
    image: grafana/grafana:latest
    depends_on:
      - reth
      - prometheus
    ports:
      - 3000:3000
    environment:
      PROMETHEUS_URL: http://prometheus:9090
    volumes:
      - grafanadata:/var/lib/grafana
      - ./grafana/datasources:/etc/grafana/provisioning/datasources
      - ./grafana/dashboards:/etc/grafana/provisioning_temp/dashboards
    # 1. Copy dashboards from temp directory to prevent modifying original host files
    # 2. Replace Prometheus datasource placeholder with the actual name
    # 3. Run Grafana
    entrypoint: >
      sh -c "cp -r /etc/grafana/provisioning_temp/dashboards/. /etc/grafana/provisioning/dashboards &&
             find /etc/grafana/provisioning/dashboards/ -name '*.json' -exec sed -i 's/$${DS_PROMETHEUS}/Prometheus/g' {} \+ &&
             /run.sh"

volumes:
  mainnet_data:
    driver: local
  sepolia_data:
    driver: local
  holesky_data:
    driver: local
  logs:
    driver: local
  prometheusdata:
    driver: local
  grafanadata:
    driver: local
