From d26c7db9be8005dcd5d76cfdc3978c235d6c2c43 Mon Sep 17 00:00:00 2001 From: Citali Date: Sun, 28 Dec 2025 00:20:01 +0100 Subject: [PATCH] Modify dockerfile to use bun and production build --- Dockerfile | 45 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7e39c2c..d0e0517 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,46 @@ # Base image -FROM node:22 +FROM oven/bun:1 AS base # Set working directory WORKDIR /app -# Install dependencies -COPY package.json package-lock.json ./ -RUN npm install +# Install dependencies with bun +FROM base AS deps +COPY package.json bun.lock* ./ +RUN bun install --no-save --frozen-lockfile + +# Rebuild the source code only when needed +FROM base AS builder +WORKDIR /app +COPY --from=deps /app/node_modules ./node_modules +COPY . . +RUN bunx prisma generate + +# Uncomment the following line in case you want to disable telemetry during the build. +ENV NEXT_TELEMETRY_DISABLED=1 # Copy the rest of the code -COPY . . -RUN npx prisma generate +RUN bun run build + +# Production image, copy all the files and run next +FROM base AS runner +WORKDIR /app + +ENV NEXT_TELEMETRY_DISABLED=1 + +ENV NODE_ENV=production \ + PORT=3000 \ + HOSTNAME="0.0.0.0" + +RUN groupadd --system --gid 1001 nodejs && \ + useradd --system --uid 1001 --no-log-init -g nodejs nextjs + +COPY --from=builder /app/public ./public +COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ +COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static + +USER nextjs -# Expose the dev port EXPOSE 3000 -# Run dev server -CMD ["npm", "run", "dev"] +CMD ["bun", "./server.js"]