version: '3'
services:
  {{nginx_name}}:
    image: docker.io/nginx:latest
    user: root:0
    container_name: {{nginx_name}}
    hostname: {{nginx_name}}
{% if debug %}
    network_mode: host
{% else %}
    networks:
      - {{web_name}}
{% endif %}
    volumes:
{% for volume in nginx_volumes %}
      - {{volume}}
{% endfor %}
    ports:
      - {{web_port_httpd}}:{{web_port_httpd}}
      - {{web_port_httpsd}}:{{web_port_httpsd}}


  {{redis_name}}:
    image: docker.io/redis:latest
{% if (become == true and ansible_become_user == 'root') or ansible_user == 'root' %}
    user: {{uid}}:{{gid}}
{% else %}
    user: root:0
    entrypoint: /tmp/entrypoint.sh
{% endif %}
    image: docker.io/redis:latest
    volumes:
{% for volume in redis_volumes %}
      - {{volume}}
{% endfor %}

{% if debug %}
    network_mode: host
{% else %}
    networks:
      - {{web_name}}
{% endif %}
    tty: true
    container_name: {{redis_name}}
    hostname: {{redis_name}}


  {{web_name}}:
{% if (become == true and ansible_become_user == 'root') or ansible_user == 'root' %}
    user: {{uid}}:{{gid}}
{% else %}
    user: root:0
{% endif %}
    image: ghcr.io/freva-org/freva-web:{{web_version}}
    container_name: {{web_name}}
    hostname: {{web_name}}
{% if debug %}
    network_mode: host
{% else %}
    networks:
      - {{web_name}}
{% endif %}
    environment:
      - EVALUATION_SYSTEM_CONFIG_FILE={{core_root_dir|regex_replace('^~', ansible_env.HOME)}}/freva/evaluation_system.conf
      - DJANGO_SUPERUSER_PASSWORD={{ root_passwd }}
      - ALLOWED_HOSTS={{web_allowed_hosts | join(',')}}
      - FREVA_WEB_CONFIG_FILE={{web_config_file}}
      - SCHEDULER_HOST={{web_scheduler_host | join(',')}}
      - REDIS_HOST={{web_redis_host}}
      - CSRF_TRUSTED_ORIGINS={{web_csrf_trusted_origins | join(',')}}
      - FREVA_BIN={{web_freva_bin}}
      - COLUMNS=140
      - FREVA_REST_URL=http://{{web_freva_rest_host}}
    volumes:
{% for volume in web_volumes %}
      - {{volume}}
{% endfor %}
    tty: true
    ports:
      - 8000:8000
    depends_on:
      - {{redis_name}}
      - {{nginx_name}}

networks:
{% if debug %}
    hostnet:
      driver: host
{% else %}
  {{web_name}}:
    driver: bridge
{% endif %}
