{% include 'roles/docker-compose/templates/base.yml.j2' %}

  application:
    image: "{{ nextcloud_image }}:{{ nextcloud_version }}"
    container_name: {{ nextcloud_container }}
    volumes:
      - data:{{nextcloud_docker_work_directory}}
      - {{nextcloud_host_config_additives_directory}}:{{nextcloud_docker_config_additives_directory}}:ro
    healthcheck:
      test: ["CMD", "su", "www-data", "-s", "/bin/sh", "-c", "php {{nextcloud_docker_work_directory}}occ status"]
      interval: 1m
      timeout: 10s
      retries: 3
{% include 'roles/docker-container/templates/base.yml.j2' %}
{% include 'roles/docker-container/templates/depends_on/dmbs_excl.yml.j2' %}
{% include 'roles/docker-container/templates/networks.yml.j2' %}
        ipv4_address: 192.168.102.69

{% if nextcloud_talk_enabled %}
  talk:
    {% include 'roles/docker-container/templates/base.yml.j2' %}
    image: "{{ nextcloud_talk_image }}:{{ nextcloud_talk_version }}"
    container_name: {{ nextcloud_talk_name }}
    hostname: hpb_yt
    init: true
    ports:
      - {{ networks.internet.ip4 }}:{{ nextcloud_talk_stun_port }}:3478/tcp #TURN TCP
      - {{ networks.internet.ip4 }}:{{ nextcloud_talk_stun_port }}:3478/udp #TURN UDP
      - {{ networks.internet.ip4 }}:8181:8081/tcp                           #Signaling @todo needs to be optimized
    networks:
      default:
        ipv4_address: 192.168.102.68
{% endif %}

  proxy:
    image: "{{ nextcloud_proxy_image }}:{{ nextcloud_proxy_version }}"
    container_name: "{{ nextcloud_proxy_name }}"
    logging:
      driver: journald
    restart: {{ DOCKER_RESTART_POLICY }}
    ports:
      - "127.0.0.1:{{ports.localhost.http[application_id]}}:{{ container_port }}"
    volumes:
        - "{{ docker_compose.directories.volumes }}nginx.conf:/etc/nginx/nginx.conf:ro"
    volumes_from:
      - application

{% include 'roles/docker-container/templates/healthcheck/curl.yml.j2' %}
    networks:
      default:
        ipv4_address: 192.168.102.67

  cron:
    container_name: "{{ nextcloud_cron_name }}"
    image: "{{ nextcloud_image }}:{{ nextcloud_version }}"
    restart: {{ DOCKER_RESTART_POLICY }}
    logging:
      driver: journald
    volumes:
      - data:{{nextcloud_docker_work_directory}}
    entrypoint: /cron.sh
    healthcheck:
      test: ["CMD", "su", "www-data", "-s", "/bin/sh", "-c", "php {{nextcloud_docker_work_directory}}occ status"]
      interval: 1m
      timeout: 10s
      retries: 3
{% include 'roles/docker-container/templates/depends_on/dmbs_excl.yml.j2' %}
{% include 'roles/docker-container/templates/networks.yml.j2' %}
        ipv4_address: 192.168.102.70

{% include 'roles/docker-compose/templates/volumes.yml.j2' %}
  data:
    name: {{ nextcloud_volume }}

{% include 'roles/docker-compose/templates/networks.yml.j2' %}
