FROM php:8.3-apache-bookworm AS base
RUN a2enmod rewrite
RUN apt update && apt install -y \
    cron \
    curl \
    git \
    libzip-dev \
    unzip \
    libpng-dev \
    libwebp-dev \
    libjpeg62-turbo-dev \
    libxmp-dev \
    libfreetype6-dev \
    libpq-dev \
    libicu-dev \
    ffmpeg \
    ;
RUN docker-php-ext-configure gd \
    --with-webp \
    --with-jpeg \
    --with-freetype
RUN docker-php-ext-install gd zip pgsql intl
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

FROM base AS with-cronjob
COPY --chmod=644 ./crontab /tmp/crontab.tmp
RUN crontab /tmp/crontab.tmp && \
    rm -f /tmp/crontab.tmp
RUN touch /var/log/cron.log && \
    touch /var/log/jobs.log && \
    touch /var/log/job-errors.log

FROM with-cronjob AS with-scripts
COPY --chmod=700 ./entrypoint.sh /entrypoint.sh
COPY --chmod=700 ./with-env /with-env

FROM with-scripts AS dev
CMD ["/entrypoint.sh"]
COPY ./000-default.conf /etc/apache2/sites-available/000-default.conf
WORKDIR /var/www/html

FROM dev AS prod
COPY ./src /var/www/html
RUN composer install