FROM chialab/php:8.2-fpm AS development

LABEL org.opencontainers.image.authors="Mike Mellor <mike.mellor@avalerehealth.com>"

# Install ghostscript
RUN apt-get update && \
    apt-get install -y ghostscript

# Copy custom.ini
COPY ./custom.ini /usr/local/etc/php/conf.d/custom.ini

# Copy ImageMagick policy
COPY ./policy.xml /etc/ImageMagick-6/policy.xml

# Install mysql client for dumps & schema imports in laravel (need to address a mismatch of versions here at some later)
RUN apt-get update && \
    apt-get install -y mariadb-client

# Add php user
RUN useradd -m -G www-data -s /bin/bash php

# Change composer home dir
ENV COMPOSER_HOME=/home/php/.composer

# Cleanup apt-get install folders
RUN apt-get clean && \
    rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

COPY entrypoint.sh /bin/entrypoint.sh
RUN chmod +x /bin/entrypoint.sh
ENTRYPOINT ["/bin/entrypoint.sh"]

CMD ["php-fpm"]

FROM fishawack/lab-env-laravel-9-php:latest AS production

# Copy source code into container
COPY . /app

# Install composer dependencies
RUN TEMPFILE=$(mktemp) && \
    curl -o "$TEMPFILE" "https://getcomposer.org/installer" && \
    php <"$TEMPFILE" && \
    ./composer.phar install -d /app --no-dev --no-interaction --no-ansi --optimize-autoloader