Files
invyone/docker/deploy/frontend.Dockerfile
T
johngreen 2d938ea45b
Build & Deploy to K8s / build-and-deploy (push) Successful in 4m52s
ci: frontend cache-bust + 진단에 deploy 이미지 표시
빌드 컨텍스트 변경에도 운영 frontend chunk 에 신규 라우트가 들어가지
않는 증상 발견. Kaniko/Docker layer cache 가 npm run build 단계를
잘못된 시점에 hit 하는 것으로 의심. GIT_SHA build-arg 를 npm run build
직전에 주입해 매 commit 마다 그 layer 부터 강제 invalidate.

또 진단 step 에 deploy 이미지 tag 표시 추가 — 새 image 로 갱신
됐는지 즉시 확인 가능.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 12:47:17 +09:00

69 lines
1.8 KiB
Docker

# Multi-stage build for Next.js
FROM dockerhub.wace.me/node:20.19-alpine.linux AS base
# Install dependencies only when needed
FROM base AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app
# Install dependencies
COPY package.json package-lock.json* ./
RUN npm install
# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# Disable telemetry during the build
ENV NEXT_TELEMETRY_DISABLED 1
# 빌드 시 환경변수 설정 (ARG로 받아서 ENV로 설정)
ARG NEXT_PUBLIC_API_URL=https://solution.invyone.com/api
ARG SERVER_API_URL=http://backend-spring.invyone.svc.cluster.local:8081
ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL
ENV SERVER_API_URL=$SERVER_API_URL
# Cache bust — GIT_SHA 가 매 commit 마다 다르므로 이 라인부터 아래 layer 가
# 항상 invalidate 되어 npm run build 가 새 source 로 다시 실행됨.
# (npm install layer 는 위쪽이라 영향 없음 — 빌드 시간 손해 없음.)
ARG GIT_SHA=unknown
ENV GIT_SHA=$GIT_SHA
RUN echo "Build SHA: $GIT_SHA"
# Build the application
ENV DISABLE_ESLINT_PLUGIN=true
RUN npm run build
# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app
ENV NODE_ENV production
ENV NEXT_TELEMETRY_DISABLED 1
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
# Copy the Next.js build output
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
USER nextjs
EXPOSE 3000
ENV PORT 3000
ENV HOSTNAME "0.0.0.0"
# Next.js start 명령어 사용
CMD ["npm", "start"]