Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
164 lines (135 loc) · 5.67 KB
/
Copy pathDockerfile
File metadata and controls
164 lines (135 loc) · 5.67 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# =============================
# Base Node image
# =============================
FROM node:24.22.2-alpine3.24@sha256:8a32c8cf649a49915a66e81e7a609223c708d0adabf288ee3f4077d765542f85 AS base
# pick up alpine security fixes released after the base image was published
RUN apk upgrade --no-cache
WORKDIR /app
ENV NODE_ENV=production
ENV DEBUG=upgrade*
# =============================
# 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
ADD ui/package.json ui/package.json
ADD api/package.json api/package.json
ADD portal/package.json portal/package.json
ADD patches patches
# full deps install used for types and ui building
# also used to fill the npm cache for faster install of api deps
# Note: --omit=peer can break nuxt's dependency resolution during postinstall
RUN npm ci --omit=dev --no-audit --no-fund
# =============================
# Build Types
# =============================
FROM installer AS types
ADD api/config api/config
ADD api/types api/types
ADD api/doc api/doc
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 /api/src/ui-config.ts api/src/ui-config.ts
ADD /ui ui
ADD /shared/markdown shared/markdown
ADD /portal/app/components portal/app/components
ADD /portal/app/utils portal/app/utils
ADD /portal/app/composables portal/app/composables
COPY --from=types /app/ui/src/components/vjsf ui/src/components/vjsf
RUN npm -w ui run build
# =============================
# Install production dependencies for API
# =============================
FROM installer AS api-installer
# vuetify and patch-package are not part of the api install, so skip the patches
RUN npm pkg delete scripts.postinstall
RUN cp -rf node_modules/@img/sharp-linuxmusl-x64 /tmp/sharp-linuxmusl-x64 && \
cp -rf node_modules/@img/sharp-libvips-linuxmusl-x64 /tmp/sharp-libvips-linuxmusl-x64 && \
npm ci -w api --prefer-offline --omit=dev --omit=optional --no-audit --no-fund && \
npx clean-modules && \
cp -rf /tmp/sharp-linuxmusl-x64 node_modules/@img/sharp-linuxmusl-x64 && \
cp -rf /tmp/sharp-libvips-linuxmusl-x64 node_modules/@img/sharp-libvips-linuxmusl-x64
RUN mkdir -p /app/shared/markdown/node_modules
RUN mkdir -p /app/api/node_modules
##########################
FROM base AS fonts-builder
ADD /dev/scripts/prepare-fonts.ts prepare-fonts.ts
RUN npm pack google-fonts-complete@2.2.3 &&\
tar -xzf google-fonts-complete-2.2.3.tgz &&\
rm google-fonts-complete-2.2.3.tgz &&\
mv package google-fonts-complete
RUN mkdir -p api/assets/fonts
RUN node prepare-fonts.ts
# =============================
# Build Portal with Nuxt
# =============================
FROM installer AS portal-builder
ENV DEBUG=""
ADD /shared/markdown shared/markdown
# the sitemap page and route import footerLinkItems from api/types at runtime
COPY --from=types /app/api/types api/types
ADD /portal portal
RUN npm -w portal run build
##########################
FROM base AS portal
COPY --from=portal-builder /app/portal/.output portal/.output
ADD package.json LICENSE ./
ENV PORT=8080
ENV HOST=0.0.0.0
# npm, corepack and yarn are never used at runtime and carry their own CVEs
RUN rm -rf /usr/local/lib/node_modules /usr/local/bin/npm /usr/local/bin/npx /usr/local/bin/corepack /opt/yarn-* /usr/local/bin/yarn /usr/local/bin/yarnpkg
# BUILD.json is written by CI for every build (README.md keeps the wildcard from matching nothing):
# last, so that a build of unchanged code only adds this layer
ADD README.md BUILD.json* ./
EXPOSE 8080
USER node
WORKDIR /app/portal
CMD ["node", "/app/portal/.output/server/index.mjs"]
# =============================
# Final API Image
# =============================
FROM base AS manager
COPY --from=fonts-builder /app/api/assets api/assets
COPY --from=api-installer /app/node_modules node_modules
COPY upgrade upgrade
ADD /shared shared
ADD /api api
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/shared/markdown/node_modules shared/markdown/node_modules
COPY --from=api-installer /app/api/node_modules api/node_modules
COPY --from=ui /app/ui/dist ui/dist
ADD package.json LICENSE ./
# artificially create a dependency to "portal" target for better caching in github ci
COPY --from=portal /app/package.json package.json
# npm, corepack and yarn are never used at runtime and carry their own CVEs
RUN rm -rf /usr/local/lib/node_modules /usr/local/bin/npm /usr/local/bin/npx /usr/local/bin/corepack /opt/yarn-* /usr/local/bin/yarn /usr/local/bin/yarnpkg
# BUILD.json is written by CI for every build (README.md keeps the wildcard from matching nothing):
# last, so that a build of unchanged code only adds this layer
ADD README.md BUILD.json* ./
EXPOSE 8080
EXPOSE 9090
USER node
WORKDIR /app/api
VOLUME /app/tmp
CMD ["node", "--max-http-header-size", "64000", "index.ts"]