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