Modify dockerfile to use bun and production build

This commit is contained in:
2025-12-28 00:20:11 +01:00
parent 78d7afcddb
commit 6eddc7dce1

View File

@ -1,19 +1,46 @@
# Base image # Base image
FROM node:22 FROM oven/bun:1 AS base
# Set working directory # Set working directory
WORKDIR /app WORKDIR /app
# Install dependencies # Install dependencies with bun
COPY package.json package-lock.json ./ FROM base AS deps
RUN npm install 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 the rest of the code
COPY . . RUN bun run build
RUN npx prisma generate
# 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 EXPOSE 3000
# Run dev server CMD ["bun", "./server.js"]
CMD ["npm", "run", "dev"]