services:

{% include 'templates/docker/services/redis.yml.j2' %}

{% include 'roles/docker-central-database/templates/services/' + database_type + '.yml.j2' %}

  # Core services
  resolver:
    image: {{docker_source}}/unbound:{{applications.mailu.version}}
{% include 'roles/docker-compose/templates/services/base.yml.j2' %}
{% include 'templates/docker/container/networks.yml.j2' %}
        ipv4_address: {{networks.local.mailu.dns}}

  front:
    image: {{docker_source}}/nginx:{{applications.mailu.version}}
{% include 'roles/docker-compose/templates/services/base.yml.j2' %}
    ports:
      - "127.0.0.1:{{ports.localhost.http[application_id]}}:80"
      - "{{networks.internet.ip4}}:25:25"
      - "{{networks.internet.ip4}}:465:465"
      - "{{networks.internet.ip4}}:587:587"
      - "{{networks.internet.ip4}}:110:110"
      - "{{networks.internet.ip4}}:995:995"
      - "{{networks.internet.ip4}}:143:143"
      - "{{networks.internet.ip4}}:993:993"
      - "{{networks.internet.ip4}}:4190:4190"
    volumes:
      - "{{docker_compose.directories.volumes}}overrides/nginx:/overrides:ro"
      - "{{cert_mount_directory}}:/certs:ro"
{% include 'templates/docker/container/depends-on-also-database.yml.j2' %}
      resolver:
        condition: service_started
{% include 'templates/docker/container/networks.yml.j2' %}
      webmail:
      radicale:
    dns:
      - {{networks.local.mailu.dns}}
      
  admin:
    image: {{docker_source}}/admin:{{applications.mailu.version}}
{% include 'roles/docker-compose/templates/services/base.yml.j2' %}
    volumes:
      - "admin_data:/data"
      - "dkim:/dkim"
{% include 'templates/docker/container/depends-on-database-redis.yml.j2' %}
      resolver:
        condition: service_started
      front:
        condition: service_started
    dns:
      - {{networks.local.mailu.dns}}
{% include 'templates/docker/container/networks.yml.j2' %}

  imap:
    image: {{docker_source}}/dovecot:{{applications.mailu.version}}
{% include 'roles/docker-compose/templates/services/base.yml.j2' %}
    volumes:
      - "dovecot_mail:/mail"
      - "{{docker_compose.directories.volumes}}overrides:/overrides:ro"
    depends_on:
      - front
      - resolver
    dns:
      - {{networks.local.mailu.dns}}
{% include 'templates/docker/container/networks.yml.j2' %}

  smtp:
    image: {{docker_source}}/postfix:{{applications.mailu.version}}
{% include 'roles/docker-compose/templates/services/base.yml.j2' %}
    volumes:
      - "{{docker_compose.directories.volumes}}overrides:/overrides:ro"
      - "smtp_queue:/queue"
    depends_on:
      - front
      - resolver
    dns:
      - {{networks.local.mailu.dns}}
{% include 'templates/docker/container/networks.yml.j2' %}

  oletools:
    image: {{docker_source}}/oletools:{{applications.mailu.version}}
    hostname: oletools
    restart: {{docker_restart_policy}}
    depends_on:
      - resolver
    dns:
      - {{networks.local.mailu.dns}}
{% include 'templates/docker/container/networks.yml.j2' %}
      noinet:

  antispam:
    image: {{docker_source}}/rspamd:{{applications.mailu.version}}
{% include 'roles/docker-compose/templates/services/base.yml.j2' %}
    volumes:
      - "filter:/var/lib/rspamd"
      - "dkim:/dkim"
      - "{{docker_compose.directories.volumes}}overrides/rspamd:/overrides:ro"
    depends_on:
      - front
      - redis 
      - antivirus
      - resolver
    dns:
      - {{networks.local.mailu.dns}}
{% include 'templates/docker/container/networks.yml.j2' %}
      noinet:  


  # Optional services
  antivirus:
    image: clamav/clamav-debian:latest
{% include 'roles/docker-compose/templates/services/base.yml.j2' %}
    volumes:
      - "filter:/data"
    depends_on:
      - resolver
    dns:
      - {{networks.local.mailu.dns}}
{% include 'templates/docker/container/networks.yml.j2' %}

  webdav:
    image: {{docker_source}}/radicale:{{applications.mailu.version}}
{% include 'roles/docker-compose/templates/services/base.yml.j2' %}
    volumes:
      - "webdav_data:/data"
    depends_on:
      - resolver
    dns:
      - {{networks.local.mailu.dns}}
{% include 'templates/docker/container/networks.yml.j2' %}
      radicale:

  fetchmail:
    image: {{docker_source}}/fetchmail:{{applications.mailu.version}}
    volumes:
      - "admin_data:/data"
{% include 'roles/docker-compose/templates/services/base.yml.j2' %}
    depends_on:
      - admin
      - smtp
      - imap
      - resolver
    dns:
      - {{networks.local.mailu.dns}}
{% include 'templates/docker/container/networks.yml.j2' %}

  webmail:
    image: {{docker_source}}/webmail:{{applications.mailu.version}}
{% include 'roles/docker-compose/templates/services/base.yml.j2' %}
    volumes:
      - "webmail_data:/data"
      - "{{docker_compose.directories.volumes}}overrides:/overrides:ro"
    depends_on:
      - imap
      - front
      - resolver
    dns:
      - {{networks.local.mailu.dns}}
{% include 'templates/docker/container/networks.yml.j2' %}
      webmail:

{% include 'templates/docker/compose/volumes.yml.j2' %}
  smtp_queue:
  admin_data:
  webdav_data:
  webmail_data:
  filter:
  dkim:
  dovecot_mail:
  redis:

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