-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
50 lines (35 loc) · 1.16 KB
/
Dockerfile
File metadata and controls
50 lines (35 loc) · 1.16 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
# ---------- 1️⃣ Base Builder Stage ----------
FROM node:22-alpine AS builder
# Set working directory
WORKDIR /usr/src/app
# Copy dependency files first (better caching)
COPY package*.json tsconfig*.json ./
COPY prisma ./prisma
# Install dependencies for building
RUN npm ci
# Copy full source and build
COPY . .
RUN npm run build
# ---------- 2️⃣ Production Dependencies Stage ----------
FROM node:22-alpine AS deps
WORKDIR /usr/src/app
# Copy only package files for prod deps
COPY package*.json ./
COPY prisma ./prisma
RUN npm ci --omit=dev
# ---------- 3️⃣ Final Runtime Stage ----------
FROM node:22-alpine AS runner
# Environment variables (can be overridden via docker-compose)
ENV NODE_ENV=production \
PORT=3000
WORKDIR /usr/src/app
# Copy production node_modules and built files from previous stages
COPY --from=deps /usr/src/app/node_modules ./node_modules
COPY --from=builder /usr/src/app/dist ./dist
# Expose app port
EXPOSE ${PORT}
# Run command
CMD ["sh", "-c", "npm run db:deploy && npm run start"]
# ---------- 4️⃣ Image Size Output ----------
# Print image size after build
RUN echo "----- IMAGE SIZE -----" && du -sh /usr/src/app