FROM php:8.3-fpm-alpine

# System deps
RUN apk add --no-cache \
    bash \
    icu-libs icu-data-full \
    curl \
    libzip \
    mariadb-client \
  && apk add --no-cache --virtual .build-deps \
    curl-dev \
    icu-dev \
    libzip-dev \
  && docker-php-ext-install \
    pdo \
    pdo_mysql \
    intl \
    curl \
  && apk del .build-deps

WORKDIR /var/www

# Copy app
COPY . /var/www

# PHP-FPM extra pools
COPY docker/php/conf/events.conf /usr/local/etc/php-fpm.d/events.conf

# Writable dirs (create even if you don't use yet)
RUN mkdir -p /var/www/storage/logs \
  && chown -R www-data:www-data /var/www/storage

RUN chmod +x /var/www/docker/scripts/entrypoint.sh \
  && chmod +x /var/www/docker/scripts/init-db.sh \
  && chmod +x /var/www/docker/scripts/wait-for-db.sh

USER www-data

ENTRYPOINT ["/var/www/docker/scripts/entrypoint.sh"]
CMD ["php-fpm", "-F"]
