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
RUN apt-get purge -y php*
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

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

#install Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
ENV COMPOSER_ALLOW_SUPERUSER=1
WORKDIR /var/www/html/

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

COPY build/conf/apache/000-default.conf /etc/apache2/sites-available/000-default.conf
COPY build/conf/config /config
COPY build/conf/php/php.ini /usr/local/etc/php/php.ini


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

COPY build/.ssh/ /root/.ssh/
RUN chmod 600 /root/.ssh/authorized_keys
RUN chmod 600 /root/.ssh/id_rsa
COPY . .
ENV COMPOSER_MEMORY_LIMIT=-1
RUN composer install --no-dev --prefer-dist --no-scripts --no-progress

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"]
