generated from AlbertHernandez/express-typescript-service-template
-
Notifications
You must be signed in to change notification settings - Fork 55
/
Dockerfile
54 lines (38 loc) · 989 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
FROM node:20-alpine3.18 AS base
ENV DIR /app
WORKDIR $DIR
ARG NPM_TOKEN
FROM base AS dev
ENV NODE_ENV=development
COPY package*.json .
RUN echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ".npmrc" && \
npm ci && \
rm -f .npmrc
COPY tsconfig*.json .
COPY .swcrc .
COPY nest-cli.json .
COPY src src
EXPOSE $PORT
CMD ["npm", "run", "dev"]
FROM base AS build
RUN apk update && apk add --no-cache dumb-init=1.2.5-r2
COPY package*.json .
RUN echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ".npmrc" && \
npm ci && \
rm -f .npmrc
COPY tsconfig*.json .
COPY .swcrc .
COPY nest-cli.json .
COPY src src
RUN npm run build && \
npm prune --production
FROM base AS production
ENV NODE_ENV=production
ENV USER=node
COPY --from=build /usr/bin/dumb-init /usr/bin/dumb-init
COPY --from=build $DIR/package*.json .
COPY --from=build $DIR/node_modules node_modules
COPY --from=build $DIR/dist dist
USER $USER
EXPOSE $PORT
CMD ["dumb-init", "node", "dist/main.js"]