# Multi-stage build for Laravel with React frontend FROM node:22-alpine AS frontend-builder WORKDIR /app COPY package*.json ./ RUN npm install --only=production COPY . . RUN npm run build FROM php:8.4-fpm-alpine # Install system dependencies and PHP extensions RUN apk add --no-cache \ git \ curl \ libpng-dev \ oniguruma-dev \ libxml2-dev \ zip \ unzip \ && docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd # Install Composer COPY --from=composer:latest /usr/bin/composer /usr/bin/composer # Set working directory WORKDIR /var/www/html # Copy composer files COPY composer*.json ./ # Copy application files (needed for artisan in composer scripts) COPY . . # Install dependencies RUN composer install --no-dev --optimize-autoloader --no-interaction # Copy production environment file and generate APP_KEY COPY docker/.env.production .env RUN php artisan key:generate # Copy built frontend assets COPY --from=frontend-builder /app/public/build /var/www/html/public/build # Set permissions RUN chown -R www-data:www-data /var/www/html \ && chmod -R 755 /var/www/html/storage \ && chmod -R 755 /var/www/html/bootstrap/cache # Create entrypoint script COPY docker/entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh EXPOSE 8000 ENTRYPOINT ["/entrypoint.sh"] CMD ["web"]