FROM php:7.2-fpm

# https://codereviewvideos.com/course/docker-tutorial-for-beginners/video/docker-php-7-tutorial-7-7-1-and-higher

RUN usermod -u 1000 www-data
RUN groupmod -g 1000 www-data

RUN apt-get update \
    && apt-get install -y --no-install-recommends \
        cron \
        nginx \
        curl \
        git \
        libicu-dev \
        libz-dev \
        libpq-dev \
        libjpeg-dev \
        libpng-dev \
        libfreetype6-dev \
        libssl-dev \
        libxml2-dev \
        libbz2-dev \
        libjpeg62-turbo-dev \
        supervisor \
        unzip \
        zip \
    && php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer \
    && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN docker-php-ext-configure bcmath --enable-bcmath \
    && docker-php-ext-configure pcntl --enable-pcntl \
    && docker-php-ext-configure pdo_mysql --with-pdo-mysql \
    && docker-php-ext-configure soap --enable-soap \
    && docker-php-ext-install \
        bcmath \
        intl \
        mysqli \
        pdo_mysql \
        pcntl \
        soap \
        sockets \
        zip \
    && docker-php-ext-configure gd \
        --enable-gd-native-ttf \
        --with-jpeg-dir=/usr/lib \
        --with-freetype-dir=/usr/include/freetype2 && \
        docker-php-ext-install gd \
    && docker-php-ext-install opcache \
    && docker-php-ext-enable opcache

ADD cronjob /etc/cron.d/cronjob
RUN chmod 0644 /etc/cron.d/cronjob
RUN crontab /etc/cron.d/cronjob

COPY nginx.conf /etc/nginx/nginx.conf
#RUN echo 'www-data ALL=(ALL:ALL) NOPASSWD:/usr/sbin/service nginx configtest,/usr/sbin/service nginx reload' >> /etc/sudoers
EXPOSE 80 443

COPY supervisord.conf /etc/supervisor/supervisord.conf

CMD ["/usr/bin/supervisord"]