FROM php:8.4-fpm-alpine
WORKDIR /app

RUN apk --no-cache add \
    pcre-dev \
    icu-dev \
    libsodium-dev \
    zlib-dev \
    libpng-dev \
    freetype-dev \
    libjpeg-turbo-dev \
    libzip-dev \
    tzdata \
    libxml2-dev

## Set the timezone to Brazil's timezone
RUN cp /usr/share/zoneinfo/America/Sao_Paulo /etc/localtime && \
  echo "America/Sao_Paulo" > /etc/timezone

## Install libraries and reduce container size
RUN apk --no-cache add postgresql-dev pcre-dev libsodium-dev zlib-dev libpng-dev libzip-dev linux-headers ${PHPIZE_DEPS} \
  && pecl install xdebug \
  && docker-php-ext-enable opcache xdebug \
  && apk del pcre-dev ${PHPIZE_DEPS}

## Copy composer
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer

## Configure extensions
RUN docker-php-ext-install bcmath intl sodium zip gd soap

# Configure pgsql
RUN docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \
    && docker-php-ext-install pdo_pgsql

## Curl certificate
RUN wget https://curl.se/ca/cacert-2023-08-22.pem -O /usr/local/share/ca-certificates/cacert.crt
RUN update-ca-certificates

## Create a first copy of the source code
COPY . /app

## Configure permissions
RUN chown -R www-data:www-data /app/
RUN chmod 755 -R /app/storage/logs /app/storage/framework/sessions /app/storage/framework/cache /app/storage/framework/views
RUN rm -Rf /app/public/storage

EXPOSE 80
