Skip to content

Commit fdd0911

Browse files
authored
Update Dockerfile
1 parent fd3f17e commit fdd0911

1 file changed

Lines changed: 38 additions & 5 deletions

File tree

Dockerfile

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,44 @@
1-
FROM node:20-slim
1+
# ---------- BUILD STAGE ----------
2+
FROM node:20-slim AS builder
3+
4+
WORKDIR /app
25

6+
# Install build deps only for native modules
37
RUN apt-get update && apt-get install -y \
4-
build-essential cmake python3 make gcc g++ \
8+
build-essential \
9+
python3 \
10+
make \
11+
gcc \
12+
g++ \
13+
cmake \
514
&& rm -rf /var/lib/apt/lists/*
615

7-
WORKDIR /app
16+
# Copy only package files first (better cache)
817
COPY package*.json ./
9-
RUN npm install --omit=dev
18+
19+
# Use npm ci for faster + reproducible builds
20+
RUN npm ci --omit=dev
21+
22+
# Copy source after deps (max cache efficiency)
1023
COPY . .
11-
CMD ["node", "--optimize-for-size", "--max-old-space-size=512", "bot.js"]
24+
25+
# ---------- RUNTIME STAGE ----------
26+
FROM node:20-slim
27+
28+
WORKDIR /app
29+
30+
# Install tini (important for child process cleanup)
31+
RUN apt-get update && apt-get install -y tini \
32+
&& rm -rf /var/lib/apt/lists/*
33+
34+
# Copy node_modules + app from builder
35+
COPY --from=builder /app /app
36+
37+
# Production env
38+
ENV NODE_ENV=production
39+
ENV NODE_OPTIONS="--max-old-space-size=512 --optimize-for-size"
40+
41+
# Use tini as PID 1 to properly reap worker processes
42+
ENTRYPOINT ["/usr/bin/tini", "--"]
43+
44+
CMD ["node", "bot.js"]

0 commit comments

Comments
 (0)