FROM nginx:stable
LABEL maintainer="antoine@barbare.me"

COPY --chown=www-data nginx.conf /etc/nginx/nginx.conf
COPY --chown=www-data run.sh /

WORKDIR /var/www
RUN apt-get update -y && \
    apt-get install -y \
        wget \
        tar \
        php7.3 \
        php7.3-fpm \
        php7.3-gd \
	php7.3-ldap \
        php7.3-xml && \
    mkdir -p html /var/run/php && \
    echo "cgi.fix_pathinfo = 0;" >> /etc/php/7.3/fpm/php.ini && \
    sed -i -e "s|;daemonize\s*=\s*yes|daemonize = no|g" /etc/php/7.3/fpm/php-fpm.conf && \
    sed -i -e "s|listen\s*=\s*127\.0\.0\.1:9000|listen = /var/run/php-fpm7.sock|g" /etc/php/7.3/fpm/pool.d/www.conf && \
    sed -i -e "s|;listen\.owner\s*=\s*|listen.owner = |g" /etc/php/7.3/fpm/pool.d/www.conf && \
    sed -i -e "s|;listen\.group\s*=\s*|listen.group = |g" /etc/php/7.3/fpm/pool.d/www.conf && \
    sed -i -e "s|;listen\.mode\s*=\s*|listen.mode = |g" /etc/php/7.3/fpm/pool.d/www.conf && \
    wget "https://download.dokuwiki.org/src/dokuwiki/dokuwiki-stable.tgz" && \
    tar -xzf dokuwiki-stable.tgz -C html --strip-components 1 && \
    rm -f dokuwiki-stable.tgz && \
    chown -R www-data . && \
    chmod +x /run.sh && \
    sed -i "s/\${MAXSIZE}/100M/g" /etc/nginx/nginx.conf && \
    apt-get remove wget tar && \
    apt-get clean

EXPOSE 80
VOLUME ["/var/www/html"]

HEALTHCHECK CMD wget -q -O /dev/null http://127.0.0.1:${DOKUWIKI_PORT:=80}/

CMD ["/run.sh"]