-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
33 lines (25 loc) · 969 Bytes
/
Dockerfile
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
# Install dependencies only when needed
FROM node:22.9.0-alpine3.20 AS deps
WORKDIR /app
RUN apk add --update --no-cache python3 make build-base && ln -sf python3 /usr/bin/python
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile
# Rebuild the source code only when needed
FROM node:22.9.0-alpine3.20 AS builder
WORKDIR /app
COPY package.json yarn.lock tsconfig.json tsconfig.build.json nest-cli.json ./
COPY ./src ./src
COPY --from=deps /app/node_modules ./node_modules
RUN yarn build && yarn install
# Production image, copy all the files and run nest
FROM node:22.9.0-alpine3.20 AS runner
WORKDIR /app
ENV NODE_ENV production
RUN addgroup -g 1001 -S nodejs \
&& adduser -S nestjs -u 1001
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json
COPY --from=builder --chown=nextjs:nestjs /app/dist ./dist
USER nestjs
EXPOSE 3001
CMD ["node", "--max-old-space-size=2048", "./dist/src/main.js"]