Following Prisma's official documentation for deployment caching issues: https://www.prisma.io/docs/orm/more/help-and-troubleshooting/vercel-caching-issue Changes: - Add 'prisma generate' to build script (official Prisma recommendation) - Add postinstall script for automatic client generation - Remove custom stub generator workaround - Keep runtime Prisma client generation in entrypoint.sh for reliability - Add openssl to runtime container (required for Prisma engines) This follows Prisma best practices: explicitly run prisma generate during the build process to ensure Prisma Client is always up-to-date. The entrypoint script regenerates the client at runtime to guarantee engine availability in the production environment.
68 lines
2.2 KiB
Docker
68 lines
2.2 KiB
Docker
# syntax=docker/dockerfile:1.6
|
|
|
|
FROM node:20-slim AS base
|
|
WORKDIR /app
|
|
|
|
FROM base AS deps
|
|
# Install build dependencies for native modules like better-sqlite3
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
python3 \
|
|
make \
|
|
g++ \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
COPY package.json package-lock.json* ./
|
|
RUN if [ -f package-lock.json ]; then npm ci; else npm install; fi
|
|
|
|
FROM base AS builder
|
|
ENV NODE_ENV=production
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
# Set a temporary database path for build
|
|
ENV DATABASE_PATH=/tmp/build.db
|
|
ENV DATABASE_URL=file:/tmp/build.db
|
|
COPY --from=deps /app/node_modules ./node_modules
|
|
COPY . .
|
|
# Build the application (includes prisma generate as per Prisma best practices)
|
|
# Real Prisma client will be regenerated at runtime to ensure engine availability
|
|
RUN npx prisma db push --skip-generate
|
|
RUN npm run build && rm -f /tmp/build.db
|
|
|
|
FROM base AS runner
|
|
ENV NODE_ENV=production
|
|
ENV PORT=3000
|
|
WORKDIR /app
|
|
|
|
# Install gosu for privilege dropping and openssl for Prisma
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
gosu \
|
|
openssl \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
RUN groupadd -g 1001 nodejs && useradd -r -u 1001 -g nodejs nextjs
|
|
|
|
COPY --from=builder /app/public ./public
|
|
COPY --from=builder /app/.next/standalone ./
|
|
COPY --from=builder /app/.next/static ./.next/static
|
|
COPY --from=builder /app/package.json ./package.json
|
|
|
|
# Copy instrumentation file and all required chunks for server startup initialization
|
|
COPY --from=builder /app/.next/server/instrumentation.js ./.next/server/instrumentation.js
|
|
COPY --from=builder /app/.next/server/instrumentation ./.next/server/instrumentation
|
|
COPY --from=builder /app/.next/server/chunks/ ./.next/server/chunks/
|
|
|
|
# Copy Prisma client
|
|
COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma
|
|
COPY --from=builder /app/node_modules/@prisma ./node_modules/@prisma
|
|
COPY --from=builder /app/prisma ./prisma
|
|
|
|
# Create data directory for SQLite database
|
|
RUN mkdir -p /app/data && chown -R nextjs:nodejs /app/data
|
|
|
|
# Copy entrypoint script
|
|
COPY docker/web/entrypoint.sh /entrypoint.sh
|
|
RUN chmod +x /entrypoint.sh
|
|
|
|
EXPOSE 3000
|
|
|
|
# Run as root so entrypoint can fix permissions, then switch to nextjs
|
|
ENTRYPOINT ["/entrypoint.sh"]
|