# Volumes required by the three rt nodes, publisher and susbcriber
volumes:
  rt-data-0:        # persistent volume for rt-data-0
  rt-data-session:  # shared volume across all three rt containers, used to orchestrate hard reset
  subscriber-1:     # persistent volume for simple subscriber
  publisher-1:      # persistent volume for simple publisher

# Bridge network across all containers
x-kxnet:
  &kxnet
  networks:
    - kx
# Intra-RT ports, used for comms within the rt cluster:
#      - 127.0.0.1:4000:4000/tcp
#      - 127.0.0.1:5009:5009/tcp
#      - 127.0.0.1:7000:7000/udp
#      - 127.0.0.1:7100:7100/tcp
#      - 127.0.0.1:8000:8000/udp
#      - 127.0.0.1:9000:9000/udp
# Internal ports, used for comms between the internal publishers/subscribers and the rt cluster:
#      - 127.0.0.1:5001:5001/tcp
#      - 127.0.0.1:5002:5002/tcp
# External ports, used for comms between the external publishers and the rt cluster:
#      - 127.0.0.1:5000:5000/tcp

# Environment variables common to all RT sequencers
x-rt-env:
  &rt-env
    environment:
      - RT_TOPIC_PREFIX
      - RT_SINK
      - RAFT_HEARTBEAT
      - RAFT_LOG_SIZE
      - RAFT_CHUNK_SIZE
      - RT_LOGLEVEL_CONSOLE
      - RT_SEQ_SESSION_PATH
      - RT_EXTERN_PREFIX
      - RT_QURAFT_LOG_LEVEL
      - RT_LOG_LEADER

# Startup command line common to all RT sequencers
x-rt-command:
  &rt-command
    command:
      [
        '-p',
        '6000',
        '-in',
        '$in_dir',
        '-out',
        '$out_dir',
        '-cp',
        '$state_dir',
        '-size',
        '$size',
        '-limit',
        '$limit',
        '-time',
        '$time',
        '-disk',
        '$disk'
      ]


networks:
  kx:
    name: kx
    driver: bridge

services:
  # RT services - these are different services (not replicas), each with its own volume
  rt-data-0:
    image: ${rt_sequencer}:${rt_sequencer_ver}
    # Need to set hostname so rt nodes/publishers/subcribers can find each other
    hostname: rt-data-0
    container_name: rt-data-0
    <<: [*rt-command, *rt-env, *kxnet]
    # Have to run as root (default is nobody) in order to write to docker volume
    user: root
    restart: unless-stopped
    ports:
      - 127.0.0.1:5000:5000/tcp
      - 127.0.0.1:5001:5001/tcp
      - 127.0.0.1:5002:5002/tcp
    volumes:
      - rt-data-0:/s
      - rt-data-session:/rt-session
      - ${kx_licence_dir}:/opt/kx/lic
      - ${server_certs_dir}:/cert

  subscriber-1:
    image: ${rt_subscriber}:${rt_subscriber_ver}
    command: [ '-p', '6000' ]
    # Have to run as root (default is nobody) in order to write to docker volume
    user: root
    # Open a TTY for interactive publishing
    tty: true
    stdin_open: true
    environment:
      - RT_TOPIC_PREFIX
      - RT_LOG_PATH
      - RT_STREAM
      - RT_REPLICAS
    volumes:
      - subscriber-1:/s
      - ${kx_licence_dir}:/opt/kx/lic
    <<: *kxnet

  publisher-1:
    image: ${rt_publisher}:${rt_publisher_ver}
    command: [ '-p', '6000' ]
    # Have to run as root (default is nobody) in order to write to docker volume
    user: root
    # Open a TTY to inspect received messages
    tty: true
    stdin_open: true
    environment:
      - RT_TOPIC_PREFIX
      - RT_LOG_PATH
      - RT_STREAM
      - PUB_TIMER_FREQ
      - PUB_TIMER_MSG
      - RT_REPLICAS
    volumes:
      - publisher-1:/s
      - ${kx_licence_dir}:/opt/kx/lic
    <<: *kxnet
