fix: simplify Dockerfile with correct OpenSSL 3 setup for Debian 12
This commit is contained in:
parent
1e4600f21e
commit
fab371228a
@ -1,42 +1,32 @@
|
|||||||
# Multi-stage build for Next.js 16 with Webpack (not Turbopack)
|
# Multi-stage build for Next.js 16 with Webpack + Prisma
|
||||||
# Using Debian Slim for better Prisma compatibility
|
# Using Debian Slim for OpenSSL 3.x compatibility
|
||||||
|
|
||||||
FROM node:22-slim AS base
|
FROM node:22-slim AS base
|
||||||
# Install dependencies only when needed
|
|
||||||
FROM base AS deps
|
FROM base AS deps
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Install system dependencies for Prisma and sharp
|
# Install OpenSSL (already 3.x in Debian Slim)
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
openssl \
|
openssl \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Install dependencies based on the preferred package manager
|
# Install dependencies
|
||||||
COPY package.json package-lock.json* ./
|
COPY package.json package-lock.json* ./
|
||||||
RUN npm install --legacy-peer-deps
|
RUN npm install --legacy-peer-deps
|
||||||
|
|
||||||
# Rebuild the source code only when needed
|
|
||||||
FROM base AS builder
|
FROM base AS builder
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY --from=deps /app/node_modules ./node_modules
|
COPY --from=deps /app/node_modules ./node_modules
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Generate Prisma Client before build
|
# Generate Prisma Client (will use debian-openssl-3.0.x from schema)
|
||||||
RUN npx prisma generate
|
RUN npx prisma generate
|
||||||
|
|
||||||
# Build Next.js with Webpack (not Turbopack) to avoid Tailwind CSS issues
|
# Build Next.js with Webpack
|
||||||
ENV NEXT_TELEMETRY_DISABLED=1
|
ENV NEXT_TELEMETRY_DISABLED=1
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
# Ensure Prisma binaries are in all search locations
|
|
||||||
RUN mkdir -p /app/prisma/client-generated && \
|
|
||||||
cp -r node_modules/.prisma/client/* /app/prisma/client-generated/ && \
|
|
||||||
mkdir -p /app/.prisma/client && \
|
|
||||||
cp -r node_modules/.prisma/client/* /app/.prisma/client/ && \
|
|
||||||
mkdir -p /app/.next/server && \
|
|
||||||
cp -r node_modules/@prisma/engines/*.node /app/.next/server/ 2>/dev/null || true
|
|
||||||
|
|
||||||
# Production image, copy all the files and run next
|
|
||||||
FROM base AS runner
|
FROM base AS runner
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
@ -48,18 +38,15 @@ RUN adduser --system --uid 1001 nextjs
|
|||||||
|
|
||||||
COPY --from=builder /app/public ./public
|
COPY --from=builder /app/public ./public
|
||||||
|
|
||||||
# Set the correct permission for prerender cache
|
|
||||||
RUN mkdir .next
|
RUN mkdir .next
|
||||||
RUN chown nextjs:nodejs .next
|
RUN chown nextjs:nodejs .next
|
||||||
|
|
||||||
# Automatically leverage output traces to reduce image size
|
# Copy Next.js standalone output
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/server ./.next/server
|
|
||||||
|
|
||||||
# Copy Prisma for runtime - ALL locations including the generated client AND engines
|
# Copy Prisma files - including generated binaries
|
||||||
COPY --from=builder /app/prisma ./prisma
|
COPY --from=builder /app/prisma ./prisma
|
||||||
COPY --from=builder /app/.prisma ./.prisma
|
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/node_modules/.prisma ./node_modules/.prisma
|
COPY --from=builder --chown=nextjs:nodejs /app/node_modules/.prisma ./node_modules/.prisma
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/node_modules/@prisma ./node_modules/@prisma
|
COPY --from=builder --chown=nextjs:nodejs /app/node_modules/@prisma ./node_modules/@prisma
|
||||||
|
|
||||||
@ -70,5 +57,4 @@ EXPOSE 3000
|
|||||||
ENV PORT=3000
|
ENV PORT=3000
|
||||||
ENV HOSTNAME="0.0.0.0"
|
ENV HOSTNAME="0.0.0.0"
|
||||||
|
|
||||||
# server.js is created by next build from the standalone output
|
|
||||||
CMD ["node", "server.js"]
|
CMD ["node", "server.js"]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user