{% set env='mailu.env' %}
# This file is auto-generated by the Mailu configuration wizard.
# Please read the documentation before attempting any change.

version: '2'

services:

  # External dependencies
  redis:
    image: redis:alpine
    restart: always
    volumes:
      - "$ROOT/redis:/data"

  # Core services
  front:
    image: mailu/nginx:{{ version }}
    restart: always
    env_file: {{ env }}
    env:
      - TLS_FLAVOR={{ tls_flavor or 'letsencrypt' }}
      - ADMIN={{ expose_admin or 'no' }}
    ports:
    {% for port in (80, 443, 25, 465, 587, 110, 995, 143, 993) %}
    {% if bind4 %}
      - "$PUBLIC_IPV4:{{ port }}:{{ port }}"
    {% endif %}
    {% if bind6 %}
      - "$PUBLIC_IPV6:{{ port }}:{{ port }}"
    {% endif %}
    {% endfor %}
    {% if flavor in ('cert', 'mail') %}
    volumes:
      - "$ROOT/certs:/certs"
    {% endif %}

  admin:
    image: mailu/admin:{{ version }}
    restart: always
    env_file: {{ env }}
    {% if not expose_admin %}
    ports:
      - 127.0.0.1:8080:80
    {% endif %}
    volumes:
      - "$ROOT/data:/data"
      - "$ROOT/dkim:/dkim"
    depends_on:
      - redis

  imap:
    image: mailu/dovecot:{{ version }}
    restart: always
    env_file: {{ env }}
    volumes:
      - "$ROOT/data:/data"
      - "$ROOT/mail:/mail"
      - "$ROOT/overrides:/overrides"
    depends_on:
      - front

  smtp:
    image: mailu/postfix:{{ version }}
    restart: always
    env_file: {{ env }}
    volumes:
      - "$ROOT/data:/data"
      - "$ROOT/overrides:/overrides"
    depends_on:
      - front

  # Optional services
  {% if enable_antispam %}
  antispam:
    image: mailu/rspamd:{{ version }}
    restart: always
    env_file: {{ env }}
    volumes:
      - "$ROOT/filter:/var/lib/rspamd"
      - "$ROOT/dkim:/dkim"
      - "$ROOT/overrides/rspamd:/etc/rspamd/override.d"
    depends_on:
      - front
  {% endif %}

  {% if enable_antivirus %}
  antivirus:
    image: mailu/clamav:{{ version }}
    restart: always
    env_file: {{ env }}
    volumes:
      - "$ROOT/filter:/data"
  {% endif %}

  {% if enable_webdav %}
  webdav:
    image: mailu/radivale:{{ version }}
    restart: always
    env_file: {{ env }}
    volumes:
      - "$ROOT/dav:/data"
  {% endif %}

  {% if enable_fetchmail %}
  fetchmail:
    image: mailu/fetchmail:{{ version }}
    restart: always
    env_file: {{ env }}
    volumes:
      - "$ROOT/data:/data"
  {% endif %}

  # Webmail
  {% if enable_webmail %}
  webmail:
    image: mailu/{{ webmail }}:{{ version }}
    restart: always
    env_file: {{ env }}
    volumes:
      - "$ROOT/webmail:/data"
    depends_on:
      - imap
  {% endif %}
