-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.Dockerfile
33 lines (32 loc) · 1.31 KB
/
api.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
FROM node:18.14.2-alpine3.16 as builder
# hadolint ignore=DL3018
RUN apk add --no-cache g++ make python3
RUN mkdir /app && chown -R node:node /app
WORKDIR /app
# TODO: Upgrade to NPM 9?
# RUN npm install --location=global [email protected]
# https://github.com/nodejs/docker-node/blob/main/docs/BestPractices.md#non-root-user
USER node
# COPY --chown=node:node package.json package-lock.json tsconfig.json src ./
COPY --chown=node:node . ./
RUN npm ci \
&& npx nx run api:build:production
FROM node:18.14.2-alpine3.16
ENV NODE_ENV=production
EXPOSE 3333
# https://github.com/nodejs/docker-node/blob/main/docs/BestPractices.md#handling-kernel-signals
# https://github.com/krallin/tini#alpine-linux-package
# https://pkgs.alpinelinux.org/package/edge/community/x86/tini
RUN apk add --no-cache tini=0.19.0-r0
ENTRYPOINT ["/sbin/tini", "--"]
RUN mkdir /app && chown -R node:node /app
WORKDIR /app
# TODO: Upgrade to NPM 9?
# RUN npm install --location=global [email protected]
# https://github.com/nodejs/docker-node/blob/main/docs/BestPractices.md#non-root-user
USER node
COPY --from=builder /app/dist/apps/api /app/dist
COPY --from=builder /app/package.json /app/package-lock.json ./
RUN npm ci --omit=dev --ignore-scripts && npm cache clean --force
# https://github.com/nodejs/docker-node/blob/main/docs/BestPractices.md#cmd
CMD ["node", "dist/main.js"]