FROM robinthoni/debian-multiarch:jessie

MAINTAINER Robin Thoni <robin@rthoni.com>

ARG CONFIG_DIR=/etc/default/config-files/

RUN apt-get update && \
    apt-get install -y curl && \
    apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN dist=$(if uname -m | grep -iq arm  ; then echo raspbian; else echo debian; fi) &&\
     echo "deb http://repo.powerdns.com/${dist} jessie-rec-40 main" > /etc/apt/sources.list.d/pdns.list && \
    echo 'Package: pdns-*\nPin: origin repo.powerdns.com\nPin-Priority: 600' > /etc/apt/preferences.d/pdns && \
    curl https://repo.powerdns.com/FD380FBB-pub.asc | apt-key add -

RUN DEBIAN_FRONTEND=noninteractive apt-get update &&\
    apt-get install -y pdns-recursor &&\
    apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN rm -rf /etc/powerdns/*

RUN rm -rf /var/log/*

COPY ./vars-vars /etc/vars-vars

COPY ./vars-files /etc/vars-files

COPY ./common.sh /common.sh

COPY ./run.sh /run.sh

RUN mkdir "${CONFIG_DIR}"

COPY ./config/recursor.conf "${CONFIG_DIR}"/recursor.conf

EXPOSE 53/udp

CMD ["/run.sh"]
