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.
This commit is contained in:
parent
ce7c7773cd
commit
718dbfcf1b
@ -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 \
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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:*",
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user