Following the Prisma guide for GitHub Actions and CI/CD, this commit addresses the Prisma client generation issues in the Docker build process: Changes: 1. **package.json**: - Removed silent failure fallback in postinstall hook - Removed redundant prisma generate from build script - Now fails fast if Prisma generation has issues 2. **docker/web/Dockerfile**: - Added DATABASE_URL environment variable in deps stage - Explicitly run prisma generate after npm install to ensure client is created - Generate Prisma client again in builder stage for build context - Removed --skip-generate flag from prisma db push - Added clear comments explaining each Prisma-related step These changes ensure: - Prisma client is generated with correct engines for debian-openssl-3.0.x - Build fails early if there are Prisma configuration issues - DATABASE_URL is set before running any Prisma commands - Proper multi-stage Docker build with Prisma support
83 lines
2.7 KiB
Docker
83 lines
2.7 KiB
Docker
# syntax=docker/dockerfile:1.6
|
|
|
|
FROM node:25-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++ \
|
|
openssl \
|
|
ca-certificates \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
COPY package.json package-lock.json* ./
|
|
# Copy prisma schema before npm ci so postinstall can generate
|
|
COPY prisma ./prisma
|
|
# Set temporary DATABASE_URL for Prisma CLI
|
|
ENV DATABASE_URL=file:/tmp/dev.db
|
|
# Install dependencies (postinstall will run prisma generate)
|
|
RUN if [ -f package-lock.json ]; then npm ci; else npm install; fi
|
|
# Explicitly verify Prisma client is generated
|
|
RUN npx prisma generate
|
|
|
|
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
|
|
# Install openssl for Prisma query engine
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
openssl \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
COPY --from=deps /app/node_modules ./node_modules
|
|
COPY . .
|
|
# Generate Prisma client (ensures it's available in this stage)
|
|
RUN npx prisma generate
|
|
# Push schema to temporary database for build-time data access
|
|
RUN npx prisma db push
|
|
# Build the Next.js application
|
|
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"]
|