name: billionmail

services:
    pgsql-billionmail:
      image: postgres:17.4-alpine
      hostname: pgsql
      volumes:
        - ./postgresql-data:/var/lib/postgresql/data
        - ./postgresql-socket:/var/run/postgresql
      environment:
        - TZ=${TZ}
        - POSTGRES_DB=${DBNAME}
        - POSTGRES_USER=${DBUSER}
        - POSTGRES_PASSWORD=${DBPASS}
      restart: always
      ports:
        - "${SQL_PORT:-127.0.0.1:25432}:5432"
      networks:
        billionmail-network:
          aliases:
            - pgsql

    redis-billionmail:
      image: redis:7.4.2-alpine
      hostname: redis
      entrypoint: ["/bin/sh","/redis-conf.sh"]
      volumes:
        - ./redis-data:/data
        - ./conf/redis/redis-conf.sh:/redis-conf.sh
      restart: always
      ports:
        - "${REDIS_PORT:-127.0.0.1:26379}:6379"
      environment:
        - TZ=${TZ}
        - REDISPASS=${REDISPASS}
      sysctls:
        - net.core.somaxconn=4096
      networks:
        billionmail-network:
          aliases:
            - redis

    rspamd-billionmail:
      image: billionmail/rspamd:1.1
      hostname: rspamd
      depends_on:
        - redis-billionmail
      environment:
        - TZ=${TZ}
        - REDISPASS=${REDISPASS}
      volumes:
        - ./conf/rspamd/local.d:/etc/rspamd/local.d
        - ./conf/rspamd/statistic.conf:/etc/rspamd/statistic.conf
        - ./conf/rspamd/rspamd.conf:/etc/rspamd/rspamd.conf 
        - ./rspamd-data:/var/lib/rspamd
        - ./logs/rspamd:/var/log/rspamd
      restart: always
      networks:
        billionmail-network:
          aliases:
            - rspamd

    dovecot-billionmail:
      image: billionmail/dovecot:1.4
      hostname: dovecot
      depends_on:
        - pgsql-billionmail
        - redis-billionmail
      cap_add:
        - NET_BIND_SERVICE
      volumes:
        - ./conf/dovecot/conf.d:/etc/dovecot/conf.d
        - ./conf/dovecot/dovecot.conf:/etc/dovecot/dovecot.conf
        - ./conf/dovecot/rsyslog.conf:/etc/rsyslog.conf
        - ./logs/dovecot:/var/log/mail
        - ./ssl:/etc/ssl/mail
        - ./ssl-self-signed:/etc/ssl/ssl-self-signed
        - ./vmail-data:/var/vmail
        - ./rspamd-data:/var/lib/rspamd
        - ./postgresql-socket:/var/run/postgresql
      environment:
        - DBNAME=${DBNAME}
        - DBUSER=${DBUSER}
        - DBPASS=${DBPASS}
        - TZ=${TZ}
        - BILLIONMAIL_HOSTNAME=${BILLIONMAIL_HOSTNAME}
        - REDISPASS=${REDISPASS}
      ports:
        - "${IMAP_PORT:-143}:143"
        - "${IMAPS_PORT:-993}:993"
        - "${POP_PORT:-110}:110"
        - "${POPS_PORT:-995}:995"
      restart: always
      ulimits:
        nproc: 65535
        nofile:
          soft: 20000
          hard: 40000
      networks:
        billionmail-network:
          aliases:
            - dovecot

    postfix-billionmail:
      image: billionmail/postfix:1.5
      hostname: postfix
      depends_on:
        pgsql-billionmail:
          condition: service_started
      volumes:
        - ./conf/postfix/main.cf:/etc/postfix/main.cf
        - ./conf/postfix/master.cf:/etc/postfix/master.cf
        - ./conf/postfix/conf:/etc/postfix/conf
        - ./conf/postfix/sql:/etc/postfix/sql
        - ./conf/postfix/rsyslog.conf:/etc/rsyslog.conf
        - ./logs/postfix:/var/log/mail
        - ./ssl:/etc/ssl/mail
        - ./postfix-data:/var/spool/postfix
        - ./rspamd-data:/var/lib/rspamd
        - ./postgresql-socket:/var/run/postgresql
      environment:
        - TZ=${TZ}
        - DBNAME=${DBNAME}
        - DBUSER=${DBUSER}
        - DBPASS=${DBPASS}
        - REDISPASS=${REDISPASS}
        - BILLIONMAIL_HOSTNAME=${BILLIONMAIL_HOSTNAME}
      cap_add:
        - NET_BIND_SERVICE
      ports:
        - "${SMTP_PORT:-25}:25"
        - "${SMTPS_PORT:-465}:465"
        - "${SUBMISSION_PORT:-587}:587"
      restart: always
      networks:
        billionmail-network:
          aliases:
            - postfix


    webmail-billionmail:
      image: roundcube/roundcubemail:1.6.10-fpm-alpine
      hostname: roundcube
      depends_on:
        - pgsql-billionmail
        - dovecot-billionmail
        - postfix-billionmail
      volumes:
        - ./webmail-data:/var/www/html
        - ./conf/webmail/mime.types:/var/roundcube/config/mime.types
        - ./conf/webmail:/var/roundcube/config
        - ./conf/php:/usr/local/etc
        - ./php-sock/:/var/run/
      environment:
        - TZ=${TZ}
        - ROUNDCUBEMAIL_DB_TYPE=pgsql
        - ROUNDCUBEMAIL_DB_HOST=pgsql
        - ROUNDCUBEMAIL_DB_NAME=${DBNAME}
        - ROUNDCUBEMAIL_DB_USER=${DBUSER}
        - ROUNDCUBEMAIL_DB_PASSWORD=${DBPASS}
        - ROUNDCUBEMAIL_DEFAULT_HOST=dovecot
        - ROUNDCUBEMAIL_DEFAULT_PORT=${IMAP_PORT:-143}
        - ROUNDCUBEMAIL_SMTP_SERVER=postfix
        - ROUNDCUBEMAIL_SMTP_PORT=${SMTP_PORT:-25}
        - ROUNDCUBEMAIL_REQUEST_PATH=/roundcube
      restart: always
      networks:
        billionmail-network:
          aliases:
            - webmail

    core-billionmail:
      image: billionmail/core:4.2.1
      hostname: core-manage
      depends_on:
        - pgsql-billionmail
      volumes:
        - ./ssl:/etc/ssl/mail
        - ./ssl-self-signed:/etc/ssl/ssl-self-signed
        - ./conf/core/fail2ban/filter.d:/etc/fail2ban/filter.d
        - ./conf/core/fail2ban/jail.d:/etc/fail2ban/jail.d
        - ./logs/fail2ban:/var/log/fail2ban
        - ./postgresql-socket:/opt/billionmail/postgresql-socket
        - ./php-sock:/opt/billionmail/php-sock
        - ./rspamd-data:/opt/billionmail/rspamd-data
        - ./webmail-data:/opt/billionmail/webmail-data
        - ./.env:/opt/billionmail/.env
        - ./conf:/opt/billionmail/conf
        - ./logs:/opt/billionmail/logs
        - ./logs/core:/opt/billionmail/core/logs
        - ./core-data:/opt/billionmail/core/data
        - /var/run/docker.sock:/var/run/docker.sock:ro
      environment:
        - TZ=${TZ}
        - FAIL2BAN_INIT=${FAIL2BAN_INIT:-y}
      cap_add:
        - NET_BIND_SERVICE
        - NET_ADMIN
        - NET_RAW
      ports:
        - "${HTTP_PORT:-80}:${HTTP_PORT:-80}"
        - "${HTTPS_PORT:-443}:${HTTPS_PORT:-443}"
      restart: always
      networks:
        billionmail-network:
          aliases:
            - core

networks:
  billionmail-network:
    driver: bridge
    driver_opts:
      com.docker.network.bridge.name: br-billionmail
    ipam:
      driver: default
      config:
        - subnet: ${IPV4_NETWORK:-172.66.1}.0/24

