# vim: ft=yaml.docker-compose
version: "3.8"

services:
  postgres:
    image: postgres:{{ services.mailu.postgres_version }}
    restart: unless-stopped
    environment:
      POSTGRES_DB: mailu
      POSTGRES_USER: mailu
      POSTGRES_PASSWORD: "{{ postgres_passwords.mailu }}"
    volumes:
      - "./postgres:/var/lib/postgresql/data"
    dns:
      - "{{ services.mailu.dns }}"

  redis:
    image: redis:{{ services.mailu.redis_version }}
    restart: unless-stopped
    volumes:
      - "./redis:/data"
    depends_on:
      - resolver
    dns:
      - "{{ services.mailu.dns }}"

  front:
    image: ghcr.io/mailu/nginx:{{ services.mailu.version }}
    restart: unless-stopped
    env_file: mailu.env
    environment:
      VIRTUAL_HOST: "{{ services.mailu.domain }}"
      LETSENCRYPT_HOST: "{{ services.mailu.domain }}"
      LETSENCRYPT_EMAIL: "{{ letsencrypt_email }}"
    volumes:
      - "./certs:/certs"
      - "./overrides/nginx:/overrides:ro"
    expose:
      - "80"
    ports:
      - "25:25"
      - "465:465"
      - "587:587"
      - "110:110"
      - "995:995"
      - "143:143"
      - "993:993"
    networks:
      - default
      - webmail
      - external_services
    depends_on:
      - resolver
    dns:
      - "{{ services.mailu.dns }}"

  resolver:
    image: ghcr.io/mailu/unbound:{{ services.mailu.version }}
    restart: unless-stopped
    env_file: mailu.env
    networks:
      default:
        ipv4_address: "{{ services.mailu.dns }}"

  admin:
    image: ghcr.io/mailu/admin:{{ services.mailu.version }}
    restart: unless-stopped
    env_file: mailu.env
    volumes:
      - "./data:/data"
      - "./dkim:/dkim"
    networks:
      default:
        aliases:
          - admin.mailu
    depends_on:
      - redis
      - resolver
    dns:
      - "{{ services.mailu.dns }}"

  imap:
    image: ghcr.io/mailu/dovecot:{{ services.mailu.version }}
    restart: unless-stopped
    env_file: mailu.env
    volumes:
      - "./mail:/mail"
      - "./overrides/dovecot:/overrides:ro"
    depends_on:
      - front
      - resolver
    dns:
      - "{{ services.mailu.dns }}"

  smtp:
    image: ghcr.io/mailu/postfix:{{ services.mailu.version }}
    restart: unless-stopped
    env_file: mailu.env
    volumes:
      - "./mailqueue:/queue"
      - "./overrides/postfix:/overrides:ro"
    depends_on:
      - front
      - resolver
    dns:
      - "{{ services.mailu.dns }}"


  antispam:
    image: ghcr.io/mailu/rspamd:{{ services.mailu.version }}
    hostname: antispam
    restart: unless-stopped
    env_file: mailu.env
    volumes:
      - "./filter:/var/lib/rspamd"
      - "./overrides/rspamd:/overrides:ro"
    depends_on:
      - front
      - redis
      - resolver
    dns:
      - "{{ services.mailu.dns }}"

  webmail:
    image: ghcr.io/mailu/webmail:{{ services.mailu.version }}
    restart: unless-stopped
    env_file: mailu.env
    volumes:
      - "./webmail:/data"
      - "./overrides/snappymail:/overrides:ro"
    networks:
      - webmail
    depends_on:
      - front

networks:
  default:
    driver: bridge
    ipam:
      driver: default
      config:
        - subnet: "{{ services.mailu.subnet }}"
  webmail:
    driver: bridge
  external_services:
    external: true