FROM laravelsail/php84-composer AS build

WORKDIR /var/www/html

COPY . .

RUN apt-get update && apt-get install -y libicu-dev \
    && docker-php-ext-configure intl \
    && docker-php-ext-install intl

RUN composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader

FROM laravelsail/php84-composer

WORKDIR /var/www/html

RUN apt-get update && apt-get install -y \
    libicu-dev \
    libpq-dev \
    libpng-dev \
    libjpeg-dev \
    libfreetype6-dev \
    file \
    && docker-php-ext-configure intl \
    && docker-php-ext-configure gd --with-freetype --with-jpeg \
    && docker-php-ext-install intl pdo_pgsql gd fileinfo \
    && docker-php-ext-enable pdo_pgsql gd fileinfo
COPY --from=build /var/www/html /var/www/html

RUN php artisan storage:link

ENTRYPOINT []

EXPOSE 80

CMD ["sh", "-c", "php artisan migrate --force && php artisan serve --host=0.0.0.0 --port=80"]
