FROM robinthoni/debian-multiarch:jessie AS builder

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

RUN apt-get update && apt-get -y install \
        git \
        curl && \
        apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/ && \
        curl https://deb.nodesource.com/setup_10.x | bash && \
        ln -s /usr/bin/nodejs /usr/bin/node

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

RUN npm install -g @angular/cli

COPY ./SiteStatus/ /tmp/frontend

RUN cd /tmp/frontend && \
    rm -rf node_modules dist && \
    npm install && \
    ng build && \
    mkdir -p /var/www/ && \
    cp -r /tmp/frontend/dist/SiteStatus/ /var/www/html && \
    rm -rf /tmp/frontend

FROM robinthoni/debian-multiarch:jessie

RUN apt-get update && apt-get -y install \
        apache2=2.4.* && \
        apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/

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 &&\
    /usr/sbin/a2enmod rewrite proxy_http proxy_wstunnel &&\
    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

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

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

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

COPY ./run.sh /run.sh

COPY --from=builder /var/www/html /var/www/html

EXPOSE 80

CMD ["/run.sh"]