FROM php:7.3-apache

ENV LC_ALL=C.UTF-8
ENV DEBIAN_FRONTEND=noninteractive
ENV ACCEPT_EULA=Y
ENV TERM=xterm

RUN apt-get update && apt-get install -y --no-install-recommends apt-utils --no-install-recommends apt-transport-https --no-install-recommends software-properties-common

RUN apt-get update -y && apt-get install -y libpng-dev
RUN apt-get install -y zlib1g-dev curl git iputils-ping libxml2-dev libzip-dev supervisor  unzip vim zip
RUN docker-php-ext-install bcmath ctype json mbstring mysqli pdo pdo_mysql tokenizer xml zip gd

RUN apt-get update && \
    apt-get install -y \
    libfreetype6-dev \
    libwebp-dev \
    libjpeg62-turbo-dev \
    libpng-dev \
    nano \
    libgmp-dev \
    libldap2-dev \
    netcat \
    sqlite3 \
    libsqlite3-dev && \
    docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-webp-dir=/usr/include/  --with-jpeg-dir=/usr/include/ && \
    docker-php-ext-install gd pdo pdo_mysql pdo_sqlite zip gmp bcmath pcntl ldap sysvmsg exif

RUN apt-get update 
RUN apt-get clean -y
RUN apt-get autoclean -y
RUN apt-get autoremove -y

#Install Cron
RUN apt-get update && apt-get -y install cron
COPY build/conf/crontab/all-crons /etc/cron.d/all-crons
RUN chmod 0644 /etc/cron.d/all-crons
RUN crontab /etc/cron.d/all-crons
RUN mkdir -p /var/log/crontab/
RUN touch /var/log/crontab/cron.log

#Add Apache files
COPY build/conf/apache/000-default.conf /etc/apache2/sites-available/000-default.conf
COPY build/conf/apache/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY build/conf/config /config

#Add SSH Key
COPY build/.ssh/ /root/.ssh
COPY build/conf/php/php.ini /usr/local/etc/php/php.ini
COPY build/conf/php/error_reporting.ini /usr/local/etc/php/conf.d/error_reporting.ini
RUN chmod 600 /root/.ssh/authorized_keys
RUN chmod 600 /root/.ssh/id_rsa

#Install Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
ENV COMPOSER_ALLOW_SUPERUSER=1
WORKDIR /var/www/html/
COPY . .
RUN composer install --no-dev --prefer-dist --no-scripts --no-progress --no-suggest

COPY build/conf/docker-php-entrypoint /usr/local/bin/docker-php-entrypoint
RUN chmod +x /usr/local/bin/docker-php-entrypoint
EXPOSE 80
CMD ["apache2-foreground"]
