-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathDockerfile
More file actions
47 lines (31 loc) · 1.47 KB
/
Copy pathDockerfile
File metadata and controls
47 lines (31 loc) · 1.47 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
ARG NODE_VERSION=lts-slim
FROM node:${NODE_VERSION} AS dependencies
WORKDIR /app
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN --mount=type=cache,id=pnpm-store,target=/pnpm/store \
--mount=type=bind,source=package.json,target=/app/package.json \
--mount=type=bind,source=pnpm-lock.yaml,target=/app/pnpm-lock.yaml \
corepack enable && \
pnpm install --frozen-lockfile --strict-peer-dependencies
FROM dependencies AS builder
COPY --chown=node:node src/ /app/src
RUN --mount=type=bind,source=package.json,target=/app/package.json \
--mount=type=bind,source=nest-cli.json,target=/app/nest-cli.json \
--mount=type=bind,source=tsconfig.json,target=/app/tsconfig.json \
--mount=type=bind,source=tsconfig.build.json,target=/app/tsconfig.build.json \
pnpm build
FROM builder AS pruner
RUN --mount=type=cache,id=pnpm-store,target=/pnpm/store \
--mount=type=bind,source=package.json,target=/app/package.json \
--mount=type=bind,source=pnpm-lock.yaml,target=/app/pnpm-lock.yaml \
pnpm prune --prod --ignore-scripts
FROM gcr.io/distroless/nodejs22-debian12:nonroot
WORKDIR /app
ENV PORT=3000
COPY --chown=nonroot:nonroot --from=pruner /app/node_modules ./node_modules
COPY --chown=nonroot:nonroot --from=builder /app/dist .
COPY --chown=nonroot:nonroot CHANGELOG.md LICENSE package.json /app/
EXPOSE ${PORT}
HEALTHCHECK --interval=30s --timeout=2s --start-period=10s --retries=2 CMD [ "/nodejs/bin/node", "bin/health-checker.js" ]
CMD ["main.js"]