FROM robinthoni/debian-multiarch:jessie

# FROM https://github.com/ZHAJOR/Docker-Apache-2.4-Php-5.6-for-Laravel
MAINTAINER Robin Thoni <robin@rthoni.com>

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

RUN apt-get update && apt-get -y install\
        apache2=2.4.*\
        libapache2-mod-php5\
        php5\
        php5-mcrypt\
        php5-pgsql\
        php5-mysql\
        php5-gd\
        php5-curl\
        php5-imap &&\
        apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN /usr/sbin/a2enmod rewrite &&\
    rm -rf /var/www/html &&\
    mkdir -p /var/lock/apache2 /var/run/apache2 /var/log/apache2 /var/www/html &&\
    chown -R www-data:www-data /var/lock/apache2 /var/run/apache2 /var/log/apache2 /var/www/html

RUN rm -rf /var/log/* &&\
    mkdir -p /var/log/apache2 &&\
    ln -s /dev/stderr /var/log/apache2/error.log &&\
    ln -s /dev/stdout /var/log/apache2/access.log &&\
    ln -s /dev/stdout /var/log/apache2/other_vhosts_access.log

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-auth-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 -

COPY ./preseed.txt /tmp/preseed.txt

RUN debconf-set-selections /tmp/preseed.txt

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

RUN rm -rf /etc/powerdns/*

COPY apache2.conf /etc/apache2/apache2.conf

COPY ./poweradmin-2.1.8/ /var/www/html/

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 ./poweradmin-2.1.7/inc/config.inc.php "${CONFIG_DIR}"/config.inc.php

COPY ./pdns.conf "${CONFIG_DIR}"/pdns.conf

EXPOSE 80

CMD ["/run.sh"]
