-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathDockerfile
More file actions
68 lines (48 loc) · 3.11 KB
/
Copy pathDockerfile
File metadata and controls
68 lines (48 loc) · 3.11 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
# syntax=docker/dockerfile:1
# ─────────────────────────────────────────────
# Stage 0: install the patched package manager used by all stages
# ─────────────────────────────────────────────
FROM node:24.17-alpine AS node-base
RUN npm install --global npm@12.0.1
# ─────────────────────────────────────────────
# Stage 1: install all workspace dependencies
# ─────────────────────────────────────────────
FROM node-base AS deps
WORKDIR /workspace
# Copy every workspace package.json (--parents preserves directory structure)
# so npm workspaces can create the correct symlinks before any source arrives.
COPY --parents package.json package-lock.json apps/*/package.json libs/*/package.json ./
RUN npm ci --ignore-scripts
# ─────────────────────────────────────────────
# Stage 2: build both apps
# ─────────────────────────────────────────────
FROM deps AS builder
# Copy the full monorepo source on top of the installed node_modules
COPY . .
# Build the React SPA → apps/chat/dist/ and overlay sandbox → apps/chat-overlay-sandbox/dist/
# Keep Docker builds deterministic: parallel Nx build/typecheck tasks can race
# while reading and regenerating declaration outputs in a clean image layer.
RUN npm exec -- nx run-many --target=build --projects=@epam/chat,chat-overlay-sandbox --parallel=1
# Build NestJS, generate a pruned package.json/lockfile, and copy
# workspace packages → apps/chat-api/dist/{main.js,package.json,...,workspace_modules/}
RUN npm exec nx run chat-api:prune
# ─────────────────────────────────────────────
# Stage 3: lean production image
# ─────────────────────────────────────────────
FROM node-base AS runner
ENV NODE_ENV=production
WORKDIR /app
# NestJS compiled bundle + pruned manifests + workspace packages
COPY --from=builder /workspace/apps/chat-api/dist ./apps/chat-api/dist
# Install only production dependencies using the pruned lockfile
# (workspace_modules are referenced via file: entries in the pruned package.json)
WORKDIR /app/apps/chat-api/dist
RUN npm ci --omit=dev
# React SPA static files
# static-assets.ts resolves __dirname(dist)/../../chat/dist → /app/apps/chat/dist
COPY --from=builder /workspace/apps/chat/dist /app/apps/chat/dist
# Overlay sandbox static files served by chat-api at /overlay-sandbox when enabled.
COPY --from=builder /workspace/apps/chat-overlay-sandbox/dist /app/apps/chat-overlay-sandbox/dist
WORKDIR /app
EXPOSE 5000
CMD ["node", "apps/chat-api/dist/main.js"]