diff --git a/amavis/Dockerfile b/amavis/Dockerfile new file mode 100644 index 0000000..9c7845a --- /dev/null +++ b/amavis/Dockerfile @@ -0,0 +1,31 @@ +FROM ubuntu:14.10 + +ENV DEBIAN_FRONTEND noninteractive +RUN locale-gen en_GB en_GB.UTF-8 && dpkg-reconfigure locales + +# Prerequisites +RUN apt-get update && apt-get install -y \ + amavisd-new \ + spamassassin \ + libnet-dns-perl \ + libmail-spf-perl \ + pyzor \ + razor && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + +# Set up razor and pyzor +RUN su - amavis -s /bin/bash && razor-admin -create && razor-admin -register && pyzor discover + +COPY ./config/amavis-content_filter_mode /etc/amavis/conf.d/15-content_filter_mode + +# Nice place for your settings +VOLUME ["/mail_settings"] + +# Configure boot script +COPY boot / +RUN chmod 755 /boot + +ENV AMAVIS=true + +ENTRYPOINT ./boot; service rsyslog start; amavisd foreground diff --git a/amavis/boot b/amavis/boot new file mode 100644 index 0000000..a9bf588 --- /dev/null +++ b/amavis/boot @@ -0,0 +1 @@ +#!/bin/bash diff --git a/amavis/config/amavis-content_filter_mode b/amavis/config/amavis-content_filter_mode new file mode 100644 index 0000000..e69de29 diff --git a/email_core/Dockerfile b/email_core/Dockerfile index c306ac1..0c4180a 100644 --- a/email_core/Dockerfile +++ b/email_core/Dockerfile @@ -29,12 +29,15 @@ ADD ./config/dovecot.imap /etc/dovecot/conf.d/20-imap.conf # Nice place for your settings VOLUME ["/mail_settings"] -# Configure boot script +# Copy boot scripts COPY boot / RUN chmod 755 /boot +COPY boot.d /boot.d +RUN chmod -R 755 /boot.d # Volume to store email VOLUME ["/vmail"] + # Add user vmail that ownes mail RUN groupadd -g 5000 vmail RUN useradd -g vmail -u 5000 vmail -d /vmail -m diff --git a/email_core/boot b/email_core/boot old mode 100644 new mode 100755 index f63dcf8..f80b4a2 --- a/email_core/boot +++ b/email_core/boot @@ -1,5 +1,6 @@ -# Check if we have SSL certificates in config, otherwise copy it there +#!/bin/bash +# Check if we have SSL certificates in config, otherwise copy it there # First the key file if [ -f /mail_settings/ssl-cert-snakeoil.key ]; then cp /mail_settings/ssl-cert-snakeoil.key /etc/ssl/private/ssl-cert-snakeoil.key @@ -46,20 +47,10 @@ chmod u+w /vmail # Add password file cp /mail_settings/passwords /etc/dovecot/passwd - -# OpenDKIM config -POSTFIX_MAIN_CF=/etc/postfix/main.cf -if [ ! -z "$OPEN_DKIM" ]; then - # Add config block if not present already - if grep -q "# OpenDKIM - dockermail" "$POSTFIX_MAIN_CF"; then - echo "# OpenDKIM - dockermail" >> "$POSTFIX_MAIN_CF" - echo "milter_default_action = accept" >> "$POSTFIX_MAIN_CF" - echo "milter_protocol = 2" >> "$POSTFIX_MAIN_CF" - echo "smtpd_milters = $OPEN_DKIM_PORT_8891_ADDR" >> "$POSTFIX_MAIN_CF" - echo "non_smtpd_milters = $OPEN_DKIM_PORT_8891_ADDR" >> "$POSTFIX_MAIN_CF" - echo "# OpenDKIM - dockermail - end" >> "$POSTFIX_MAIN_CF" - fi -else - # Remove OpenDKIM block - sed '/# OpenDKIM - dockermail/,/# OpenDKIM - dockermail - end/d' "$POSTFIX_MAIN_CF" -fi +# Run boot scripts +for SCRIPT in /boot.d/* +do + if [ -f "$SCRIPT" -a -x "$SCRIPT" ]; then + "$SCRIPT" + fi +done diff --git a/email_core/boot.d/opendkim b/email_core/boot.d/opendkim new file mode 100755 index 0000000..384986c --- /dev/null +++ b/email_core/boot.d/opendkim @@ -0,0 +1,49 @@ +#!/bin/bash +echo 'Running opendkim boot script' + +export DOCKERMAIL_OPENDKIM_ENV_OPEN_DKIM=true +export DOCKERMAIL_OPENDKIM_PORT_8891_TCP_ADDR=172.17.0.10 + +POSTFIX_MAIN_CF=/etc/postfix/main.cf + +env_dump=$(printenv) + +OPENDKIM_CONFIG_HEADER="# OpenDKIM - dockermail - start" +OPENDKIM_CONFIG_FOOTER="# OpenDKIM - dockermail - end" + +function remove_opendkim () { + if grep -q "$OPENDKIM_CONFIG_HEADER" "$POSTFIX_MAIN_CF"; then + sed "/$OPENDKIM_CONFIG_HEADER/,/$OPENDKIM_CONFIG_FOOTER/d" "$POSTFIX_MAIN_CF" + fi +} + +function add_opendkim () { + if ! grep -q "$OPENDKIM_CONFIG_HEADER" "$POSTFIX_MAIN_CF"; then + echo "$OPENDKIM_CONFIG_HEADER" >> "$POSTFIX_MAIN_CF" + + echo "milter_default_action = accept" >> "$POSTFIX_MAIN_CF" + echo "milter_protocol = 2" >> "$POSTFIX_MAIN_CF" + + if [[ $env_dump =~ ^.*PORT_8891_TCP_ADDR=([0-9\.]*) ]] ; then + echo "smtpd_milters = inet:${BASH_REMATCH[1]}:8891" >> "$POSTFIX_MAIN_CF" + echo "non_smtpd_milters = inet:${BASH_REMATCH[1]}:8891" >> "$POSTFIX_MAIN_CF" + fi + + echo "$OPENDKIM_CONFIG_FOOTER" >> "$POSTFIX_MAIN_CF" + else + echo "Warning: $POSTFIX_MAIN_CF already contains OpenDKIM configuration, skipping" + fi +} + +if [[ $env_dump =~ ^(.+OPEN_DKIM)= ]] ; then + if [ ! -z "${BASH_REMATCH[1]}" ]; then + echo "OPEN_DKIM env set, enabling email signing" + remove_opendkim # Remove first, to refresh IP info + add_opendkim + fi +else + echo "Cant find OPEN_DKIM env, signing will be disabled" + remove_opendkim +fi + +echo 'Finished opendkim boot script' diff --git a/opendkim/Dockerfile b/opendkim/Dockerfile index d67261a..dbf8454 100644 --- a/opendkim/Dockerfile +++ b/opendkim/Dockerfile @@ -16,8 +16,8 @@ VOLUME ["/mail_settings"] COPY boot / RUN chmod 755 /boot -ENV OPEN_DKIM true -ENV OPEN_DKIM_PORT_8891_ADDR inet:8891 +ENV OPEN_DKIM=true EXPOSE 8891 -ENTRYPOINT ./boot; service rsyslog start; opendkim -f -p $OPEN_DKIM_PORT_8891_ADDR + +ENTRYPOINT /boot; service rsyslog start; opendkim -f -p inet:8891 diff --git a/opendkim/boot b/opendkim/boot index 9e88114..22b8c8f 100755 --- a/opendkim/boot +++ b/opendkim/boot @@ -1,3 +1,5 @@ +#!/bin/bash + # Copy OpenDKIM config cp /mail_settings/opendkim.conf /etc/opendkim.conf cp /mail_settings/mail.private /etc/dkim.key