FROM paheko/paheko:1.3.18-php8.4

ENV PAHEKO_DIR /var/www/paheko

COPY dockers/paheko/config/factory_cron.sh ${PAHEKO_DIR}/
COPY dockers/paheko/config/factory_cron_emails.sh ${PAHEKO_DIR}/
COPY dockers/paheko/config/setupWebRights.sh ${PAHEKO_DIR}/
RUN mkdir ${PAHEKO_DIR}/users

#pour corriger le bug "export excel"
RUN docker-php-ext-install calendar

RUN apt-get update
RUN apt-get install -y libwebp-dev
RUN docker-php-ext-configure gd --with-jpeg --with-freetype --with-webp
RUN docker-php-ext-install gd

#Plugin facturation (le seul qui ne fasse pas parti de la distribution de base
RUN apt-get install unzip
COPY "dockers/paheko/config/facturation.zip" ${PAHEKO_DIR}/data/plugins/
WORKDIR ${PAHEKO_DIR}/data/plugins/
RUN unzip ${PAHEKO_DIR}/data/plugins/facturation.zip
WORKDIR /

#RUN mkdir ${PAHEKO_DIR}/data/plugins/facturation && tar zxvf ${PAHEKO_DIR}/data/plugins/facturation.tar.gz -C ${PAHEKO_DIR}/data/plugins/facturation && rm ${PAHEKO_DIR}/data/plugins/facturation.tar.gz

#install cron pour factory_cron.sh
RUN apt-get install cron joe rsyslog -y
RUN sed -i '/imklog/s/^/#/' /etc/rsyslog.conf
RUN echo "0 1 * * * cd ${PAHEKO_DIR} && ${PAHEKO_DIR}/factory_cron.sh 1> /dev/null 2> /dev/null" >> /var/spool/cron/crontabs/www-data
RUN echo "* * * * *  cd ${PAHEKO_DIR} && ${PAHEKO_DIR}/factory_cron_emails.sh 1> /dev/null 2> /dev/null" >> /var/spool/cron/crontabs/www-data
RUN chmod 600 /var/spool/cron/crontabs/www-data
RUN chown www-data:www-data /var/spool/cron/crontabs/www-data
RUN sed -i "/exec/i\service cron start\n" /usr/local/bin/docker-php-entrypoint
RUN ln -sf /usr/local/bin/php /usr/bin/

#outil pour debugger dans le docker
RUN apt-get install -y inetutils-ping net-tools

# Set owner web server
RUN chown -R www-data: ${PAHEKO_DIR}

#fab le 03/02/2023: pour avoir un php.ini de prod avec zend.assertions = -1
RUN cp "/usr/local/etc/php/php.ini-production" "/usr/local/etc/php/php.ini"

HEALTHCHECK --timeout=10s CMD exit 0
EXPOSE 80
VOLUME [ "${PAHEKO_DIR}/users" ]
