networks:
  dom-cli-domjudge:
    name: dom-cli-domjudge

services:
  mariadb:
    container_name: dom-cli-mariadb
    image: mariadb:11.7.2
    platform: linux/x86_64
    environment:
      - MYSQL_ROOT_PASSWORD={{ db_password }}
      - MYSQL_DATABASE=domjudge
      - MYSQL_USER=domjudge
      - MYSQL_PASSWORD={{ db_password }}
    networks:
      - dom-cli-domjudge
    ports:
      - "3306:3306"
    restart: unless-stopped

  mysql-client:
    container_name: dom-cli-mysql-client
    image: mysql:8
    platform: linux/x86_64
    entrypoint: tail -f /dev/null  # So it keeps running and stays idle
    networks:
      - dom-cli-domjudge
    depends_on:
      - mariadb
    restart: unless-stopped

  domserver:
    container_name: dom-cli-domserver
    image: domjudge/domserver:8.3.1
    platform: linux/x86_64
    environment:
      - MYSQL_HOST=dom-cli-mariadb
      - MYSQL_ROOT_PASSWORD={{ db_password }}
      - MYSQL_DATABASE=domjudge
      - MYSQL_USER=domjudge
      - MYSQL_PASSWORD={{ db_password }}
    networks:
      - dom-cli-domjudge
    ports:
      - "{{ platform_port }}:80"
    depends_on:
      - mariadb
    restart: unless-stopped

{% for i in range(judgehost_count) %}
  judgehost-{{i+1}}:
    container_name: dom-cli-judgehost-{{i+1}}
    hostname: judgedaemon-{{i+1}}
    image: domjudge/judgehost:8.3.1
    platform: linux/x86_64
    privileged: true
    volumes:
      - /sys/fs/cgroup:/sys/fs/cgroup
    environment:
      - DAEMON_ID={{i+1}}
      - DOMSERVER_BASEURL=http://dom-cli-domserver/
      - JUDGEDAEMON_PASSWORD={{ judgedaemon_password }}
    networks:
      - dom-cli-domjudge
    depends_on:
      - domserver
    restart: unless-stopped
{% endfor %}
