perf(CI): frontend build runner stage 를 Next.js standalone output 활용으로 전환

배경:
- 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) <noreply@anthropic.com>
This commit is contained in:
2026-05-13 16:44:36 +09:00
parent b3f955d97d
commit 5fdd1c67b1
+10 -10
View File
@@ -37,7 +37,9 @@ ENV DISABLE_ESLINT_PLUGIN=true
ENV NODE_OPTIONS=--max-old-space-size=4096 ENV NODE_OPTIONS=--max-old-space-size=4096
RUN npm run build 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 FROM base AS runner
WORKDIR /app WORKDIR /app
@@ -47,15 +49,13 @@ ENV NEXT_TELEMETRY_DISABLED 1
RUN addgroup --system --gid 1001 nodejs RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs RUN adduser --system --uid 1001 nextjs
# Copy the Next.js build output # public 폴더 (standalone 가 자동 포함하지 않음)
COPY --from=builder /app/public ./public COPY --from=builder /app/public ./public
# Production 모드에서는 .next 폴더 전체를 복사 # standalone 빌드 결과: server.js + minimal node_modules
COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/package.json ./package.json # static asset (standalone 가 자동 포함하지 않음)
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
# node_modules 복사 (production dependencies)
COPY --from=deps --chown=nextjs:nodejs /app/node_modules ./node_modules
USER nextjs USER nextjs
@@ -64,6 +64,6 @@ EXPOSE 3000
ENV PORT 3000 ENV PORT 3000
ENV HOSTNAME "0.0.0.0" ENV HOSTNAME "0.0.0.0"
# Next.js start 명령어 사용 # standalone 의 server.js 직접 실행 (npm start 대신)
CMD ["npm", "start"] CMD ["node", "server.js"]