-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
78 lines (55 loc) · 1.91 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
67
68
69
70
71
72
73
74
75
76
77
78
# This dockerfile has multiple stages in order
# to optimize the build process time and reduce
# the final image size.
# ============================
# ==== Dependencies stage ====
# ============================
FROM node:20.11-alpine as dependencies
WORKDIR /app
COPY package.json .
COPY package-lock.json .
# install deps
RUN apk add --no-cache --virtual .build-deps alpine-sdk python3 && \
npm ci --silent && \
apk del .build-deps
# ======================
# ===== Build stage ====
# ======================
FROM node:20.11-alpine as builder
WORKDIR /app
# copy source files
COPY src ./src
COPY tsconfig.json .
# copy build files from dependencies stage
COPY --from=dependencies /app/package.json .
COPY --from=dependencies /app/package-lock.json .
COPY --from=dependencies /app/node_modules /app/node_modules
# build the project
RUN npm run build
# ========================
# ===== Prepare stage ====
# ========================
FROM node:20.11-alpine as prepare
WORKDIR /app
# copy build files from builder stage
COPY --from=builder /app/build /app/build
COPY --from=builder /app/package.json /app/package.json
COPY --from=builder /app/package-lock.json /app/package-lock.json
COPY --from=builder /app/node_modules /app/node_modules
# purge dev dependencies
RUN npm prune --omit=dev
# =====================
# ===== Run stage =====
# =====================
FROM node:20.11-alpine as runner
WORKDIR /app
# set production mode
ARG NODE_ENV=production
ENV NODE_ENV $NODE_ENV
# copy build files from prepare stage
COPY --from=prepare /app/build /app/build
COPY --from=prepare /app/package.json /app/package.json
COPY --from=prepare /app/package-lock.json /app/package-lock.json
COPY --from=prepare /app/node_modules /app/node_modules
# finaly start the bot
CMD ["npm", "run", "start"]