FROM 086679231553.dkr.ecr.us-east-1.amazonaws.com/docker-parent-images:centos7

# Install prerequisite updates and packages
RUN yum -y update
RUN yum -y install epel-release unzip zip

# Install Remi Collet's repo for CentOS 7
RUN yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm

# Install PHP and required extensions
RUN yum -y install --enablerepo=remi,remi-php74 php php-cli php-pdo php-soap php-pecl-zip php-xml php-pecl-ssh2

# Install and secure apache
RUN yum -y install httpd
RUN chmod 600 /etc/httpd/conf/httpd.conf
RUN rm -rf /etc/httpd/conf.d/autoindex.conf
RUN rm -rf /etc/httpd/conf.d/welcome.conf
RUN echo "ServerSignature Off" >> /etc/httpd/conf/httpd.conf
RUN echo "ServerTokens Prod" >> /etc/httpd/conf/httpd.conf
RUN echo "UserDir disabled root" >> /etc/httpd/conf/httpd.conf

# Install Datadog PHP trace agent
RUN yum -y install https://github.com/DataDog/dd-trace-php/releases/download/0.41.1/datadog-php-tracer-0.41.1-1.x86_64.rpm

# Add Composer
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
RUN php -r "if (hash_file('sha384', 'composer-setup.php') === 'dac665fdc30fdd8ec78b38b9800061b4150413ff2e3b6f88543c636f7cd84f6db9189d43a81e5503cda447da73c7e5b6') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
RUN php composer-setup.php
RUN php -r "unlink('composer-setup.php');"
RUN mv composer.phar /usr/local/bin/composer && chmod +x /usr/local/bin/composer

# Configure PHP settings
RUN echo "error_log = stderr" >> /etc/php.ini
RUN echo "error_reporting = E_ALL" >> /etc/php.ini
RUN echo "max_execution_time = 100" >> /etc/php.ini

ENV APP_HOME /var/www/html

# Copy the app into the image
COPY . $APP_HOME

WORKDIR $APP_HOME

# Install app and dependencies
RUN composer install --no-dev
RUN chgrp -R apache $APP_HOME
RUN chown -R apache $APP_HOME/assets
RUN chmod -R 755 $APP_HOME
ADD conf/streams.conf /etc/httpd/conf.d/streams.conf

EXPOSE 80

ENTRYPOINT /var/www/html/entry_point.sh
