FROM php:8.4-fpm

RUN apt-get update && apt-get install -y --no-install-recommends \
    libpq-dev \
    libzip-dev \
    libicu-dev \
    cron \
    && rm -rf /var/lib/apt/lists/* \
    && docker-php-ext-install pdo_pgsql intl \
    && pecl install redis \
    && docker-php-ext-enable redis \
    && groupadd -g 1000 appuser && useradd -u 1000 -g appuser -m appuser

COPY crontab /etc/cron.d/app-crontab
RUN chmod 0644 /etc/cron.d/app-crontab && crontab -u appuser /etc/cron.d/app-crontab

COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

WORKDIR /app

# cron daemon requires root to manage user crontabs, jobs run as appuser
USER root

CMD ["/entrypoint.sh"]
