-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
120 lines (103 loc) · 4.15 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# =============================
# Base Node image
# =============================
FROM node:22.11.0-alpine3.20 AS base
WORKDIR /app
ENV NODE_ENV=production
# =============================
# Package preparation (stripping version for caching)
# =============================
FROM base AS package-strip
RUN apk add --no-cache jq moreutils
ADD package.json package-lock.json ./
# remove version from manifest for better caching when building a release
RUN jq '.version="build"' package.json | sponge package.json
RUN jq '.version="build"' package-lock.json | sponge package-lock.json
# =============================
# Full dependencies installation (for types and building)
# =============================
FROM base AS installer
RUN apk add --no-cache python3 make g++ git jq moreutils
RUN npm i -g clean-modules@3.0.4
COPY --from=package-strip /app/package.json package.json
COPY --from=package-strip /app/package-lock.json package-lock.json
COPY ui/package.json ui/package.json
COPY api/package.json api/package.json
COPY worker/package.json worker/package.json
# full deps install used for types and ui building
# also used to fill the npm cache for faster install api and worker deps
RUN npm ci --omit=dev --omit=optional --omit=peer --no-audit --no-fund
# =============================
# Build Types for API and Worker
# =============================
FROM installer AS types
COPY api/types api/types
COPY api/doc api/doc
COPY api/config api/config
COPY worker/config worker/config
RUN npm run build-types
# =============================
# Build UI with Vite
# =============================
FROM installer AS ui
RUN npm i --no-save @rollup/rollup-linux-x64-musl
COPY --from=types /app/api/config api/config
COPY --from=types /app/api/types api/types
ADD /api/src/config.ts api/src/config.ts
ADD /ui ui
RUN npm -w ui run build
# =============================
# Install production dependencies for Worker
# =============================
FROM installer AS worker-installer
RUN npm ci -w worker --prefer-offline --omit=dev --omit=optional --omit=peer --no-audit --no-fund && \
npx clean-modules --yes
RUN mkdir -p /app/worker/node_modules
RUN mkdir -p /app/shared/node_modules
# =============================
# Final Worker Image
# =============================
FROM base AS worker
COPY --from=worker-installer /app/node_modules node_modules
COPY worker worker
COPY shared shared
COPY upgrade upgrade
COPY --from=types /app/worker/config worker/config
COPY --from=types /app/api/types api/types
COPY --from=worker-installer /app/worker/node_modules worker/node_modules
COPY --from=worker-installer /app/shared/node_modules shared/node_modules
COPY package.json README.md LICENSE BUILD.json* ./
EXPOSE 9090
# USER node # This would be great to use, but not possible as the volumes are mounted as root
WORKDIR /app/worker
CMD ["node", "--experimental-strip-types", "index.ts"]
# =============================
# Install production dependencies for API
# =============================
FROM installer AS api-installer
# remove other workspaces and reinstall, otherwise we can get rig have some peer dependencies from other workspaces
RUN npm ci -w api --prefer-offline --omit=dev --omit=optional --omit=peer --no-audit --no-fund && \
npx clean-modules --yes
RUN mkdir -p /app/api/node_modules
RUN mkdir -p /app/shared/node_modules
# =============================
# Final API Image
# =============================
FROM base AS main
COPY --from=api-installer /app/node_modules node_modules
COPY api api
COPY shared shared
COPY --from=types /app/api/types api/types
COPY --from=types /app/api/doc api/doc
COPY --from=types /app/api/config api/config
COPY --from=api-installer /app/api/node_modules api/node_modules
COPY --from=api-installer /app/shared/node_modules shared/node_modules
COPY --from=ui /app/ui/dist ui/dist
COPY package.json README.md LICENSE BUILD.json* ./
# artificially create a dependency to "worker" target for better caching in github ci
COPY --from=worker /app/package.json package.json
EXPOSE 8080
EXPOSE 9090
# USER node # This would be great to use, but not possible as the volumes are mounted as root
WORKDIR /app/api
CMD ["node", "--max-http-header-size", "65536", "--experimental-strip-types", "index.ts"]