master
text 253 lines 9.18 KB
Raw
1 ### STAGE 1 BUILDING.
2 FROM debian:trixie-slim AS builder
3
4 # Any value inside one of the disable ARGs will be accepted.
5 ARG DISABLE_EXTRACT="yes"
6 ARG DISABLE_MINIFY="yes"
7 ARG DISABLE_TRANSLATE="yes"
8 # NODE_OPTIONS="--max_old_space_size=4096"
9 # If your process gets OOM killed, perhaps the above will help.
10
11 # Install nodesource's NodeJS
12 RUN apt-get update && \
13 apt-get install -y --no-install-recommends --no-install-suggests \
14 nodejs npm && \
15 npm install -g npm@latest && \
16 mkdir -p /opt/meshcentral/meshcentral
17
18 WORKDIR /opt/meshcentral
19 COPY ./ /opt/meshcentral/meshcentral/
20
21 # Check the Docker build arguments and if they are empty do the task.
22 RUN if [ -n "$DISABLE_EXTRACT" ] || [ -n "$DISABLE_MINIFY" ] || [ -n "$DISABLE_TRANSLATE" ]; then \
23 echo -e "----------\nPREPARING ENVIRONMENT...\n----------"; \
24 cd meshcentral && \
25 npm install html-minifier-terser@7.2.0 jsdom@26.0.0 esprima@4.0.1 && \
26 cd translate && \
27 case "$DISABLE_EXTRACT" in \
28 false|no|FALSE|NO) \
29 echo -e "----------\nSTARTING THE EXTRACTING PROCESS...\n----------"; \
30 node translate.js extractall;; \
31 *) \
32 echo "Setting EXTRACT as disabled.";; \
33 esac && \
34 case "$DISABLE_MINIFY" in \
35 false|no|FALSE|NO) \
36 echo -e "----------\nSTARTING THE MINIFYING PROCESS...\n----------"; \
37 node translate.js minifyall;; \
38 *) \
39 echo "Setting MINIFY as disabled.";; \
40 esac && \
41 case "$DISABLE_TRANSLATE" in \
42 false|no|FALSE|NO) \
43 echo -e "----------\nSTARTING THE TRANSLATING PROCESS...\n----------"; \
44 node translate.js translateall;; \
45 *) \
46 echo "Setting TRANSLATE as disabled.";; \
47 esac; \
48 npm uninstall html-minifier-terser jsdom esprima; \
49 fi
50 # Possible more updated alternative? @minify-html/node@0.15.0 -> https://www.npmjs.com/package/@minify-html/node
51
52 RUN rm -rf /opt/meshcentral/meshcentral/docker /opt/meshcentral/meshcentral/node_modules /opt/meshcentral/meshcentral/docs
53
54 ### STAGE 2 PRECOMPILE DEPS MODULE
55
56 FROM debian:trixie-slim AS dep-compiler
57
58 ENV NODE_ENV="production"
59
60 # Install general dependencies and nodesource's NodeJS
61 RUN apt-get update && \
62 echo -e "----------\nINSTALLING DEBIAN PACKAGES...\n----------"; \
63 apt-get install -y --no-install-recommends --no-install-suggests \
64 bash gcc g++ jq make nodejs npm python3 tzdata && \
65 npm install -g npm@latest
66
67 COPY --from=builder /opt/meshcentral/meshcentral /opt/meshcentral/meshcentral
68 WORKDIR /opt/meshcentral/meshcentral
69
70 RUN jq '.dependencies += {"modern-syslog": "1.2.0", "telegram": "2.26.22"}' package.json > temp.json && mv temp.json package.json \
71 && npm i --package-lock-only \
72 && npm ci --omit=dev \
73 && npm cache clean --force
74
75 ### STAGE 3 fun. building from source...
76
77 FROM golang:trixie AS mongo-tools-compiler
78
79 ARG INCLUDE_MONGODB_TOOLS="false"
80
81 RUN apt-get update && \
82 apt-get install -y --no-install-recommends --no-install-suggests \
83 git lsb-release
84
85 RUN case "$INCLUDE_MONGODB_TOOLS" in \
86 true|yes|TRUE|YES) \
87 git clone https://github.com/mongodb/mongo-tools /mongo-tools; \
88 cd /mongo-tools; \
89 ./make build -pkgs=mongodump,mongorestore;; \
90 false|no|FALSE|NO) \
91 echo "Not building MongoDB Tools from source, what a shame!"; \
92 mkdir -p /mongo-tools/bin;; \
93 *) \
94 echo "Invalid value for build argument INCLUDE_MONGODB_TOOLS, possible values: 'yes', 'true', 'no' or 'false'"; \
95 exit 1;; \
96 esac
97
98 ### STAGE 4 BUILDING.
99
100 FROM debian:trixie-slim AS finalizer
101
102 ARG NODEJS_DOWNLOAD="https://nodejs.org/dist/v24.12.0/node-v24.12.0-linux-x64.tar.xz"
103
104 # Copy files from previous layers
105 COPY --from=dep-compiler /opt/meshcentral/meshcentral /opt/meshcentral/meshcentral
106 COPY --from=mongo-tools-compiler /mongo-tools/bin/ /tmp/bin/
107
108 # environment variables
109 ENV NODE_ENV="production" \
110 CONFIG_FILE="/opt/meshcentral/meshcentral-data/config.json" \
111 DYNAMIC_CONFIG="false"
112
113 # environment variables for the above defined MeshCentral Config.json. Can be done like that following: https://docs.docker.com/reference/dockerfile/#env
114 ENV ALLOW_PLUGINS="false" \
115 ALLOW_NEW_ACCOUNTS="false" \
116 ALLOWED_ORIGIN="false" \
117 HOSTNAME="localhost" \
118 PORT="443" \
119 REDIR_PORT="80" \
120 INSTALL_STYLISHUI="false" \
121 IFRAME="false" \
122 LOCAL_SESSION_RECORDING="true" \
123 MINIFY="true" \
124 REVERSE_PROXY="" \
125 REVERSE_PROXY_TLS_PORT="443" \
126 REGEN_SESSIONKEY="false" \
127 STYLISHUI_FORCE_LATEST="false" \
128 WEBRTC="false" \
129 TRUSTED_PROXY="" \
130 ARGS=""
131
132 # Database
133 # Multi-variable declaration to reduce layers.
134 ENV USE_MONGODB="false" \
135 USE_POSTGRESQL="false" \
136 USE_MARIADB="false"
137
138 # Preinstallation args one per line due to: https://docs.docker.com/reference/dockerfile/#arg
139 ARG PREINSTALL_LIBS="false"
140 ARG INCLUDE_MONGODB_TOOLS="false"
141 ARG INCLUDE_POSTGRESQL_TOOLS="false"
142 ARG INCLUDE_MARIADB_TOOLS="false"
143
144 # MongoDB Variables
145 # The following MONGO_URL variable overwrites most other mongoDb related varialbes.
146 ENV MONGO_HOST="" \
147 MONGO_PORT="27017" \
148 MONGO_USERNAME="" \
149 MONGO_PASS="" \
150 MONGO_URL=""
151
152 # PostgreSQL Variables
153 ENV PSQL_HOST="" \
154 PSQL_PORT="5432" \
155 PSQL_USER="" \
156 PSQL_PASS="" \
157 PSQL_DATABASE=""
158
159 # MariaDB/MySQL Variables.
160 ENV MARIADB_HOST="" \
161 MARIADB_PORT="3306" \
162 MARIADB_USER="" \
163 MARIADB_PASS="" \
164 MARIADB_DATABASE=""
165
166 WORKDIR /opt/meshcentral
167
168 RUN apt-get update && \
169 echo -e "----------\nINSTALLING DEBIAN PACKAGES...\n----------"; \
170 apt-get install -y --no-install-recommends --no-install-suggests \
171 bash ca-certificates curl jq nodejs npm tzdata wget && \
172 npm install -g npm@latest && \
173 rm -rfv \
174 /var/cache/* \
175 /usr/share/man/ \
176 /usr/share/doc/ \
177 /var/log/* \
178 /var/spool/* \
179 /var/tmp/* \
180 /usr/lib/debug/
181
182 RUN case "$PREINSTALL_LIBS" in \
183 true|yes|TRUE|YES) \
184 cd meshcentral && \
185 echo -e "----------\nPREINSTALLING LIBRARIES...\n----------"; \
186 npm install ssh2@1.17.0 nodemailer@6.10.1 image-size@2.0.2 wildleek@2.0.0 yub@0.11.1;; \
187 false|no|FALSE|NO) \
188 echo "Not pre-installing libraries.";; \
189 *) \
190 echo -e "Invalid value for build argument INCLUDE_POSTGRESQL_TOOLS, possible values: 'yes', 'true', 'no' or 'false'"; \
191 exit 1;; \
192 esac
193
194 # NOTE: ALL MODULES MUST HAVE A VERSION NUMBER AND THE VERSION MUST MATCH THAT USED IN meshcentraljs mainStart()
195 RUN case "$INCLUDE_MONGODB_TOOLS" in \
196 true|yes|TRUE|YES) \
197 mv /tmp/bin/* /usr/bin; \
198 cd meshcentral && \
199 echo -e "----------\nPREINSTALLING MONGODB LIBRARIES...\n----------"; \
200 npm install mongodb@4.17.2 @mongodb-js/saslprep@1.3.1;; \
201 false|no|FALSE|NO) \
202 echo "Not including MongoDB Tools.";; \
203 *) \
204 echo "Invalid value for build argument INCLUDE_MONGODB_TOOLS, possible values: 'yes', 'true', 'no' or 'false'"; \
205 exit 1;; \
206 esac
207
208 RUN case "$INCLUDE_POSTGRESQL_TOOLS" in \
209 true|yes|TRUE|YES) \
210 apt-get install -y --no-install-recommends --no-install-suggests postgresql-client-17; \
211 cd meshcentral && \
212 echo -e "----------\nPREINSTALLING POSTGRESQL LIBRARIES...\n----------"; \
213 npm install pg@8.16.3;; \
214 false|no|FALSE|NO) \
215 echo "Not including PostgreSQL Tools.";; \
216 *) \
217 echo -e "Invalid value for build argument INCLUDE_POSTGRESQL_TOOLS, possible values: 'yes', 'true', 'no' or 'false'"; \
218 exit 1;; \
219 esac
220
221 RUN case "$INCLUDE_MARIADB_TOOLS" in \
222 true|yes|TRUE|YES) \
223 apt-get install -y --no-install-recommends --no-install-suggests default-mysql-client mariadb-client; \
224 cd meshcentral && \
225 echo -e "----------\nPREINSTALLING MARIADB/MYSQL LIBRARIES...\n----------"; \
226 npm install mariadb@3.4.5 mysql2@3.15.1;; \
227 false|no|FALSE|NO) \
228 echo "Not including MariaDB/MySQL Tools.";; \
229 *) \
230 echo -e "Invalid value for build argument INCLUDE_MARIADB_TOOLS, possible values: 'yes', 'true', 'no' or 'false'"; \
231 exit 1;; \
232 esac
233
234 # Remove left over files and cache
235 RUN cd meshcentral \
236 && rm -rf /root /tmp/* /var/tmp/* /usr/lib/node_modules/npm/man /usr/lib/node_modules/npm/doc /usr/lib/node_modules/npm/html \
237 && npm cache clean --force
238
239 # Expose needed ports
240 EXPOSE ${PORT}
241 EXPOSE ${REDIR_PORT}
242
243 # These volumes will be created by default even without any declaration, this allows default persistence in Docker/Podman. Dummy-proofing.
244 VOLUME /opt/meshcentral/meshcentral-data
245 VOLUME /opt/meshcentral/meshcentral-files
246 VOLUME /opt/meshcentral/meshcentral-web
247 VOLUME /opt/meshcentral/meshcentral-backups
248
249 # Copy images from Git repo, place it before ending so recompilation can make good use of cache.
250 COPY ./docker/entrypoint.sh /opt/meshcentral/entrypoint.sh
251 COPY ./docker/config.json.template /opt/meshcentral/config.json.template
252
253 ENTRYPOINT ["/bin/bash", "/opt/meshcentral/entrypoint.sh"]