# FrankenPHP bundles Caddy + PHP into one process and serves plain HTTP,
# so the edge Caddy can reverse_proxy to it like any other service —
# no FastCGI / shared document-root wiring needed. Official arm64 builds
# exist, which matters since the target is a Raspberry Pi 4.
FROM dunglas/frankenphp:php8.3-alpine

RUN apk add --no-cache icu-dev oniguruma-dev libzip-dev $PHPIZE_DEPS \
    && install-php-extensions pdo_mysql zip intl mbstring redis opcache \
    && apk del $PHPIZE_DEPS

COPY infrastructure/docker/php.ini /usr/local/etc/php/conf.d/99-nas.ini

COPY --from=composer:2 /usr/bin/composer /usr/bin/composer

WORKDIR /app

COPY backend/composer.json backend/composer.lock ./
RUN composer install --no-dev --no-scripts --no-autoloader --prefer-dist

COPY backend/. .
RUN composer dump-autoload --optimize

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

ENV SERVER_NAME=:8000
EXPOSE 8000

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