FROM node:20-alpine AS base # Install dependencies only when needed FROM base AS deps RUN apk add --no-cache libc6-compat openssl WORKDIR /app COPY package.json package-lock.json* ./ RUN npm install # Rebuild the source code only when needed FROM base AS builder WORKDIR /app COPY --from=deps /app/node_modules ./node_modules COPY . . # Generate Prisma Client (with SQLite) ENV DATABASE_URL="file:/app/data/dev.db" RUN npx prisma generate # Disable telemetry during build ENV NEXT_TELEMETRY_DISABLED=1 RUN npm run build # Production image, copy all the files and run next FROM base AS runner WORKDIR /app ENV NODE_ENV=production ENV NEXT_TELEMETRY_DISABLED=1 ENV DATABASE_URL="file:/app/data/dev.db" RUN addgroup --system --gid 1001 nodejs RUN adduser --system --uid 1001 nextjs # Create data directory for SQLite and set permissions RUN mkdir -p /app/data && chown nextjs:nodejs /app/data COPY --from=builder /app/public ./public # Set the correct permission for prerender cache RUN mkdir .next RUN chown nextjs:nodejs .next # Automatically leverage output traces to reduce image size 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/prisma ./prisma COPY --from=deps --chown=nextjs:nodejs /app/node_modules ./node_modules USER nextjs EXPOSE 3000 ENV PORT=3000 # script to run migrations before starting COPY --chown=nextjs:nodejs <