forked from nestjs/typescript-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
66 lines (50 loc) · 1.47 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# https://github.com/BretFisher/dockercon19
FROM node:20 AS base
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable
ENV TINI_VERSION v0.19.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
RUN chmod +x /tini
EXPOSE 3000
RUN mkdir /app && chown -R node:node /app
WORKDIR /app
USER node
COPY --chown=node:node package.json pnpm-lock.yaml ./
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile --ignore-scripts
# Development
FROM base AS dev
ENV NODE_ENV=development
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
ENV PATH=/app/node_modules/.bin:$PATH
CMD ["nest", "start", "--watch"]
FROM dev AS dev-source
COPY --chown=node:node . .
# Debugging
FROM dev AS debug
CMD [ "nest", "start", "--debug", "--watch"]
FROM dev-source AS debug-source
CMD [ "nest", "start", "--debug", "--watch"]
FROM debug-source AS debug-source-brk
ENV DEBUG_BRK=true
# Testing
FROM dev-source AS test
RUN yarn lint
RUN yarn test
FROM test AS audit
USER root
RUN yarn audit --level critical
ARG MICROSCANNER_TOKEN
ADD https://get.aquasec.com/microscanner /
RUN chmod +x /microscanner
RUN /microscanner "$MICROSCANNER_TOKEN" --continue-on-failure
# Build
FROM dev-source AS build
RUN pnpm run build
# Prod
FROM gcr.io/distroless/nodejs20-debian12 AS prod
COPY --from=build /app/node_modules/ /app/node_modules
COPY --from=build /app/dist/ /app/dist
USER nonroot
WORKDIR /app
CMD ["./dist/main.js"]