diff --git a/Dockerfile b/Dockerfile index 0b4b9e8..bfcd01e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,6 @@ FROM node:20-alpine AS deps RUN apk add --no-cache libc6-compat WORKDIR /app -# Install dependencies based on the preferred package manager COPY package.json package-lock.json* ./ RUN npm ci @@ -16,19 +15,20 @@ COPY . . RUN npx prisma generate RUN npm run build -# Stage 3: Production image, copy all the files and run next +# Stage 3: Production image FROM node:20-alpine AS runner WORKDIR /app -ENV NODE_ENV production +ENV NODE_ENV=production + +# Install prisma CLI globally for migrations +RUN npm install -g prisma RUN addgroup --system --gid 1001 nodejs RUN adduser --system --uid 1001 nextjs -# Copy public folder COPY --from=builder /app/public ./public -# Set the correct permission for prerender cache RUN mkdir .next RUN chown nextjs:nodejs .next @@ -36,32 +36,19 @@ 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 files for migrations (as root before switching user) -COPY --from=builder /app/prisma ./prisma -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/prisma ./node_modules/prisma +# Copy Prisma schema and migrations +COPY --from=builder --chown=nextjs:nodejs /app/prisma ./prisma -# Fix permissions for prisma folder -RUN chown -R nextjs:nodejs ./prisma ./node_modules/.prisma ./node_modules/@prisma ./node_modules/prisma - -# Create entrypoint script -COPY <