From 5fdd1c67b19eb49c4ffba43e2cd138d58cbf9a50 Mon Sep 17 00:00:00 2001 From: johngreen Date: Wed, 13 May 2026 16:44:36 +0900 Subject: [PATCH] =?UTF-8?q?perf(CI):=20frontend=20build=20runner=20stage?= =?UTF-8?q?=20=EB=A5=BC=20Next.js=20standalone=20output=20=ED=99=9C?= =?UTF-8?q?=EC=9A=A9=EC=9C=BC=EB=A1=9C=20=EC=A0=84=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 배경: - frontend build 의 가장 큰 시간 소비 = runner stage 의 COPY node_modules (12분 16초) - 전체 21분 34초 중 57% - next.config.mjs 의 output: "standalone" 가 prod 빌드에서 이미 활성 상태였으나, Dockerfile 의 runner stage 가 .next 통째 + node_modules 통째를 COPY 하느라 standalone 결과물 미활용 조치: - runner stage 재작성: - .next 전체 → .next/standalone (server.js + 실제 사용 node_modules) - .next/static 별도 COPY (standalone 가 자동 포함 안 함) - public 별도 COPY (standalone 가 자동 포함 안 함) - node_modules 통째 COPY 제거 (standalone 가 알아서 포함) - package.json COPY 제거 (server.js 직접 실행) - CMD: npm start → node server.js 검증: - frontend 에 dynamic require/import 0건 (정적 import 만) → standalone 의존성 추적 정확 - prisma 가 package.json 에 있으나 코드 import 0건 → 자연 제외, 추가 설정 불필요 예상 효과: - 빌드 시간 21m 34s → 약 9분 (12분 단축, 57% 감소) - 이미지 크기 약 1GB → 약 300MB (70% 감소) - pull 시간 단축 - runtime memory footprint 감소 Co-Authored-By: Claude Opus 4.7 (1M context) --- docker/deploy/frontend.Dockerfile | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/docker/deploy/frontend.Dockerfile b/docker/deploy/frontend.Dockerfile index 6c0736f5..30f997ad 100644 --- a/docker/deploy/frontend.Dockerfile +++ b/docker/deploy/frontend.Dockerfile @@ -37,7 +37,9 @@ ENV DISABLE_ESLINT_PLUGIN=true ENV NODE_OPTIONS=--max-old-space-size=4096 RUN npm run build -# Production image, copy all the files and run next +# Production image — Next.js standalone output 활용 +# next.config.mjs 의 `output: "standalone"` 이 빌드 시 .next/standalone/ 에 +# server.js + 실제로 사용되는 node_modules 만 자동 포함. node_modules 통째 COPY 불필요. FROM base AS runner WORKDIR /app @@ -47,15 +49,13 @@ ENV NEXT_TELEMETRY_DISABLED 1 RUN addgroup --system --gid 1001 nodejs RUN adduser --system --uid 1001 nextjs -# Copy the Next.js build output +# public 폴더 (standalone 가 자동 포함하지 않음) COPY --from=builder /app/public ./public -# Production 모드에서는 .next 폴더 전체를 복사 -COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next -COPY --from=builder --chown=nextjs:nodejs /app/package.json ./package.json - -# node_modules 복사 (production dependencies) -COPY --from=deps --chown=nextjs:nodejs /app/node_modules ./node_modules +# standalone 빌드 결과: server.js + minimal node_modules +COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ +# static asset (standalone 가 자동 포함하지 않음) +COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static USER nextjs @@ -64,6 +64,6 @@ EXPOSE 3000 ENV PORT 3000 ENV HOSTNAME "0.0.0.0" -# Next.js start 명령어 사용 -CMD ["npm", "start"] +# standalone 의 server.js 직접 실행 (npm start 대신) +CMD ["node", "server.js"]