File size: 1,628 Bytes
34367da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
FROM node:20-alpine AS builder
WORKDIR /app
RUN apk add --no-cache python3 make g++ sqlite

# 1. Dependency Layering (Cache Optimization)
# Copy ONLY package files first
COPY package*.json ./
COPY packages/shared/package.json ./packages/shared/
COPY packages/domain-types/package.json ./packages/domain-types/
COPY packages/mcp-types/package.json ./packages/mcp-types/
COPY apps/backend/package.json ./apps/backend/

# Install ALL dependencies (cached unless package.json changes)
RUN npm ci --legacy-peer-deps

# 2. Source Layering
COPY packages ./packages
COPY apps/backend ./apps/backend

# Build dependencies
WORKDIR /app/packages/mcp-types
RUN npm run build 2>/dev/null || true
WORKDIR /app/packages/domain-types
RUN npm run build 2>/dev/null || true

# Build Backend
WORKDIR /app/apps/backend
RUN npm run build

# Prune dev dependencies to save space
WORKDIR /app
RUN npm prune --production

# -----------------------------------------
# Production Stage
# -----------------------------------------
FROM node:20-alpine
WORKDIR /app
RUN apk add --no-cache sqlite

# Copy ALL production node_modules (Essential for tsc builds)
COPY --from=builder /app/node_modules ./node_modules
# Copy workspaces if they are symlinked (npm workspaces structure)
COPY --from=builder /app/packages ./packages

# Copy built app
COPY --from=builder /app/apps/backend/dist ./dist
COPY --from=builder /app/apps/backend/package*.json ./
# Schema (Adjust path if needed)
COPY --from=builder /app/apps/backend/src/database/schema.sql ./dist/schema.sql

EXPOSE 3001
CMD ["node", "dist/index.js"]