FROM php:8.3-cli-bullseye

# Set environment variables for PHP configuration
ENV UPLOAD_MAX_FILESIZE=100M
ENV POST_MAX_SIZE=100M
ENV MEMORY_LIMIT=256M

# Install system dependencies
RUN apt-get update && apt-get install -y \
    git \
    unzip \
    libzip-dev \
    libicu-dev \
    libpng-dev \
    libjpeg-dev \
    libfreetype6-dev \
    libwebp-dev \
    && docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp \
    && docker-php-ext-install \
        pdo \
        pdo_mysql \
        zip \
        intl \
        gd \
        exif

# Copy Composer
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer

# Create custom php.ini with upload settings
RUN echo "memory_limit = \${MEMORY_LIMIT}" > /usr/local/etc/php/conf.d/uploads.ini && \
    echo "upload_max_filesize = \${UPLOAD_MAX_FILESIZE}" >> /usr/local/etc/php/conf.d/uploads.ini && \
    echo "post_max_size = \${POST_MAX_SIZE}" >> /usr/local/etc/php/conf.d/uploads.ini

# Set working directory
WORKDIR /var/www

# Health check to verify PHP is working
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
    CMD php -v || exit 1

