version: "3.8"

services:
  # Validator service (if VAL1_NODE_NAME is set)
  validator-1:
    image: hyperledger/besu:23.10.0
    container_name: ${VAL1_NODE_NAME:-validator-1}
    restart: unless-stopped
    stop_grace_period: 60s
    networks:
      - besu-net
    volumes:
      - ./config:/config:ro
      - ./data/validator-1:/data
      - ./keys:/keys:ro
      - ./logs/validator-1:/logs
    command:
      - --config-file=/config/config-validator.toml
      - --genesis-file=/config/${GENESIS_FILE:-genesis.json}
      - --data-path=/data
      - --node-private-key-file=/keys/${VAL1_NODE_KEY:-validator1.priv}
      - --p2p-host=${VAL1_P2P_HOST}
      - --p2p-port=${VAL1_P2P_PORT:-30303}
      - --rpc-http-enabled=false
    ports:
      - "${VAL1_P2P_PORT:-30303}:${VAL1_P2P_PORT:-30303}/tcp"
      - "${VAL1_P2P_PORT:-30303}:${VAL1_P2P_PORT:-30303}/udp"
    profiles:
      - validator-1

  # RPC Permissioned service (if RPCP_NODE_NAME is set)
  rpc-perm:
    image: hyperledger/besu:23.10.0
    container_name: ${RPCP_NODE_NAME:-rpc-perm}
    restart: unless-stopped
    stop_grace_period: 60s
    networks:
      - besu-net
    volumes:
      - ./config:/config:ro
      - ./data/rpc-perm:/data
      - ./keys:/keys:ro
      - ./logs/rpc-perm:/logs
    command:
      - --config-file=/config/config-rpc-perm.toml
      - --genesis-file=/config/${GENESIS_FILE:-genesis.json}
      - --data-path=/data
      - --node-private-key-file=/keys/${RPCP_NODE_KEY:-rpc-perm.priv}
      - --p2p-host=${RPCP_P2P_HOST}
      - --p2p-port=${RPCP_P2P_PORT:-30304}
      - --rpc-http-host=0.0.0.0
      - --rpc-http-port=${RPCP_HTTP_PORT:-8545}
    ports:
      - "${RPCP_P2P_PORT:-30304}:${RPCP_P2P_PORT:-30304}/tcp"
      - "${RPCP_P2P_PORT:-30304}:${RPCP_P2P_PORT:-30304}/udp"
      - "${RPCP_HTTP_PORT:-8545}:${RPCP_HTTP_PORT:-8545}/tcp"
    profiles:
      - rpc-perm

  # RPC Core service (if RPCC_NODE_NAME is set)
  rpc-core:
    image: hyperledger/besu:23.10.0
    container_name: ${RPCC_NODE_NAME:-rpc-core}
    restart: unless-stopped
    stop_grace_period: 60s
    networks:
      - besu-net
    volumes:
      - ./config:/config:ro
      - ./data/rpc-core:/data
      - ./keys:/keys:ro
      - ./logs/rpc-core:/logs
    command:
      - --config-file=/config/config-rpc-core.toml
      - --genesis-file=/config/${GENESIS_FILE:-genesis.json}
      - --data-path=/data
      - --node-private-key-file=/keys/${RPCC_NODE_KEY:-rpc-core.priv}
      - --p2p-host=${RPCC_P2P_HOST}
      - --p2p-port=${RPCC_P2P_PORT:-30304}
      - --rpc-http-host=0.0.0.0
      - --rpc-http-port=${RPCC_HTTP_PORT:-8545}
    ports:
      - "${RPCC_P2P_PORT:-30304}:${RPCC_P2P_PORT:-30304}/tcp"
      - "${RPCC_P2P_PORT:-30304}:${RPCC_P2P_PORT:-30304}/udp"
      - "${RPCC_HTTP_PORT:-8545}:${RPCC_HTTP_PORT:-8545}/tcp"
    profiles:
      - rpc-core

  # Member service (if MEM1_NODE_NAME is set)
  member-1:
    image: hyperledger/besu:23.10.0
    container_name: ${MEM1_NODE_NAME:-member-1}
    restart: unless-stopped
    stop_grace_period: 60s
    networks:
      - besu-net
    volumes:
      - ./config:/config:ro
      - ./data/member-1:/data
      - ./keys:/keys:ro
      - ./logs/member-1:/logs
    command:
      - --config-file=/config/config-member.toml
      - --genesis-file=/config/${GENESIS_FILE:-genesis.json}
      - --data-path=/data
      - --node-private-key-file=/keys/${MEM1_NODE_KEY:-member1.priv}
      - --p2p-host=${MEM1_P2P_HOST}
      - --p2p-port=${MEM1_P2P_PORT:-30304}
      - --rpc-http-host=0.0.0.0
      - --rpc-http-port=${MEM1_HTTP_PORT:-8550}
    ports:
      - "${MEM1_P2P_PORT:-30304}:${MEM1_P2P_PORT:-30304}/tcp"
      - "${MEM1_P2P_PORT:-30304}:${MEM1_P2P_PORT:-30304}/udp"
      - "${MEM1_HTTP_PORT:-8550}:${MEM1_HTTP_PORT:-8550}/tcp"
    profiles:
      - member-1

  # Member-2 service (if MEM2_NODE_NAME is set)
  member-2:
    image: hyperledger/besu:23.10.0
    container_name: ${MEM2_NODE_NAME:-member-2}
    restart: unless-stopped
    stop_grace_period: 60s
    networks:
      - besu-net
    volumes:
      - ./config:/config:ro
      - ./data/member-2:/data
      - ./keys:/keys:ro
      - ./logs/member-2:/logs
    command:
      - --config-file=/config/config-member.toml
      - --genesis-file=/config/${GENESIS_FILE:-genesis.json}
      - --data-path=/data
      - --node-private-key-file=/keys/${MEM2_NODE_KEY:-member2.priv}
      - --p2p-host=${MEM2_P2P_HOST}
      - --p2p-port=${MEM2_P2P_PORT:-30304}
      - --rpc-http-host=0.0.0.0
      - --rpc-http-port=${MEM2_HTTP_PORT:-8550}
    ports:
      - "${MEM2_P2P_PORT:-30304}:${MEM2_P2P_PORT:-30304}/tcp"
      - "${MEM2_P2P_PORT:-30304}:${MEM2_P2P_PORT:-30304}/udp"
      - "${MEM2_HTTP_PORT:-8550}:${MEM2_HTTP_PORT:-8550}/tcp"
    profiles:
      - member-2

  # RPC Public service (if RPCPUB_NODE_NAME is set)
  rpc-public:
    image: hyperledger/besu:23.10.0
    container_name: ${RPCPUB_NODE_NAME:-rpc-public}
    restart: unless-stopped
    stop_grace_period: 60s
    networks:
      - besu-net
    volumes:
      - ./config:/config:ro
      - ./data/rpc-public:/data
      - ./keys:/keys:ro
      - ./logs/rpc-public:/logs
    command:
      - --config-file=/config/config-rpc-public.toml
      - --genesis-file=/config/${GENESIS_FILE:-genesis.json}
      - --data-path=/data
      - --node-private-key-file=/keys/${RPCPUB_NODE_KEY:-rpc-public.priv}
      - --p2p-host=${RPCPUB_P2P_HOST}
      - --p2p-port=${RPCPUB_P2P_PORT:-30303}
      - --rpc-http-host=0.0.0.0
      - --rpc-http-port=${RPCPUB_HTTP_PORT:-8545}
    ports:
      - "${RPCPUB_P2P_PORT:-30303}:${RPCPUB_P2P_PORT:-30303}/tcp"
      - "${RPCPUB_P2P_PORT:-30303}:${RPCPUB_P2P_PORT:-30303}/udp"
      - "${RPCPUB_HTTP_PORT:-8545}:${RPCPUB_HTTP_PORT:-8545}/tcp"
    profiles:
      - rpc-public

networks:
  besu-net:
    external: true

