Skip to content

Commit d129e70

Browse files
Updated Dockerfile to be multi-stage.
1 parent 4eacea1 commit d129e70

File tree

1 file changed

+32
-16
lines changed

1 file changed

+32
-16
lines changed

Dockerfile

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,49 @@
1-
FROM node:24-alpine
21

3-
# Install pnpm globally
4-
RUN npm install -g pnpm
2+
# Stage 1: Build the application
3+
FROM node:24-alpine AS builder
54

6-
# Set working directory
7-
WORKDIR /usr/src/app
5+
WORKDIR /app
86

7+
# Install pnpm globally
8+
RUN npm install -g pnpm
99

10-
# Copy only manifest, lockfile, and prisma schema for better caching
10+
# Copy package manifests and lockfile
1111
COPY package.json pnpm-lock.yaml ./
1212
COPY prisma ./prisma
1313

14-
15-
# Install all dependencies (including devDependencies for build)
14+
# Install dependencies
1615
RUN pnpm install --unsafe-perm
1716

18-
# Generate Prisma Client
19-
RUN npx prisma generate
20-
21-
# Copy the rest of the source code
17+
# Copy the rest of your application code
2218
COPY . .
2319

24-
# Build the app (requires @nestjs/cli as devDependency)
20+
# Run Prisma Generate
21+
RUN npx prisma generate
22+
23+
# Build the application
2524
RUN pnpm build
2625

27-
# Prune devDependencies for smaller final image
28-
RUN pnpm prune --prod
26+
# Stage 2: Production Image
27+
FROM node:24-alpine
28+
29+
WORKDIR /app
30+
31+
# Install pnpm in the final production image as well
32+
RUN npm install -g pnpm
33+
34+
# Set environment variables for better console output
35+
ENV FORCE_COLOR=1
36+
ENV NODE_ENV=production
37+
38+
# Copy only the necessary production artifacts from the 'builder' stage
39+
COPY --from=builder /app/node_modules ./node_modules
40+
COPY --from=builder /app/package.json ./package.json
41+
COPY --from=builder /app/pnpm-lock.yaml ./pnpm-lock.yaml
42+
COPY --from=builder /app/dist ./dist
43+
COPY --from=builder /app/prisma ./prisma
44+
COPY docker-entrypoint.sh .
2945

30-
# Ensure entrypoint is executable
46+
# Ensure the entrypoint is executable
3147
RUN chmod +x docker-entrypoint.sh
3248

3349
# Expose the NestJS port

0 commit comments

Comments
 (0)