x-settings-{{network}}: &settings
  image: europe-west3-docker.pkg.dev/hoprassociation/docker-images/hoprd:{{ version|default("latest", true) }}
  restart: unless-stopped
  pull_policy: always
  stop_signal: SIGINT
  security_opt:
    - seccomp:unconfined
  deploy:
    resources:
      reservations:
        memory: 1g
      limits:
        memory: 2g
  logging:
    driver: json-file
    options:
      max-size: 1000M
      max-file: "5"

x-envars: &envvars
  RUST_BACKTRACE: full
  HOPRD_CONFIGURATION_FILE_PATH: /app/hoprd.cfg.yaml
  {% for key, value in envvars.items() %}
  {{ key }}: {{ value }}
  {% endfor %}

services:
  {% for service in services %}
  hoprd-{{ service.network.meta.name }}-{{ service.index }}:
    <<: *settings
    container_name: hoprd-{{ service.network.meta.name }}-{{ service.index }}
    environment:
      HOPRD_API_PORT: {{ service.api_port }}
      <<: *envvars
    volumes:
      - {{ service.folder }}/.hopr-configs/{{ service.network.meta.name }}/hoprd-{{ service.network.meta.name }}-{{ service.index }}.cfg.yaml:/app/hoprd.cfg.yaml
      - {{ service.folder }}/.hopr-ids/{{ service.network.meta.name }}/hoprd-{{ service.network.meta.name }}-{{ service.index }}.id:/app/hopr.id
      - {{ service.folder }}/.volumes/{{ service.network.meta.name }}/hoprd-{{ service.network.meta.name }}-{{ service.index }}:/app/hoprd-db
    ports:
      - {{ service.session_port }}:{{ service.session_port }}/tcp
      - {{ service.session_port }}:{{ service.session_port }}/udp
      - {{ service.network_port }}:{{ service.network_port }}/tcp
      - {{ service.network_port }}:{{ service.network_port }}/udp
      - {{ service.api_port }}:{{ service.api_port }}

  {% endfor %}
  {% for service in services %}
  {% if service.network.slug != none %}
  metricspusher-{{ service.network.meta.name }}-{{ service.index }}:
    image: curlimages/curl:latest
    command: /bin/sh /app/metricspusher.sh
    volumes:
      - ./metricspusher.sh:/app/metricspusher.sh
    network_mode: service:hoprd-{{ service.network.meta.name }}-{{ service.index }}
    container_name: metricspusher-{{ service.network.meta.name }}-{{ service.index }}
    environment:
      HOPRD_API_TOKEN: {{ service.api_password }}
      HOPRD_NODE_NAME: hoprd-{{ service.network.meta.name }}-{{ service.index }}
      HOPRD_JOB_NAME: {{ service.network.slug }}{{ service.index }}
      HOPRD_API_PORT: {{ service.api_port }}
      HOPRD_NETWORK: {{ service.network.meta.name }}

  {% endif %}
  {% endfor %}