name: billionmail

services:
  core-billionmail:
    image: billionmail/core:4.7.11
    container_name: ${CONTAINER_NAME}
    hostname: billionmail-core-manage
    volumes:
      - ${CORE_DATA_PATH}/ssl:/etc/ssl/mail
      - ${CORE_DATA_PATH}/ssl-self-signed:/etc/ssl/ssl-self-signed
      - ${CORE_DATA_PATH}/conf/core/fail2ban/filter.d:/etc/fail2ban/filter.d
      - ${CORE_DATA_PATH}/conf/core/fail2ban/jail.d:/etc/fail2ban/jail.d
      - ${CORE_DATA_PATH}/logs/fail2ban:/var/log/fail2ban
      - ${CORE_DATA_PATH}/postgresql-socket:/opt/billionmail/postgresql-socket
      - ${CORE_DATA_PATH}/php-sock:/opt/billionmail/php-sock
      - ${CORE_DATA_PATH}/rspamd-data:/opt/billionmail/rspamd-data
      - ${CORE_DATA_PATH}/webmail-data:/opt/billionmail/webmail-data
      - ${CORE_DATA_PATH}/.env:/opt/billionmail/.env
      - ${CORE_DATA_PATH}/conf:/opt/billionmail/conf
      - ${CORE_DATA_PATH}/logs:/opt/billionmail/logs
      - ${CORE_DATA_PATH}/logs/core:/opt/billionmail/core/logs
      - ${CORE_DATA_PATH}/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
      - ${HTTPS_PORT}:443
    restart: always
    networks:
      - 1panel-network

  rspamd-billionmail:
    image: billionmail/rspamd:1.2
    container_name: ${CONTAINER_NAME}-rspamd
    hostname: billionmail-rspamd
    environment:
      - TZ=${TZ}
      - REDISPASS=${REDISPASS}
      - RETENTION_DAYS=${RETENTION_DAYS:-7}
    volumes:
      - ${RSPAMD_DATA_PATH}/conf/rspamd/local.d:/etc/rspamd/local.d
      - ${RSPAMD_DATA_PATH}/conf/rspamd/statistic.conf:/etc/rspamd/statistic.conf
      - ${RSPAMD_DATA_PATH}/conf/rspamd/rspamd.conf:/etc/rspamd/rspamd.conf 
      - ${RSPAMD_DATA_PATH}/rspamd-data:/var/lib/rspamd
      - ${RSPAMD_DATA_PATH}/logs/rspamd:/var/log/rspamd
    restart: always
    networks:
      - 1panel-network

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

  postfix-billionmail:
    image: billionmail/postfix:1.6
    container_name: ${CONTAINER_NAME}-postfix
    hostname: billionmail-postfix
    volumes:
      - ${POSTFIX_DATA_PATH}/conf/postfix/main.cf:/etc/postfix/main.cf
      - ${POSTFIX_DATA_PATH}/conf/postfix/master.cf:/etc/postfix/master.cf
      - ${POSTFIX_DATA_PATH}/conf/postfix/conf:/etc/postfix/conf
      - ${POSTFIX_DATA_PATH}/conf/postfix/sql:/etc/postfix/sql
      - ${POSTFIX_DATA_PATH}/conf/postfix/rsyslog.conf:/etc/rsyslog.conf
      - ${POSTFIX_DATA_PATH}/logs/postfix:/var/log/mail
      - ${POSTFIX_DATA_PATH}/ssl:/etc/ssl/mail
      - ${POSTFIX_DATA_PATH}/postfix-data:/var/spool/postfix
      - ${POSTFIX_DATA_PATH}/rspamd-data:/var/lib/rspamd
      - ${POSTFIX_DATA_PATH}/postgresql-socket:/var/run/postgresql
    environment:
      - TZ=${TZ}
      - DBNAME=${DBNAME}
      - DBUSER=${DBUSER}
      - DBPASS=${DBPASS}
      - REDISPASS=${REDISPASS}
      - BILLIONMAIL_HOSTNAME=${BILLIONMAIL_HOSTNAME}
      - RETENTION_DAYS=${RETENTION_DAYS:-7}
    cap_add:
      - NET_BIND_SERVICE
    ports:
      - "${SMTP_PORT}:25"
      - "${SMTPS_PORT}:465"
      - "${SUBMISSION_PORT}:587"
    restart: always
    networks:
      - 1panel-network

  webmail-billionmail:
    image: roundcube/roundcubemail:1.6.11-fpm-alpine
    container_name: ${CONTAINER_NAME}-roundcube
    hostname: billionmail-roundcube
    depends_on:
      - dovecot-billionmail
      - postfix-billionmail
    volumes:
      - ${ROUNDCUBE_DATA_PATH}/webmail-data:/var/www/html
      - ${ROUNDCUBE_DATA_PATH}/conf/webmail/mime.types:/var/roundcube/config/mime.types
      - ${ROUNDCUBE_DATA_PATH}/conf/webmail:/var/roundcube/config
      - ${ROUNDCUBE_DATA_PATH}/conf/php:/usr/local/etc
      - ${ROUNDCUBE_DATA_PATH}/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}
      - ROUNDCUBEMAIL_SMTP_SERVER=postfix
      - ROUNDCUBEMAIL_SMTP_PORT=${SMTP_PORT}
      - ROUNDCUBEMAIL_REQUEST_PATH=/roundcube
    restart: always
    networks:
      - 1panel-network

networks:
  1panel-network:
    external: true