Dockerfix (#7074)

* Added Dockerfile improvements for parsing and building * Downgraded versions to match meshcentral.js * removed unneeded removal * syntax fix.

DaanSelen committed Jun 2, 2025 at 15:26 UTC d533cc377b72d7966e617489c1a1eaebeac59e15
1 file changed +38 -31
docker/Dockerfile
+38 -31
@@ -2,39 +2,41 @@
2 FROM node:lts-alpine3.21 AS builder
3
4 # Any value inside one of the disable ARGs will be accepted.
5 -ARG DISABLE_MINIFY="yes" \
6 - DISABLE_TRANSLATE="yes"
5 +ARG DISABLE_MINIFY="yes"
6 +ARG DISABLE_TRANSLATE="yes"
7 +# NODE_OPTIONS="--max_old_space_size=4096"
8 +# If your process gets OOM killed, perhaps the above will help.
9
10 RUN mkdir -p /opt/meshcentral/meshcentral
11 WORKDIR /opt/meshcentral
12 COPY ./ /opt/meshcentral/meshcentral/
13
14 # Check the Docker build arguments and if they are empty do the task.
13 -RUN if [ -z "$DISABLE_MINIFY" ] || [ -z "$DISABLE_TRANSLATE" ]; then \
15 +RUN if [ -n "$DISABLE_MINIFY" ] || [ -n "$DISABLE_TRANSLATE" ]; then \
16 + echo -e "----------\nPREPARING ENVIRONMENT...\n----------"; \
17 cd meshcentral && \
18 npm install html-minifier@4.0.0 jsdom@26.0.0 esprima@4.0.1 && \
19 cd translate && \
20 + echo -e "----------\nSTARTING THE EXTRACTING PROCESS...\n----------"; \
21 node translate.js extractall && \
22 case "$DISABLE_MINIFY" in \
23 false|no|FALSE|NO) \
24 + echo -e "----------\nSTARTING THE MINIFYING PROCESS...\n----------"; \
25 node translate.js minifyall;; \
26 *) \
27 echo "Setting MINIFY as disabled.";; \
28 esac && \
29 case "$DISABLE_TRANSLATE" in \
30 false|no|FALSE|NO) \
31 + echo -e "----------\nSTARTING THE TRANSLATING PROCESS...\n----------"; \
32 node translate.js translateall;; \
33 *) \
34 echo "Setting TRANSLATE as disabled.";; \
29 - esac \
35 + esac; \
36 + npm uninstall html-minifier jsdom esprima; \
37 fi
38 # Possible more updated alternative? @minify-html/node@0.15.0 -> https://www.npmjs.com/package/@minify-html/node
39
33 -RUN cd meshcentral \
34 - && npm uninstall html-minifier jsdom esprima
35 -
36 -# cleanup for inter-container copying.
37 -
40 RUN rm -rf /opt/meshcentral/meshcentral/docker
41 RUN rm -rf /opt/meshcentral/meshcentral/node_modules
42
@@ -47,7 +49,7 @@ ENV NODE_ENV="production" \
49 CONFIG_FILE="/opt/meshcentral/meshcentral-data/config.json" \
50 DYNAMIC_CONFIG="false"
51
50 -# environment variables for the above defined MeshCentral Config.json
52 +# environment variables for the above defined MeshCentral Config.json. Can be done like that following: https://docs.docker.com/reference/dockerfile/#env
53 ENV ALLOW_PLUGINS="false" \
54 ALLOW_NEW_ACCOUNTS="false" \
55 ALLOWED_ORIGIN="false" \
@@ -68,11 +70,11 @@ ENV USE_MONGODB="false" \
70 USE_POSTGRESQL="false" \
71 USE_MARIADB="false"
72
71 -# Preinstallation args
72 -ARG PREINSTALL_LIBS="false" \
73 - INCLUDE_MONGODB_TOOLS="false" \
74 - INCLUDE_POSTGRESQL_TOOLS="false" \
75 - INCLUDE_MARIADB_TOOLS="false"
73 +# Preinstallation args one per line due to: https://docs.docker.com/reference/dockerfile/#arg
74 +ARG PREINSTALL_LIBS="false"
75 +ARG INCLUDE_MONGODB_TOOLS="false"
76 +ARG INCLUDE_POSTGRESQL_TOOLS="false"
77 +ARG INCLUDE_MARIADB_TOOLS="false"
78
79 # MongoDB Variables
80 # The following MONGO_URL variable overwrites most other mongoDb related varialbes.
@@ -99,26 +101,28 @@ ENV MARIADB_HOST="" \
101 RUN mkdir -p /opt/meshcentral/meshcentral
102 WORKDIR /opt/meshcentral
103
102 -RUN apk update \
103 - && apk add --no-cache --update \
104 - bash gcc g++ jq make nodejs npm python3 tzdata \
105 - && rm -rf /var/cache/* \
104 +RUN apk update && \
105 + echo -e "----------\nINSTALLING ALPINE PACKAGES...\n----------"; \
106 + apk add --no-cache --update \
107 + bash gcc g++ jq make nodejs npm python3 tzdata && \
108 + rm -rf /var/cache/* \
109 /tmp/* \
110 /usr/share/man/ \
111 /usr/share/doc/ \
112 /var/log/* \
113 /var/spool/* \
111 - /usr/lib/debug/
112 -RUN npm install -g npm@latest
114 + /usr/lib/debug/ && \
115 + npm install -g npm@latest
116
117 RUN case "$PREINSTALL_LIBS" in \
118 true|yes|TRUE|YES) \
119 cd meshcentral && \
120 + echo -e "----------\nPREINSTALLING LIBRARIES...\n----------"; \
121 npm install ssh2@1.16.0 semver@7.7.1 nodemailer@6.10.0 image-size@2.0.1 wildleek@2.0.0 otplib@12.0.1 yubikeyotp@0.2.0;; \
122 false|no|FALSE|NO) \
123 echo "Not pre-installing libraries.";; \
124 *) \
121 - echo -e "Invalid value for build argument INCLUDE_POSTGRESQL_TOOLS, possible values: 'yes' or 'true'"; \
125 + echo -e "Invalid value for build argument INCLUDE_POSTGRESQL_TOOLS, possible values: 'yes', 'true', 'no' or 'false'"; \
126 exit 1;; \
127 esac
128
@@ -126,36 +130,39 @@ RUN case "$PREINSTALL_LIBS" in \
130 RUN case "$INCLUDE_MONGODB_TOOLS" in \
131 true|yes|TRUE|YES) \
132 apk add --no-cache mongodb-tools && \
129 - cd meshcentral && npm install mongodb@6.16.0 \
130 - ;; \
133 + cd meshcentral && \
134 + echo -e "----------\nPREINSTALLING MONGODB LIBRARIES...\n----------"; \
135 + npm install mongodb@4.17.2;; \
136 false|no|FALSE|NO) \
137 echo "Not including MongoDB Tools.";; \
138 *) \
134 - echo "Invalid value for build argument INCLUDE_MONGODB_TOOLS, possible values: 'yes' or 'true'"; \
139 + echo "Invalid value for build argument INCLUDE_MONGODB_TOOLS, possible values: 'yes', 'true', 'no' or 'false'"; \
140 exit 1;; \
141 esac
142
143 RUN case "$INCLUDE_POSTGRESQL_TOOLS" in \
144 true|yes|TRUE|YES) \
145 apk add --no-cache postgresql-client && \
141 - cd meshcentral && npm install pg@8.14.1 \
142 - ;; \
146 + cd meshcentral && \
147 + echo -e "----------\nPREINSTALLING POSTGRESQL LIBRARIES...\n----------"; \
148 + npm install pg@8.14.1;; \
149 false|no|FALSE|NO) \
150 echo "Not including PostgreSQL Tools.";; \
151 *) \
146 - echo -e "Invalid value for build argument INCLUDE_POSTGRESQL_TOOLS, possible values: 'yes' or 'true'"; \
152 + echo -e "Invalid value for build argument INCLUDE_POSTGRESQL_TOOLS, possible values: 'yes', 'true', 'no' or 'false'"; \
153 exit 1;; \
154 esac
155
156 RUN case "$INCLUDE_MARIADB_TOOLS" in \
157 true|yes|TRUE|YES) \
158 apk add --no-cache mariadb-client && \
153 - cd meshcentral && npm install mariadb@3.4.0 mysql2@3.11.4-canary.401db79b \
154 - ;; \
159 + cd meshcentral && \
160 + echo -e "----------\nPREINSTALLING MARIADB/MYSQL LIBRARIES...\n----------"; \
161 + npm install mariadb@3.4.0 mysql2@3.11.4;; \
162 false|no|FALSE|NO) \
163 echo "Not including MariaDB/MySQL Tools.";; \
164 *) \
158 - echo -e "Invalid value for build argument INCLUDE_MARIADB_TOOLS, possible values: 'yes' or 'true'"; \
165 + echo -e "Invalid value for build argument INCLUDE_MARIADB_TOOLS, possible values: 'yes', 'true', 'no' or 'false'"; \
166 exit 1;; \
167 esac
168