From 912ca8f2fffab1b26f8d42b6b5eb59efb8a87011 Mon Sep 17 00:00:00 2001 From: gunshiz Date: Sun, 9 Aug 2026 22:09:33 +0700 Subject: [PATCH] perf(docker): prune runtime before copy --- Dockerfile | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5887924..90b4fad 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,18 +10,22 @@ RUN --mount=type=cache,target=/root/.bun/install/cache \ bun install --frozen-lockfile # Stage 2: Build the application -FROM oven/bun:1.3.14-alpine AS builder -WORKDIR /app +FROM deps AS builder +ARG TARGETARCH ENV NEXT_TELEMETRY_DISABLED=1 -COPY --from=deps /app/node_modules ./node_modules COPY . . # Build Next.js RUN --mount=type=cache,target=/app/.next/cache \ bun run build +# The standalone tracer includes both glibc and musl Sharp packages. Alpine only +# needs musl, so prune the incompatible copy before it enters a runtime layer. +RUN rm -rf \ + ".next/standalone/node_modules/@img/sharp-linux-${TARGETARCH}" \ + ".next/standalone/node_modules/@img/sharp-libvips-linux-${TARGETARCH}" + # Stage 3: Production runner FROM oven/bun:1.3.14-alpine AS runner -ARG TARGETARCH WORKDIR /app ENV NODE_ENV=production ENV NEXT_TELEMETRY_DISABLED=1 @@ -33,12 +37,6 @@ COPY --from=builder /app/.next/standalone ./ COPY --from=builder /app/public ./public COPY --from=builder /app/.next/static ./.next/static -# The standalone tracer includes both glibc and musl Sharp packages. Alpine only -# needs musl, so discard the incompatible duplicate without touching runtime deps. -RUN rm -rf \ - "./node_modules/@img/sharp-linux-${TARGETARCH}" \ - "./node_modules/@img/sharp-libvips-linux-${TARGETARCH}" - EXPOSE 3000 CMD ["bun", "server.js"]