File size: 2,117 Bytes
cfbb685
 
a59f28c
 
 
cfbb685
 
8ff7abb
cfbb685
8ff7abb
b035578
cfbb685
8ff7abb
827d82d
93faeee
 
 
cfbb685
 
34c79d1
cfbb685
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a59f28c
b035578
 
8ff7abb
cfbb685
752165b
b035578
10211c3
e4884cd
cfbb685
86731f4
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
# ─── STAGE 1: Builder ──────────────────────────────────────────────────────────
FROM node:20 AS builder

WORKDIR /app

# Install pnpm and turbo
RUN npm install -g pnpm turbo

# Copy the entire monorepo for building
COPY . .

# Install all dependencies (including devDependencies)
RUN pnpm install --frozen-lockfile

# Generate Prisma client BEFORE building (API and worker both need the generated types)
RUN pnpm --filter @repo/database generate

# Build everything (packages and apps)
RUN pnpm turbo run build

# ─── STAGE 2: Runner ───────────────────────────────────────────────────────────
FROM node:20-slim AS runner

WORKDIR /app

# Install system dependencies (ffmpeg for audio, espeak-ng for TTS)
RUN apt-get update && apt-get install -y \
    ffmpeg \
    espeak-ng \
    && rm -rf /var/lib/apt/lists/*

# Install pnpm and pm2 globally in the runner
RUN npm install -g pnpm pm2

# Copy only what's necessary from the builder stage
# In a monorepo, we copy the root node_modules and the built apps/packages
COPY --from=builder /app/package.json /app/pnpm-lock.yaml /app/pnpm-workspace.yaml /app/
COPY --from=builder /app/node_modules /app/node_modules
COPY --from=builder /app/apps/api/dist /app/apps/api/dist
COPY --from=builder /app/apps/api/package.json /app/apps/api/package.json
COPY --from=builder /app/apps/whatsapp-worker/dist /app/apps/whatsapp-worker/dist
COPY --from=builder /app/apps/whatsapp-worker/package.json /app/apps/whatsapp-worker/package.json
COPY --from=builder /app/packages /app/packages
COPY --from=builder /app/ecosystem.config.js /app/ecosystem.config.js
COPY --from=builder /app/start.sh /app/start.sh

# Environment variables
ENV NODE_ENV=production
ENV NODE_OPTIONS="--dns-result-order=ipv4first"
ENV PATH="/app/node_modules/.bin:${PATH}"

# Expose API and Worker Bridge ports
EXPOSE 7860 8082

# Start with PM2
CMD ["./start.sh"]