# Multi-stage build for Laravel + Livewire application FROM node:20-alpine AS frontend-builder WORKDIR /app # Copy package files COPY package*.json ./ # Install Node dependencies RUN npm ci # Copy frontend source COPY resources/ resources/ COPY public/ public/ COPY vite.config.ts ./ # Build frontend assets RUN npm run build # PHP runtime stage FROM php:8.3-fpm-alpine # mysql-client backs the database readiness loop in start-app.sh. RUN apk add --no-cache \ curl \ zip \ unzip \ mysql-client \ nginx \ supervisor # Prebuilt binaries rather than docker-php-ext-install: compiling these under # QEMU for the arm64 image dominated the build time. COPY --from=mlocati/php-extension-installer:2 /usr/bin/install-php-extensions /usr/local/bin/ RUN install-php-extensions \ pdo_mysql \ mbstring \ pcntl \ bcmath \ gd # Install Composer COPY --from=composer:2 /usr/bin/composer /usr/bin/composer # Set working directory WORKDIR /var/www/html # Dependencies before the source, so a code change does not reinstall vendor. # --no-scripts because package discovery needs the full application. COPY composer.json composer.lock ./ RUN composer install --no-dev --optimize-autoloader --no-interaction --no-scripts COPY . . # dump-autoload triggers post-autoload-dump, which runs package:discover. RUN composer dump-autoload --optimize --no-interaction # Copy built frontend assets from builder stage COPY --from=frontend-builder /app/public/build/ ./public/build/ # Copy nginx and supervisor configurations COPY docker/production/nginx.conf /etc/nginx/http.d/default.conf COPY docker/production/supervisord.conf /etc/supervisord.conf COPY docker/production/start-app.sh /usr/local/bin/start-app # Set proper permissions RUN chown -R www-data:www-data storage bootstrap/cache public/build \ && chmod -R 755 storage bootstrap/cache \ && chmod +x /usr/local/bin/start-app # Expose port 80 for nginx EXPOSE 80 # Health check HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ CMD php artisan --version || exit 1 # Start the application CMD ["/usr/local/bin/start-app"]