-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDockerfile
60 lines (53 loc) · 1.49 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
#
# ---- Base Node ----
FROM node:19.8.1-alpine3.17 AS base
# set working directory
WORKDIR /app
# Update npm
RUN npm --silent install -g --depth 0 npm@latest
# Install pnpm
RUN npm --silent install -g --depth 0 pnpm@latest
RUN pnpm set progress=false && npm config set depth 0
# Install nx dependencies
RUN pnpm --silent install reflect-metadata tslib rxjs bcrypt
#
# ---- Dependencies ----
FROM base AS dependencies
# copy dependecies files
COPY package.json .
COPY pnpm-lock.yaml .
# install node packages
RUN pnpm install --silent --frozen-lockfile
#
# ---- Builder ----
FROM base AS builder
# copy node_modules for build
COPY --from=dependencies /app/node_modules node_modules
# copy app sources
COPY . .
# build production app
RUN pnpm run build
#
# ---- Prod Dependencies ----
FROM base AS proddependencies
# install node-prune (https://github.com/tj/node-prune)
RUN wget -O - https://gobinaries.com/tj/node-prune | sh
# copy all node_modules
COPY --from=dependencies /app/node_modules node_modules
# copy project package.json
COPY --from=builder /app/package.json .
RUN pnpm prune --silent --prod
# run node prune
RUN /usr/local/bin/node-prune
#
# ---- Release ----
FROM alpine:3.17
# Install Nodejs (this setup results in significantly smaller image sizes)
RUN apk add --update nodejs=18.14.2-r0
# copy production node_modules
COPY --from=proddependencies /app/node_modules ./node_modules
# copy production build
COPY --from=builder /app/dist .
# expose port and define CMD
EXPOSE 3333
CMD node ./main.js