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

  # Core services
  resolver:
{% set service_name = 'resolver' %}
    image: {{ MAILU_DOCKER_FLAVOR }}/unbound:{{ MAILU_VERSION }}
    container_name: {{ MAILU_CONTAINER }}_resolver
{% include 'roles/docker-container/templates/base.yml.j2' %}
{% include 'roles/docker-container/templates/networks.yml.j2' %}
        ipv4_address: {{ MAILU_DNS_RESOLVER }}

  front:
{% set service_name = 'front' %}
    container_name: {{ MAILU_CONTAINER }}_front
    image: {{ MAILU_DOCKER_FLAVOR }}/nginx:{{ MAILU_VERSION }}
{% include 'roles/docker-container/templates/base.yml.j2' %}
    ports:
      - "127.0.0.1:{{ ports.localhost.http[application_id] }}:80"
      - "{{ MAILU_IP4_PUBLIC }}:25:25"
      - "{{ MAILU_IP4_PUBLIC }}:465:465"
      - "{{ MAILU_IP4_PUBLIC }}:587:587"
      - "{{ MAILU_IP4_PUBLIC }}:110:110"
      - "{{ MAILU_IP4_PUBLIC }}:995:995"
      - "{{ MAILU_IP4_PUBLIC }}:143:143"
      - "{{ MAILU_IP4_PUBLIC }}:993:993"
      - "{{ MAILU_IP4_PUBLIC }}:4190:4190"
    volumes:
      - "{{ docker_compose.directories.volumes }}overrides/nginx:/overrides:ro"
      - "{{ cert_mount_directory }}:/certs:ro"
{% include 'roles/docker-container/templates/depends_on/dmbs_incl.yml.j2' %}
      resolver:
        condition: service_started
{% include 'roles/docker-container/templates/networks.yml.j2' %}
      webmail:
      radicale:
    dns:
      - {{ MAILU_DNS_RESOLVER }}
      
  admin:
{% set service_name = 'admin' %}
    container_name: {{ MAILU_CONTAINER }}_admin
    image: {{ MAILU_DOCKER_FLAVOR }}/admin:{{ MAILU_VERSION }}
{% include 'roles/docker-container/templates/base.yml.j2' %}
    volumes:
      - "admin_data:/data"
      - "dkim:/dkim"
{% include 'roles/docker-container/templates/depends_on/dmbs_incl.yml.j2' %}
      resolver:
        condition: service_started
      front:
        condition: service_started
    dns:
      - {{ MAILU_DNS_RESOLVER }}
{% include 'roles/docker-container/templates/networks.yml.j2' %}

  imap:
{% set service_name = 'imap' %}
    container_name: {{ MAILU_CONTAINER }}_imap
    image: {{ MAILU_DOCKER_FLAVOR }}/dovecot:{{ MAILU_VERSION }}
{% include 'roles/docker-container/templates/base.yml.j2' %}
    volumes:
      - "dovecot_mail:/mail"
      - "{{ docker_compose.directories.volumes }}overrides:/overrides:ro"
    depends_on:
      - front
      - resolver
    dns:
      - {{ MAILU_DNS_RESOLVER }}
{% include 'roles/docker-container/templates/networks.yml.j2' %}

  smtp:
{% set service_name = 'smtp' %}
    container_name: {{ MAILU_CONTAINER }}_smtp
    image: {{ MAILU_DOCKER_FLAVOR }}/postfix:{{ MAILU_VERSION }}
{% include 'roles/docker-container/templates/base.yml.j2' %}
    volumes:
      - "{{ docker_compose.directories.volumes }}overrides:/overrides:ro"
      - "smtp_queue:/queue"
    depends_on:
      - front
      - resolver
    dns:
      - {{ MAILU_DNS_RESOLVER }}
{% include 'roles/docker-container/templates/networks.yml.j2' %}

  oletools:
{% set service_name = 'oletools' %}
{% include 'roles/docker-container/templates/base.yml.j2' %}
    container_name: {{ MAILU_CONTAINER }}_oletools
    image: {{ MAILU_DOCKER_FLAVOR }}/oletools:{{ MAILU_VERSION }}
    hostname: oletools
    depends_on:
      - resolver
    dns:
      - {{ MAILU_DNS_RESOLVER }}
{% include 'roles/docker-container/templates/networks.yml.j2' %}
      noinet:

  antispam:
{% set service_name = 'antispam' %}
    container_name: {{ MAILU_CONTAINER }}_antispam
    image: {{ MAILU_DOCKER_FLAVOR }}/rspamd:{{ MAILU_VERSION }}
{% include 'roles/docker-container/templates/base.yml.j2' %}
    volumes:
      - "filter:/var/lib/rspamd"
      - "dkim:/dkim"
      - "{{ MAILU_RSPAMD_HOST_DIR }}:/overrides:ro"
    depends_on:
      - front
      - redis
      - antivirus
      - resolver
    dns:
      - {{ MAILU_DNS_RESOLVER }}
{% include 'roles/docker-container/templates/networks.yml.j2' %}
      noinet:  

  antivirus:
{% set service_name = 'antivirus' %}
    container_name: {{ MAILU_CONTAINER }}_antivirus
    image: clamav/clamav-debian:latest
{% include 'roles/docker-container/templates/base.yml.j2' %}
    volumes:
      - "clamav_db:/var/lib/clamav"
    depends_on:
      - resolver
    dns:
      - {{ MAILU_DNS_RESOLVER }}
{% include 'roles/docker-container/templates/networks.yml.j2' %}

  webdav:
{% set service_name = 'webdav' %}
    container_name: {{ MAILU_CONTAINER }}_webdav
    image: {{ MAILU_DOCKER_FLAVOR }}/radicale:{{ MAILU_VERSION }}
{% include 'roles/docker-container/templates/base.yml.j2' %}
    volumes:
      - "webdav_data:/data"
    depends_on:
      - resolver
    dns:
      - {{ MAILU_DNS_RESOLVER }}
{% include 'roles/docker-container/templates/networks.yml.j2' %}
      radicale:

  fetchmail:
{% set service_name = 'fetchmail' %}
    container_name: {{ MAILU_CONTAINER }}_fetchmail
    image: {{ MAILU_DOCKER_FLAVOR }}/fetchmail:{{ MAILU_VERSION }}
    volumes:
      - "admin_data:/data"
{% include 'roles/docker-container/templates/base.yml.j2' %}
    depends_on:
      - admin
      - smtp
      - imap
      - resolver
    dns:
      - {{ MAILU_DNS_RESOLVER }}
{% include 'roles/docker-container/templates/networks.yml.j2' %}

  webmail:
{% set service_name = 'webmail' %}
    container_name: {{ MAILU_CONTAINER }}_webmail
    image: {{ MAILU_DOCKER_FLAVOR }}/webmail:{{ MAILU_VERSION }}
{% include 'roles/docker-container/templates/base.yml.j2' %}
    volumes:
      - "webmail_data:/data"
      - "{{ docker_compose.directories.volumes }}overrides:/overrides:ro"
    depends_on:
      - imap
      - front
      - resolver
    dns:
      - {{ MAILU_DNS_RESOLVER }}
{% include 'roles/docker-container/templates/networks.yml.j2' %}
      webmail:

{% include 'roles/docker-compose/templates/volumes.yml.j2' %}
  smtp_queue:
    name: {{ MAILU_SMTP_QUEUE_VOLUME }}
  admin_data:
    name: {{ MAILU_ADMIN_DATA_VOLUME }}
  webdav_data:
    name: {{ MAILU_WEBDAV_DATA }}
  webmail_data:
    name: {{ MAILU_WEBMAIL_DATA }}
  filter:
    name: {{ MAILU_FILTER_VOLUME }}
  clamav_db:
    name: {{ MAILU_CLAMAV_VOLUME }}
  dkim:
    name: {{ MAILU_DKIM_VOLUME }}
  dovecot_mail:
    name: {{ MAILU_DOVECOT_MAIL_VOLUME }}

{% include 'roles/docker-compose/templates/networks.yml.j2' %}
  radicale:
    driver: bridge
  webmail:
    driver: bridge
  noinet:
    driver: bridge
    internal: true