FROM dunglas/frankenphp:1-php8.4-bookworm

WORKDIR /app

# Install extensions Symfony commonly needs now,
# plus MariaDB support for the next phase.
RUN install-php-extensions \
    intl \
    opcache \
    pdo_mysql \
    zip

# Copy Composer from its official image.
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer

# Copy dependency definitions first.
# This allows Docker to cache composer install between builds.
COPY composer.json composer.lock symfony.lock ./

ENV APP_ENV=prod
ENV APP_DEBUG=0
ENV SERVER_NAME=:8080

RUN composer install \
    --no-dev \
    --prefer-dist \
    --no-interaction \
    --no-progress \
    --no-scripts

# Copy the rest of the Symfony project.
COPY . .

# Run Symfony/Flex scripts now that the complete project exists.
RUN composer run-script post-install-cmd \
    && mkdir -p var/cache var/log \
    && chown -R www-data:www-data var


COPY entrypoint.sh /usr/local/bin/entrypoint
RUN chmod +x /usr/local/bin/entrypoint

ENTRYPOINT ["entrypoint"]

CMD ["frankenphp", "run", "--config", "/etc/caddy/Caddyfile"]
EXPOSE 8080
