-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
97 lines (71 loc) · 3.03 KB
/
Dockerfile
File metadata and controls
97 lines (71 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# ============================================================
# Stage 1: Pruning - 필요한 워크스페이스만 추출
# ============================================================
FROM node:22-alpine AS pruner
WORKDIR /app
# Turbo 설치
RUN npm install -g turbo@2.6.0
# 전체 모노레포 복사 (prune 실행 위해)
COPY . .
# asset-transform과 의존성만 추출
RUN turbo prune --scope=asset-transform --docker
# ============================================================
# Stage 2: Builder - 의존성 설치 및 빌드
# ============================================================
FROM node:22-alpine AS builder
WORKDIR /app
# Sentry 릴리스 버전 및 인증 토큰 설정
ARG SENTRY_RELEASE=development
ARG SENTRY_AUTH_TOKEN
ENV SENTRY_RELEASE=$SENTRY_RELEASE
# pnpm 설치
RUN npm install -g pnpm
# FFmpeg 설치 (비디오/오디오 변환용)
RUN apk add --no-cache ffmpeg
# 1️⃣ 의존성 메타데이터만 복사 (캐싱 최적화)
COPY --from=pruner /app/out/json/ ./
# 2️⃣ 의존성 설치 (소스 변경 시 재실행되지 않음)
RUN pnpm install --frozen-lockfile
# 3️⃣ 전체 소스 코드 복사
COPY --from=pruner /app/out/full/ ./
# 4️⃣ 애플리케이션 빌드
RUN npx turbo@2.6.0 run build --filter=asset-transform
# 5️⃣ Sentry 소스맵 업로드 (토큰이 있는 경우에만)
RUN if [ -n "$SENTRY_AUTH_TOKEN" ]; then \
pnpm --filter=asset-transform sentry:sourcemaps; \
else \
echo "⚠️ Sentry 소스맵 업로드 건너뜀 (SENTRY_AUTH_TOKEN 없음)"; \
fi
# ============================================================
# Stage 3: Runner - 프로덕션 이미지
# ============================================================
FROM node:22-alpine AS runner
WORKDIR /app
# 프로덕션 환경 설정
ENV NODE_ENV=production
# PM2와 pnpm 설치
RUN npm install -g pm2 pnpm
# FFmpeg 설치 (비디오/오디오 변환용 - 런타임에 필요)
RUN apk add --no-cache ffmpeg
# 로그 디렉터리 생성
RUN mkdir -p /app/apps/asset-transform/logs
# Sentry 릴리스 버전을 런타임에 전달
ARG SENTRY_RELEASE=development
ENV SENTRY_RELEASE=$SENTRY_RELEASE
# 필요한 파일만 복사
COPY --from=builder /app/package.json /app/pnpm-lock.yaml /app/pnpm-workspace.yaml ./
COPY --from=builder /app/apps/asset-transform/package.json ./apps/asset-transform/
COPY --from=builder /app/apps/asset-transform/tsconfig.json ./apps/asset-transform/tsconfig.json
COPY --from=builder /app/apps/asset-transform/dist ./apps/asset-transform/dist
COPY --from=builder /app/packages ./packages
COPY --from=builder /app/turbo.json ./turbo.json
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/apps/asset-transform/node_modules ./apps/asset-transform/node_modules
# PM2 ecosystem 설정 파일 복사
COPY apps/asset-transform/ecosystem.config.js ./apps/asset-transform/
# 실행 포트 설정
EXPOSE 80
# 작업 디렉터리를 asset-transform으로 변경
WORKDIR /app/apps/asset-transform
# PM2로 클러스터 모드 실행
CMD ["pm2-runtime", "start", "ecosystem.config.js"]