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

version: '3.6'

services:

# External dependencies
  redis:
    image: redis:alpine
    volumes:
      - "{{ root }}/redis:/data"

# Core services
  front:
    image: ${DOCKER_ORG:-mailu}/nginx:${MAILU_VERSION:-{{ version }}}
    env_file: {{ env }}
    logging:
      driver: {{ log_driver or 'json-file' }}
    ports:
    {% for port in (80, 443, 25, 465, 587, 110, 995, 143, 993) %}
      - target: {{ port }}
        published: {{ port }}
        mode: overlay
    {% endfor %}
    volumes:
      - "{{ root }}/certs:/certs"
      - "{{ root }}/overrides/nginx:/overrides"
    deploy:
      replicas: {{ front_replicas }}

  {% if resolver_enabled %}
  resolver:
    image: ${DOCKER_ORG:-mailu}/unbound:${MAILU_VERSION:-{{ version }}}
    env_file: {{ env }}
    networks:
      default:
        ipv4_address: {{ dns }}
  {% endif %}

  admin:
    image: ${DOCKER_ORG:-mailu}/admin:${MAILU_VERSION:-{{ version }}}
    env_file: {{ env }}
    {% if not admin_enabled %}
    ports:
      - 127.0.0.1:8080:80
    {% endif %}
    volumes:
      - "{{ root }}/data:/data"
      - "{{ root }}/dkim:/dkim"
    deploy:
      replicas: {{ admin_replicas }}

  imap:
    image: ${DOCKER_ORG:-mailu}/dovecot:${MAILU_VERSION:-{{ version }}}
    env_file: {{ env }}
    volumes:
      - "{{ root }}/mail:/mail"
      - "{{ root }}/overrides:/overrides"
    deploy:
      replicas: {{ imap_replicas }}

  smtp:
    image: ${DOCKER_ORG:-mailu}/postfix:${MAILU_VERSION:-{{ version }}}
    env_file: {{ env }}
    volumes:
      - "{{ root }}/overrides:/overrides"
    deploy:
      replicas: {{ smtp_replicas }}
    {% if resolver_enabled %}
    dns:
      - {{ dns }}
    {% endif %}

  antispam:
    image: ${DOCKER_ORG:-mailu}/rspamd:${MAILU_VERSION:-{{ version }}}
    env_file: {{ env }}
    volumes:
      - "{{ root }}/filter:/var/lib/rspamd"
      - "{{ root }}/dkim:/dkim"
      - "{{ root }}/overrides/rspamd:/etc/rspamd/override.d"
    deploy:
      replicas: 1
    {% if resolver_enabled %}
    dns:
      - {{ dns }}
    {% endif %}

  # Optional services
  {% if antivirus_enabled %}
  antivirus:
    image: ${DOCKER_ORG:-mailu}/clamav:${MAILU_VERSION:-{{ version }}}
    env_file: {{ env }}
    volumes:
      - "{{ root }}/filter:/data"
    deploy:
      replicas: 1
    {% if resolver_enabled %}
    dns:
      - {{ dns }}
    {% endif %}
  {% endif %}

  {% if webdav_enabled %}
  webdav:
    image: ${DOCKER_ORG:-mailu}/none:${MAILU_VERSION:-{{ version }}}
    env_file: {{ env }}
    volumes:
      - "{{ root }}/dav:/data"
    deploy:
      replicas: 1
  {% endif %}

  {% if fetchmail_enabled %}
  fetchmail:
    image: ${DOCKER_ORG:-mailu}/fetchmail:${MAILU_VERSION:-{{ version }}}
    env_file: {{ env }}
    volumes:
      - "{{ root }}/data:/data"
    deploy:
      replicas: 1
    {% if resolver_enabled %}
    dns:
      - {{ dns }}
    {% endif %}
  {% endif %}

  {% if webmail_type != 'none' %}
  webmail:
    image: ${DOCKER_ORG:-mailu}/{{ webmail_type }}:${MAILU_VERSION:-{{ version }}}
    env_file: {{ env }}
    volumes:
      - "{{ root }}/webmail:/data"
    deploy:
      replicas: 1
  {% endif %}

networks:
  default:
    driver: overlay
    ipam:
      driver: default
      config:
        - subnet: {{ subnet }}
