1- # syntax=docker.io/docker/dockerfile:1
2- FROM node:18-alpine AS base
3-
4- # Install dependencies only when needed
5- FROM base AS deps
6- # Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
7- RUN apk add --no-cache libc6-compat
1+ FROM oven/bun:alpine AS base
82WORKDIR /app
93
10- # Install dependencies based on the preferred package manager
11- COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* bun.lockb* bun.lock* .npmrc* source.config.ts next.config.* ./
12- RUN \
13- if [ -f bun.lockb ] || [ -f bun.lock ]; then \
14- apk add --no-cache curl unzip && \
15- curl -fsSL https://bun.sh/install | bash && \
16- /root/.bun/bin/bun install --frozen-lockfile; \
17- elif [ -f yarn.lock ]; then yarn --frozen-lockfile; \
18- elif [ -f package-lock.json ]; then npm ci; \
19- elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
20- else echo "Lockfile not found." && exit 1; \
21- fi
4+ FROM base AS deps
5+ COPY bun.lock package.json ./
6+ RUN bun install --frozen-lockfile
227
23- # Rebuild the source code only when needed
248FROM base AS builder
259WORKDIR /app
10+
2611COPY --from=deps /app/node_modules ./node_modules
27- COPY --from=deps /root/.bun /root/.bun
12+
2813COPY . .
2914
30- # Next.js collects completely anonymous telemetry data about general usage.
31- # Learn more here: https://nextjs.org/telemetry
32- # Uncomment the following line in case you want to disable telemetry during the build.
33- # ENV NEXT_TELEMETRY_DISABLED=1
15+ ENV NEXT_TELEMETRY_DISABLED=1
16+ RUN bun run build
3417
35- RUN \
36- if [ -f bun.lockb ] || [ -f bun.lock ]; then /root/.bun/bin/bun run build; \
37- elif [ -f yarn.lock ]; then yarn run build; \
38- elif [ -f package-lock.json ]; then npm run build; \
39- elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
40- else echo "Lockfile not found." && exit 1; \
41- fi
18+ FROM oven/bun:alpine AS runner
4219
43- # Production image, copy all the files and run next
44- FROM base AS runner
45- WORKDIR /app
20+ RUN addgroup --system --gid 1001 nodejs && \
21+ adduser --system --uid 1001 nextjs
4622
47- ENV NODE_ENV=production
48- # Uncomment the following line in case you want to disable telemetry during runtime.
49- # ENV NEXT_TELEMETRY_DISABLED=1
50-
51- RUN addgroup --system --gid 1001 nodejs
52- RUN adduser --system --uid 1001 nextjs
23+ WORKDIR /app
5324
5425COPY --from=builder /app/public ./public
55-
56- # Automatically leverage output traces to reduce image size
57- # https://nextjs.org/docs/advanced-features/output-file-tracing
58- COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
59- COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
26+ COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
27+ COPY --from=builder --chown=nextjs:nodejs /app/node_modules ./node_modules
28+ COPY --from=builder --chown=nextjs:nodejs /app/package.json ./package.json
6029
6130USER nextjs
6231
6332EXPOSE 8080
33+ ENV NODE_ENV=production
6434ENV PORT=8080
65-
66- # server.js is created by next build from the standalone output
67- # https://nextjs.org/docs/pages/api-reference/config/next-config-js/output
6835ENV HOSTNAME="0.0.0.0"
69- CMD ["node" , "server.js" ]
36+
37+ CMD ["bun" , "run" , "start" ]
0 commit comments