fix: add openssl and improve Prisma setup in Docker
This commit is contained in:
29
Dockerfile
29
Dockerfile
@@ -1,34 +1,38 @@
|
||||
# Stage 1: Install dependencies
|
||||
FROM node:20-alpine AS deps
|
||||
RUN apk add --no-cache libc6-compat
|
||||
RUN apk add --no-cache libc6-compat openssl
|
||||
WORKDIR /app
|
||||
|
||||
COPY package.json package-lock.json* ./
|
||||
RUN npm ci
|
||||
|
||||
# Stage 2: Rebuild the source code only when needed
|
||||
# Stage 2: Build
|
||||
FROM node:20-alpine AS builder
|
||||
RUN apk add --no-cache openssl
|
||||
WORKDIR /app
|
||||
COPY --from=deps /app/node_modules ./node_modules
|
||||
COPY . .
|
||||
|
||||
# Generate Prisma client
|
||||
RUN npx prisma generate
|
||||
|
||||
# Build Next.js
|
||||
RUN npm run build
|
||||
|
||||
# Stage 3: Production image
|
||||
# Stage 3: Production
|
||||
FROM node:20-alpine AS runner
|
||||
RUN apk add --no-cache openssl
|
||||
WORKDIR /app
|
||||
|
||||
ENV NODE_ENV=production
|
||||
|
||||
# Install prisma CLI globally (same version as project)
|
||||
RUN npm install -g prisma@6.19.2
|
||||
|
||||
RUN addgroup --system --gid 1001 nodejs
|
||||
RUN adduser --system --uid 1001 nextjs
|
||||
|
||||
# Copy public files
|
||||
COPY --from=builder /app/public ./public
|
||||
|
||||
# Create .next directory
|
||||
RUN mkdir .next
|
||||
RUN chown nextjs:nodejs .next
|
||||
|
||||
@@ -36,12 +40,13 @@ RUN chown nextjs:nodejs .next
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||
|
||||
# Copy Prisma schema and migrations
|
||||
# Copy Prisma files - important for migrations and runtime
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/prisma ./prisma
|
||||
|
||||
# Copy prisma client
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/node_modules/.prisma ./node_modules/.prisma
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/node_modules/@prisma/client ./node_modules/@prisma/client
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/node_modules/@prisma ./node_modules/@prisma
|
||||
|
||||
# Install prisma CLI for migrations (as root before switching user)
|
||||
RUN npm install -g prisma@6.19.2
|
||||
|
||||
USER nextjs
|
||||
|
||||
@@ -50,5 +55,5 @@ EXPOSE 3000
|
||||
ENV PORT=3000
|
||||
ENV HOSTNAME="0.0.0.0"
|
||||
|
||||
# Entrypoint: run migrations then start
|
||||
CMD sh -c "echo 'Running migrations...' && prisma migrate deploy && echo 'Starting server...' && node server.js"
|
||||
# Run migrations and start server
|
||||
CMD sh -c "echo 'Running migrations...' && prisma migrate deploy --schema=./prisma/schema.prisma && echo 'Starting server...' && node server.js"
|
||||
|
||||
Reference in New Issue
Block a user