From 718dbfcf1b119d96632144bea6a44ddbd460494c Mon Sep 17 00:00:00 2001 From: barsa Date: Thu, 11 Dec 2025 10:44:21 +0900 Subject: [PATCH] Update SHA256 checksums, enhance Dockerfile for Prisma client regeneration, and improve package scripts - Updated SHA256 checksums for the latest backend and frontend tarballs. - Modified the Dockerfile for the BFF application to regenerate the Prisma client in the production layout, ensuring the embedded schema path is correct. - Adjusted package scripts to use `pnpm` consistently for build and analysis commands, improving clarity and consistency across the project. --- apps/bff/Dockerfile | 18 +++++------------- apps/bff/prisma/README.md | 15 ++------------- apps/portal/package.json | 4 ++-- apps/portal/scripts/bundle-monitor.mjs | 2 +- docker/portainer/stack.env.example | 5 +++-- docs/guides/docker-prisma.md | 22 ++++++---------------- docs/portal/PERFORMANCE.md | 8 ++++---- portal-backend.latest.tar.gz.sha256 | 2 +- portal-frontend.latest.tar.gz.sha256 | 2 +- 9 files changed, 25 insertions(+), 53 deletions(-) diff --git a/apps/bff/Dockerfile b/apps/bff/Dockerfile index 69735149..0f37a82e 100644 --- a/apps/bff/Dockerfile +++ b/apps/bff/Dockerfile @@ -60,6 +60,11 @@ RUN pnpm deploy --filter @customer-portal/bff --prod /app/deploy \ && cp -r apps/bff/prisma deploy/prisma \ && cp -r packages/domain/dist deploy/node_modules/@customer-portal/domain/dist +# Regenerate Prisma client in the flattened deploy layout so embedded schema path matches production +WORKDIR /app/deploy +RUN pnpm dlx prisma@${PRISMA_VERSION} generate --schema=prisma/schema.prisma +WORKDIR /app + # ============================================================================= # Stage 3: Production # ============================================================================= @@ -86,19 +91,6 @@ ENV PRISMA_SCHEMA_PATH=/app/prisma/schema.prisma # Copy deploy bundle with correct ownership in single layer COPY --from=builder --chown=nestjs:nodejs /app/deploy ./ -# Regenerate Prisma client for production paths and cleanup -RUN npm install -g prisma@${PRISMA_VERSION} \ - && rm -rf node_modules/.prisma \ - && prisma generate --schema=${PRISMA_SCHEMA_PATH} \ - && mkdir -p /app/node_modules/.prisma \ - # Create symlink for backward compatibility with any hardcoded paths - && mkdir -p /app/apps/bff/prisma \ - && ln -sf /app/prisma/schema.prisma /app/apps/bff/prisma/schema.prisma \ - # Fix ownership - && chown -R nestjs:nodejs /app/node_modules/.prisma /app/apps/bff/prisma \ - # Cleanup npm cache and temp files - && rm -rf /root/.npm /tmp/* /root/.cache - # Copy entrypoint and setup directories COPY --chown=nestjs:nodejs apps/bff/scripts/docker-entrypoint.sh ./docker-entrypoint.sh RUN chmod +x docker-entrypoint.sh \ diff --git a/apps/bff/prisma/README.md b/apps/bff/prisma/README.md index 4f6d16d1..e51c39c7 100644 --- a/apps/bff/prisma/README.md +++ b/apps/bff/prisma/README.md @@ -6,20 +6,9 @@ This directory contains the Prisma schema and migrations for the BFF application ## Important: Docker Build Behavior -### The Problem with Monorepos +### Canonical schema path -Prisma embeds the schema path into the generated client. In a monorepo, this path is relative to the workspace root (e.g., `apps/bff/prisma/schema.prisma`). However, in production Docker containers, the directory structure is flattened by `pnpm deploy`, placing the schema at `prisma/schema.prisma`. - -### How We Solve This - -In the Dockerfile, we regenerate the Prisma client inside the **production directory layout** so the embedded path is `/app/prisma/schema.prisma`: - -```dockerfile -WORKDIR /app -RUN npx prisma@6.16.0 generate --schema=prisma/schema.prisma -``` - -This ensures the embedded schema path matches the production layout. +Prisma embeds the schema path into the generated client. We regenerate the client in Docker using the production layout so the embedded path is `/app/prisma/schema.prisma`. ## Directory Structure diff --git a/apps/portal/package.json b/apps/portal/package.json index 3d5089ec..0f08aee6 100644 --- a/apps/portal/package.json +++ b/apps/portal/package.json @@ -8,14 +8,14 @@ "build": "next build", "build:webpack": "next build --webpack", "build:analyze": "ANALYZE=true next build", - "analyze": "npm run build:analyze", + "analyze": "pnpm run build:analyze", "start": "next start -p ${NEXT_PORT:-3000}", "lint": "eslint .", "lint:fix": "eslint . --fix", "type-check": "tsc --project tsconfig.json --noEmit", "type-check:watch": "tsc --project tsconfig.json --noEmit --watch", "test": "echo 'No tests yet'", - "bundle-analyze": "npm run build:analyze && npx @next/bundle-analyzer" + "bundle-analyze": "pnpm run build:analyze && pnpm exec @next/bundle-analyzer" }, "dependencies": { "@customer-portal/domain": "workspace:*", diff --git a/apps/portal/scripts/bundle-monitor.mjs b/apps/portal/scripts/bundle-monitor.mjs index 387017cf..d96c73bd 100644 --- a/apps/portal/scripts/bundle-monitor.mjs +++ b/apps/portal/scripts/bundle-monitor.mjs @@ -37,7 +37,7 @@ class BundleMonitor { const buildManifest = join(this.buildDir, "build-manifest.json"); if (!existsSync(buildManifest)) { - console.error('Build manifest not found. Run "npm run build" first.'); + console.error('Build manifest not found. Run "pnpm run build" first.'); process.exit(1); } diff --git a/docker/portainer/stack.env.example b/docker/portainer/stack.env.example index 7005a470..a6a80259 100644 --- a/docker/portainer/stack.env.example +++ b/docker/portainer/stack.env.example @@ -8,8 +8,9 @@ # ----------------------------------------------------------------------------- # Images & Ports # ----------------------------------------------------------------------------- -FRONTEND_IMAGE=portal-frontend:latest -BACKEND_IMAGE=portal-backend:latest +FRONTEND_IMAGE=portal-frontend +BACKEND_IMAGE=portal-backend +IMAGE_TAG=latest FRONTEND_PORT=3000 BACKEND_PORT=4000 diff --git a/docs/guides/docker-prisma.md b/docs/guides/docker-prisma.md index 3d41af5e..d4be4968 100644 --- a/docs/guides/docker-prisma.md +++ b/docs/guides/docker-prisma.md @@ -13,7 +13,7 @@ When you run `prisma generate`, Prisma creates a client at `node_modules/.prisma ```javascript // Inside generated client (simplified) const config = { - schemaPath: "apps/bff/prisma/schema.prisma", // ← This path is embedded! + schemaPath: "prisma/schema.prisma", // embedded at generate time // ... } ``` @@ -41,21 +41,11 @@ const config = { ### 3. The Mismatch -The generated Prisma client still contains: -```javascript -schemaPath: "apps/bff/prisma/schema.prisma" -``` - -But in production, the schema is at: +In production, the schema is at: ``` prisma/schema.prisma ``` -This causes errors like: -``` -Error: Could not load `--schema` from provided path `apps/bff/prisma/schema.prisma`: file or directory not found -``` - ## The Solution Regenerate the Prisma client **from the production directory layout** before creating the final image: @@ -63,7 +53,7 @@ Regenerate the Prisma client **from the production directory layout** before cre ```dockerfile # After pnpm deploy creates the bundle at /app (final layout) WORKDIR /app -RUN npx prisma@6.16.0 generate --schema=prisma/schema.prisma +RUN npx prisma@${PRISMA_VERSION} generate --schema=prisma/schema.prisma ``` This regenerates the client with: @@ -79,7 +69,7 @@ Add comments in Dockerfile and schema.prisma explaining why regeneration is need ### 2. Version Lock Prisma Use explicit version in Docker: ```dockerfile -RUN npx prisma@6.16.0 generate --schema=prisma/schema.prisma +RUN npx prisma@${PRISMA_VERSION} generate --schema=prisma/schema.prisma ``` ### 3. Match Prisma Versions @@ -87,10 +77,10 @@ Ensure the version in Docker matches `package.json`: ```json { "dependencies": { - "@prisma/client": "^6.16.0" + "@prisma/client": "7.1.0" }, "devDependencies": { - "prisma": "^6.16.0" + "prisma": "7.1.0" } } ``` diff --git a/docs/portal/PERFORMANCE.md b/docs/portal/PERFORMANCE.md index e4923471..61a8cdf2 100644 --- a/docs/portal/PERFORMANCE.md +++ b/docs/portal/PERFORMANCE.md @@ -32,10 +32,10 @@ Monitor bundle size using the built-in analyzer: ```bash # Analyze bundle size -npm run build:analyze +pnpm run build:analyze # Monitor bundle size with reporting -npm run build:monitor +pnpm run build:monitor ``` ## Performance Monitoring @@ -216,10 +216,10 @@ Regular bundle analysis helps identify optimization opportunities: ```bash # Generate bundle analysis report -npm run build:analyze +pnpm run build:analyze # Monitor bundle size over time -npm run build:monitor +pnpm run build:monitor ``` ## Troubleshooting diff --git a/portal-backend.latest.tar.gz.sha256 b/portal-backend.latest.tar.gz.sha256 index cf79af19..8c22bc14 100644 --- a/portal-backend.latest.tar.gz.sha256 +++ b/portal-backend.latest.tar.gz.sha256 @@ -1 +1 @@ -8c26832b5a788235f2fb461eeeb10a33f34f40830d04fb1235aed449b67ebe1c /home/barsa/projects/customer_portal/customer-portal/portal-backend.latest.tar.gz +8b34bdb6417b9d5edd0cd2e37e6ab96c591bc47bfb0c1f8c0a89e2a970424792 /home/barsa/projects/customer_portal/customer-portal/portal-backend.latest.tar.gz diff --git a/portal-frontend.latest.tar.gz.sha256 b/portal-frontend.latest.tar.gz.sha256 index 2e0a1a49..4d7d6453 100644 --- a/portal-frontend.latest.tar.gz.sha256 +++ b/portal-frontend.latest.tar.gz.sha256 @@ -1 +1 @@ -8b0b76418ba09fc6cb3134db6ac87d350463f88fae6ffae4fd536111d15fa0cf /home/barsa/projects/customer_portal/customer-portal/portal-frontend.latest.tar.gz +8b35fd94746b155255781dd7567a8d1feb4cc45e19b7ad558ce3f988b268b874 /home/barsa/projects/customer_portal/customer-portal/portal-frontend.latest.tar.gz