FROM php:8.4-fpm-alpine

RUN apk add --no-cache nginx curl zip unzip git postgresql-dev nodejs npm dcron \
    && docker-php-ext-install pdo pdo_pgsql pgsql opcache pcntl

RUN docker-php-ext-install bcmath
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

WORKDIR /var/www

COPY . .

RUN composer install --no-dev --optimize-autoloader

RUN npm install && npm run build && rm -f public/hot

COPY docker/nginx.conf /etc/nginx/nginx.conf

RUN chown -R www-data:www-data /var/www/storage /var/www/bootstrap/cache

RUN echo "* * * * * cd /var/www && php artisan schedule:run" \
    > /etc/crontabs/root

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

EXPOSE 80

CMD ["/entrypoint.sh"]
