# syntax=docker/dockerfile:1
# StreakFit API — Laravel 13 OSDD, runtime Laravel Octane + FrankenPHP.

# ── Stage 1 : dépendances PHP (les couches OSDD sont des packages "path") ─────
FROM composer:2 AS vendor
WORKDIR /app
COPY composer.json composer.lock ./
COPY functional ./functional
COPY technical ./technical
RUN composer install --no-dev --optimize-autoloader --no-interaction --no-scripts --ignore-platform-reqs

# ── Stage 2 : assets Filament (thème/admin) ──────────────────────────────────
# Filament v5 publie ses assets via artisan au runtime ; pas de build vite nécessaire ici.

# ── Stage 3 : runtime (FrankenPHP + Octane) ──────────────────────────────────
FROM dunglas/frankenphp:1-php8.4 AS runtime
RUN install-php-extensions intl gd zip bcmath pdo_mysql exif pcntl opcache

ENV OCTANE_SERVER=frankenphp \
    SERVER_NAME=:80 \
    APP_ENV=production

WORKDIR /app
COPY . .
COPY --from=vendor /app/vendor ./vendor

RUN cp docker/entrypoint.sh /usr/local/bin/entrypoint && chmod +x /usr/local/bin/entrypoint \
    && chown -R www-data:www-data storage bootstrap/cache

EXPOSE 80
ENTRYPOINT ["entrypoint"]
CMD ["php", "artisan", "octane:frankenphp", "--host=0.0.0.0", "--port=80", "--workers=auto", "--max-requests=512"]
