File size: 1,067 Bytes
e3eb984
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Multi-stage build for ChatApp

# ----- Build Stage -----
FROM node:18 AS builder
WORKDIR /app

# Install root dependencies and workspaces
COPY package.json package-lock.json* ./
COPY client/package.json ./client/package.json
COPY server/package.json ./server/package.json
RUN npm install

# Copy source code
COPY . .

# Build client and server
RUN npm run build

# Remove development dependencies to reduce size
RUN npm prune --omit=dev --workspaces

# ----- Production Stage -----
FROM node:18-alpine AS runner
WORKDIR /app

# Copy built application from builder
COPY --from=builder /app/package.json ./
COPY --from=builder /app/client/package.json ./client/package.json
COPY --from=builder /app/server/package.json ./server/package.json
COPY --from=builder /app/client/dist ./client/dist
COPY --from=builder /app/server/dist ./server/dist
COPY --from=builder /app/client/node_modules ./client/node_modules
COPY --from=builder /app/server/node_modules ./server/node_modules

ENV NODE_ENV=production
ENV PORT=3001

EXPOSE 3001

CMD ["node", "server/dist/index.js"]