# Multi-stage build for FFR Laravel application FROM node:22-alpine AS frontend-builder WORKDIR /app # Copy frontend package files COPY frontend/package*.json ./ # Install Node dependencies RUN npm ci # Copy frontend source COPY frontend/ ./ # Build frontend assets RUN npm run build # PHP runtime stage FROM php:8.4-fpm-alpine # Install system dependencies RUN apk add --no-cache \ git \ curl \ libpng-dev \ libxml2-dev \ zip \ unzip \ oniguruma-dev \ mysql-client \ nginx \ supervisor \ autoconf \ gcc \ g++ \ make # Install PHP extensions RUN docker-php-ext-install \ pdo_mysql \ mbstring \ exif \ pcntl \ bcmath \ gd \ && pecl install redis \ && docker-php-ext-enable redis # Install Composer COPY --from=composer:latest /usr/bin/composer /usr/bin/composer # Set working directory WORKDIR /var/www/html # Copy application code COPY . . # Install PHP dependencies in backend directory WORKDIR /var/www/html/backend RUN composer install --no-dev --optimize-autoloader --no-interaction # Copy built frontend assets from builder stage to frontend dist COPY --from=frontend-builder /app/dist/ /var/www/html/frontend/dist/ # Back to main directory WORKDIR /var/www/html # 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 /var/www/html \ && chmod -R 755 /var/www/html/backend/storage \ && chmod -R 755 /var/www/html/backend/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 cd /var/www/html/backend && php artisan --version || exit 1 # Start the application CMD ["/usr/local/bin/start-app"]