# ---------------------------- # Stage 1: PHP + Composer # ---------------------------- FROM php:8.4-fpm AS php-base WORKDIR /var/www/html # Install system dependencies and PHP extensions RUN apt-get update && apt-get install -y \ git curl libpng-dev libonig-dev libxml2-dev zip unzip \ && docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd # Install Composer COPY --from=composer:2 /usr/bin/composer /usr/bin/composer # Copy app code COPY . . # Install PHP dependencies (no dev) RUN composer install --no-dev --optimize-autoloader --no-interaction # ---------------------------- # Stage 2: Node build # ---------------------------- FROM node:20 AS frontend WORKDIR /app # Copy only package files and install Node dependencies COPY package*.json ./ RUN npm ci # Copy the rest of the app code COPY . . # Copy vendor from PHP stage (needed if assets reference PHP files) COPY --from=php-base /var/www/html/vendor ./vendor # Build assets RUN npm run build # ---------------------------- # Stage 3: Final production image # ---------------------------- FROM php:8.4-fpm AS final WORKDIR /var/www/html # Install system deps and PHP extensions in the final image RUN apt-get update && apt-get install -y \ git curl libpng-dev libonig-dev libxml2-dev zip unzip \ && docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd # Copy PHP code + vendor COPY --from=php-base /var/www/html . # Copy built frontend assets COPY --from=frontend /app/public ./public # Fix permissions for Laravel RUN chown -R www-data:www-data storage bootstrap/cache CMD ["php-fpm"]