FROM ubuntu:xenial
MAINTAINER Andre Peters <andre.peters@debinux.de>

ENV DEBIAN_FRONTEND noninteractive
ENV LC_ALL C

RUN dpkg-divert --local --rename --add /sbin/initctl \
    && ln -sf /bin/true /sbin/initctl \
    && dpkg-divert --local --rename --add /usr/bin/ischroot \
    && ln -sf /bin/true /usr/bin/ischroot

RUN apt-key adv --fetch-keys http://rspamd.com/apt-stable/gpg.key \
    && echo "deb http://rspamd.com/apt-stable/ xenial main" > /etc/apt/sources.list.d/rspamd.list \
    && apt-get update \
    && apt-get -y install rspamd ca-certificates python-pip coreutils

RUN echo '.include $LOCAL_CONFDIR/local.d/rspamd.conf.local' > /etc/rspamd/rspamd.conf.local

ADD settings.conf /etc/rspamd/modules.d/settings.conf
ADD antivirus.conf /etc/rspamd/modules.d/antivirus.conf
ADD wait-for-it.sh /wait-for-it.sh

RUN pip install -U oletools
RUN timeout 30 /usr/bin/rspamd -f -u _rspamd -g _rspamd; exit 0
RUN chmod +x /wait-for-it.sh

CMD ["/wait-for-it.sh", "nginx:8081", "--", "/usr/bin/rspamd", "-f", "-u", "_rspamd", "-g", "_rspamd"]

RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

USER _rspamd

EXPOSE 11333 11334
