FROM php:8.4-fpm-alpine

RUN apk add --no-cache \
    curl \
    git \
    zip \
    unzip \
    libzip-dev \
    imagemagick \
    libreoffice \
    libreoffice-lang-de \
    ghostscript \
    poppler-utils \
    sqlite \
    sqlite-dev \
    postgresql-client \
    mysql-client \
    nodejs \
    npm \
    fcgi

RUN docker-php-ext-install \
    pdo_sqlite \
    pdo_mysql \
    zip \
    bcmath

COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

WORKDIR /app

COPY build/fpm-healthcheck.conf /usr/local/etc/php-fpm.d/zz-healthcheck.conf
COPY build/php-error-logging.conf /usr/local/etc/php-fpm.d/zz-error-logging.conf
COPY build/php-errors.ini /usr/local/etc/php/conf.d/errors.ini
COPY build/entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh

EXPOSE 9000

HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
    CMD SCRIPT_NAME=/ping SCRIPT_FILENAME=/ping REQUEST_METHOD=GET cgi-fcgi -bind -connect 127.0.0.1:9000 | grep -q pong || exit 1

ENTRYPOINT ["entrypoint.sh"]
CMD ["php-fpm"]
