Skip to content

Commit eff418f

Browse files
committed
feat: Optimized the docker image
1 parent 4d750ca commit eff418f

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

Dockerfile

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
1-
FROM node:20-alpine
1+
FROM node:20-alpine AS builder
22

33
WORKDIR /app
44

5-
# Copying dependencies & env & schema
65
COPY package*.json ./
76
COPY prisma ./prisma
87

9-
# Install dependencies
10-
RUN npm install
8+
RUN npm ci
9+
10+
RUN DATABASE_URL="x" npx prisma generate
1111

12-
# Copying source code
1312
COPY . .
13+
RUN npm run build
14+
15+
# ---- Final image ----
16+
FROM node:20-alpine AS runner
1417

15-
# Clean old builds -- (super important)
16-
RUN rm -rf node_modules/.prisma dist
18+
WORKDIR /app
1719

18-
# Generate Prisma Client
19-
# Build-time ARG (only needed for prisma generate)
20-
ARG DATABASE_URL
21-
ENV DATABASE_URL=$DATABASE_URL
22-
RUN npx prisma generate
20+
COPY --from=builder /app/dist ./dist
21+
COPY --from=builder /app/node_modules ./node_modules
22+
COPY --from=builder /app/prisma ./prisma
23+
COPY package*.json ./
2324

24-
# Build TS files after client is ready
25-
RUN npm run build
25+
ENV NODE_ENV=production
2626

27-
# Run compiled app
2827
CMD ["npm", "start"]

0 commit comments

Comments
 (0)