From 0d1d9d5259644b666d93426ddcf0e49afa0c4045 Mon Sep 17 00:00:00 2001 From: PSergio984 Date: Wed, 19 Aug 2026 20:14:10 +0800 Subject: [PATCH] fix(docker): resolve maryui asset build, qr hmac fallback, and imagick runtime support --- .dockerignore | 23 +++++++----- .env.example | 1 + Dockerfile | 72 ++++++++++++++++++++++++++++--------- app/Livewire/ChatWidget.php | 2 +- app/Services/AiService.php | 1 + config/app.php | 4 +-- docker-compose.yml | 1 + resources/css/app.css | 14 +++----- 8 files changed, 81 insertions(+), 37 deletions(-) diff --git a/.dockerignore b/.dockerignore index 201dadb1..0c431d6a 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,14 +1,21 @@ +/node_modules +/public/hot +/public/storage +/storage/*.key +/storage/logs/* +/storage/framework/cache/data/* +/storage/framework/sessions/* +/storage/framework/views/* +/storage/app/ai-corpus/* +/vendor .env .env.* !.env.example -vendor/ -node_modules/ -storage/logs/* -storage/framework/cache/data/* -storage/framework/sessions/* -storage/framework/views/* -storage/app/ai-corpus/* -tests/ +.phpunit.result.cache +Homestead.json +Homestead.yaml +npm-debug.log +yarn-error.log .git/ .github/ docker-compose.yml diff --git a/.env.example b/.env.example index a35e365e..960b5ff9 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,7 @@ APP_NAME=Laravel APP_ENV=local APP_KEY= +QR_HMAC_SECRET= APP_DEBUG=true APP_URL=http://localhost diff --git a/Dockerfile b/Dockerfile index ca33d8d8..41475339 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,35 @@ -# Build stage for assets -FROM node:20-alpine AS builder +# Stage 1: Install Composer dependencies +FROM composer:2 AS vendor -WORKDIR /tmp +WORKDIR /app + +COPY composer.json composer.lock ./ + +RUN composer install \ + --no-dev \ + --no-interaction \ + --no-progress \ + --no-scripts \ + --prefer-dist \ + --optimize-autoloader \ + --ignore-platform-req=ext-gd \ + --ignore-platform-req=ext-imagick + +# Stage 2: Build frontend assets +FROM node:20-alpine AS frontend + +WORKDIR /app COPY package*.json ./ RUN npm ci +# Copy full application and vendor so Tailwind can scan MaryUI and Blade components COPY . . +COPY --from=vendor /app/vendor ./vendor + RUN npm run build -# Production stage +# Stage 3: Production runtime FROM php:8.4-fpm-alpine # Install nginx, supervisor, and system dependencies @@ -22,6 +42,9 @@ RUN apk add --no-cache \ freetype \ libjpeg-turbo \ libpng \ + icu-libs \ + imagemagick \ + imagemagick-libs \ && apk add --no-cache --virtual .build-deps \ $PHPIZE_DEPS \ freetype-dev \ @@ -29,22 +52,39 @@ RUN apk add --no-cache \ libpng-dev \ libzip-dev \ postgresql-dev \ + icu-dev \ + imagemagick-dev \ && docker-php-ext-configure gd --with-freetype --with-jpeg \ && docker-php-ext-install -j$(nproc) \ + bcmath \ gd \ + intl \ + opcache \ + pcntl \ pdo_pgsql \ pgsql \ zip \ + && printf "\n" | pecl install imagick \ + && docker-php-ext-enable imagick \ && apk del .build-deps \ && rm -rf /tmp/pear -# Copy composer from the official composer image -COPY --from=composer:latest /usr/bin/composer /usr/bin/composer +# Copy composer binary +COPY --from=composer:2 /usr/bin/composer /usr/bin/composer WORKDIR /var/www/html +# Copy application source code COPY . /var/www/html -COPY --from=builder /tmp/public/build /var/www/html/public/build + +# Copy vendor dependencies from vendor stage +COPY --from=vendor /app/vendor /var/www/html/vendor + +# Copy compiled frontend assets from frontend stage +COPY --from=frontend /app/public/build /var/www/html/public/build + +# Generate optimized autoload with app classes +RUN composer dump-autoload --optimize --no-dev --working-dir=/var/www/html # Setup configuration COPY Docker/nginx.conf /etc/nginx/http.d/default.conf @@ -55,16 +95,14 @@ COPY Docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf RUN chown -R nginx:nginx /var/www/html/storage /var/www/html/bootstrap/cache \ && chmod +x /var/www/html/Docker/start.sh -RUN composer install --no-dev --no-interaction --optimize-autoloader --working-dir=/var/www/html - -ENV WEBROOT /var/www/html/public -ENV PHP_ERRORS_STDERR 1 -ENV RUN_SCRIPTS 1 -ENV REAL_IP_HEADER 1 -ENV APP_ENV production -ENV APP_DEBUG false -ENV LOG_CHANNEL stderr -ENV COMPOSER_ALLOW_SUPERUSER 1 +ENV WEBROOT=/var/www/html/public +ENV PHP_ERRORS_STDERR=1 +ENV RUN_SCRIPTS=1 +ENV REAL_IP_HEADER=1 +ENV APP_ENV=production +ENV APP_DEBUG=false +ENV LOG_CHANNEL=stderr +ENV COMPOSER_ALLOW_SUPERUSER=1 EXPOSE 80 diff --git a/app/Livewire/ChatWidget.php b/app/Livewire/ChatWidget.php index c8d30f24..582f65a5 100644 --- a/app/Livewire/ChatWidget.php +++ b/app/Livewire/ChatWidget.php @@ -23,7 +23,7 @@ class ChatWidget extends Component /** @var array */ public array $conversations = []; - /** @var array */ + /** @var array|null}> */ public array $messages = []; public string $draft = ''; diff --git a/app/Services/AiService.php b/app/Services/AiService.php index 78b1fa84..1ccec292 100644 --- a/app/Services/AiService.php +++ b/app/Services/AiService.php @@ -75,6 +75,7 @@ public function feedback(string $query, string $rating, ?string $answer = null, return true; } catch (\Throwable $e) { $this->logFailure('/feedback', 'best_effort'); + return false; } } diff --git a/config/app.php b/config/app.php index a9d4610a..e10ef940 100644 --- a/config/app.php +++ b/config/app.php @@ -99,8 +99,8 @@ 'key' => env('APP_KEY'), - // Dedicated secret for QR code HMAC - 'qr_hmac_secret' => env('QR_HMAC_SECRET'), + // Dedicated secret for QR code HMAC (falls back to APP_KEY if not explicitly set) + 'qr_hmac_secret' => env('QR_HMAC_SECRET') ?: env('APP_KEY'), 'previous_keys' => [ ...array_filter( diff --git a/docker-compose.yml b/docker-compose.yml index 04d874ee..0ba6522c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -22,6 +22,7 @@ services: APP_DEBUG: "true" APP_URL: ${APP_URL:-http://localhost} APP_KEY: ${APP_KEY:-} + QR_HMAC_SECRET: ${QR_HMAC_SECRET:-} DB_CONNECTION: pgsql DB_HOST: db DB_PORT: "5432" diff --git a/resources/css/app.css b/resources/css/app.css index 5649a7ee..05c832dc 100644 --- a/resources/css/app.css +++ b/resources/css/app.css @@ -11,21 +11,17 @@ @import '@fontsource/outfit/900.css'; @import 'tailwindcss'; -@plugin "daisyui"; - @plugin "daisyui" { themes: light --default, dark --prefersdark; } -@source "../../vendor/robsontenorio/mary/src/View/Components/**/*.php"; - -@source "../../vendor/laravel/framework/src/Illuminate/Pagination/resources/views/*.blade.php"; -@source "../../storage/framework/views/*.php"; -@source "../**/*.blade.php"; -@source "../**/*.js"; -@source "../**/*.vue"; +@source "../../vendor/robsontenorio/mary"; +@source "../../vendor/laravel/framework/src/Illuminate/Pagination/resources/views"; +@source "../../storage/framework/views"; +@source "../views"; +@source "../js"; /* Dark theme variant support */ @custom-variant dark (&:where(.dark, .dark *));