1- # syntax=docker.io/docker/dockerfile:1
2-
3- FROM node:18-alpine AS base
4-
5- # Install dependencies only when needed
6- FROM base AS deps
7- # Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
8- RUN apk add --no-cache libc6-compat
9- WORKDIR /app
10-
11- # Install dependencies based on the preferred package manager
12- COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* .npmrc* ./
13- RUN \
14- if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
15- elif [ -f package-lock.json ]; then npm ci; \
16- elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
17- else echo "Lockfile not found." && exit 1; \
18- fi
19-
20-
21- # Rebuild the source code only when needed
22- FROM base AS builder
23- WORKDIR /app
24- COPY --from=deps /app/node_modules ./node_modules
1+ # use the official Bun image
2+ # see all versions at https://hub.docker.com/r/oven/bun/tags
3+ FROM oven/bun:1 AS base
4+ WORKDIR /usr/src/app
5+
6+ # install dependencies into temp directory
7+ # this will cache them and speed up future builds
8+ FROM base AS install
9+ RUN mkdir -p /temp/dev
10+ COPY package.json bun.lock /temp/dev/
11+ RUN cd /temp/dev && bun install --frozen-lockfile
12+
13+ # install with --production (exclude devDependencies)
14+ RUN mkdir -p /temp/prod
15+ COPY package.json bun.lock /temp/prod/
16+ RUN cd /temp/prod && bun install --frozen-lockfile --production
17+
18+ # copy node_modules from temp directory
19+ # then copy all (non-ignored) project files into the image
20+ FROM base AS prerelease
21+ COPY --from=install /temp/dev/node_modules node_modules
2522COPY . .
2623
27- # Next.js collects completely anonymous telemetry data about general usage.
28- # Learn more here: https://nextjs.org/telemetry
29- # Uncomment the following line in case you want to disable telemetry during the build.
30- # ENV NEXT_TELEMETRY_DISABLED=1
31-
32- RUN \
33- if [ -f yarn.lock ]; then yarn run build; \
34- elif [ -f package-lock.json ]; then npm run build; \
35- elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
36- else echo "Lockfile not found." && exit 1; \
37- fi
38-
39- # Production image, copy all the files and run next
40- FROM base AS runner
41- WORKDIR /app
42-
24+ # [optional] tests & build
4325ENV NODE_ENV=production
44- # Uncomment the following line in case you want to disable telemetry during runtime.
45- # ENV NEXT_TELEMETRY_DISABLED=1
46-
47- RUN addgroup --system --gid 1001 nodejs
48- RUN adduser --system --uid 1001 nextjs
49-
50- COPY --from=builder /app/public ./public
51-
52- # Automatically leverage output traces to reduce image size
53- # https://nextjs.org/docs/advanced-features/output-file-tracing
54- COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
55- COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
56-
57- USER nextjs
58-
59- EXPOSE 3000
60-
61- ENV PORT=3000
62-
63- # server.js is created by next build from the standalone output
64- # https://nextjs.org/docs/pages/api-reference/config/next-config-js/output
65- ENV HOSTNAME="0.0.0.0"
66- CMD ["node" , "server.js" ]
26+ RUN bun test
27+ RUN bun run build
28+
29+ # copy production dependencies and source code into final image
30+ FROM base AS release
31+ COPY --from=install /temp/prod/node_modules node_modules
32+ COPY --from=prerelease /usr/src/app/index.ts .
33+ COPY --from=prerelease /usr/src/app/package.json .
34+
35+ # run the app
36+ USER bun
37+ EXPOSE 3000/tcp
38+ ENTRYPOINT [ "bun" , "run" , "index.ts" ]
0 commit comments