Fix prisma CLI in production container for db push
Use a separate Docker stage to install prisma CLI + all transitive deps, then merge into the runner's node_modules with correct ownership. Verified: prisma --version works inside the container. Made-with: Cursor
This commit is contained in:
parent
3b8d580ded
commit
f174bd9977
2 changed files with 9 additions and 4 deletions
11
Dockerfile
11
Dockerfile
|
|
@ -18,6 +18,11 @@ COPY . .
|
|||
ENV NEXT_TELEMETRY_DISABLED=1
|
||||
RUN npx prisma generate && npm run build
|
||||
|
||||
# Standalone prisma install for runtime db push
|
||||
FROM base AS prisma-cli
|
||||
WORKDIR /tmp/prisma
|
||||
RUN npm init -y > /dev/null 2>&1 && npm install --ignore-scripts prisma dotenv @prisma/adapter-pg 2>/dev/null
|
||||
|
||||
FROM base AS runner
|
||||
WORKDIR /app
|
||||
|
||||
|
|
@ -32,11 +37,11 @@ COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
|||
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||
COPY --from=builder /app/prisma ./prisma
|
||||
COPY --from=builder /app/prisma.config.ts ./prisma.config.ts
|
||||
COPY --from=builder /app/node_modules/prisma ./node_modules/prisma
|
||||
COPY --from=builder /app/node_modules/@prisma ./node_modules/@prisma
|
||||
COPY --from=builder /app/node_modules/dotenv ./node_modules/dotenv
|
||||
COPY --from=builder /app/start.sh ./start.sh
|
||||
|
||||
# Merge prisma CLI + deps into node_modules (alongside standalone deps)
|
||||
COPY --chown=nextjs:nodejs --from=prisma-cli /tmp/prisma/node_modules ./node_modules
|
||||
|
||||
RUN mkdir -p /data/watch && chown -R nextjs:nodejs /data
|
||||
|
||||
USER nextjs
|
||||
|
|
|
|||
2
start.sh
2
start.sh
|
|
@ -2,7 +2,7 @@
|
|||
set -e
|
||||
|
||||
echo "Running database migrations..."
|
||||
npx prisma db push --skip-generate 2>&1 || echo "Warning: prisma db push failed, tables may already exist"
|
||||
node node_modules/prisma/build/index.js db push --skip-generate 2>&1 || echo "Warning: prisma db push failed, tables may already exist"
|
||||
|
||||
echo "Starting server..."
|
||||
exec node server.js
|
||||
|
|
|
|||
Loading…
Reference in a new issue