Refactored more Dockerfile
Daan Selen committed
Mar 20, 2025 at 17:07 UTC
6eb85fa892dcdfbe41567d4aa360f1ef2f4f3801
1 file changed
+48
-45
docker/Dockerfile
+48
-45
@@ -1,40 +1,47 @@
1
### STAGE 1 BUILDING.
2
-FROM node:current-alpine AS builder
3
-
4
-RUN mkdir -p /opt/meshcentral/meshcentral
5
-COPY ./ /opt/meshcentral/meshcentral/
6
-WORKDIR /opt/meshcentral
2
+FROM node:lts-alpine AS builder
3
4
ARG DISABLE_MINIFY=""
5
ARG DISABLE_TRANSLATE="yes"
6
11
-RUN if ! [ -z "$DISABLE_MINIFY" ] && [ "$DISABLE_MINIFY" != "yes" ] && [ "$DISABLE_MINIFY" != "YES" ] \
7
+RUN mkdir -p /opt/meshcentral/meshcentral
8
+COPY ./ /opt/meshcentral/meshcentral/
9
+
10
+# Check if minify should be disabled on compilation.
11
+RUN if ! [ -z "$DISABLE_MINIFY" ] \
12
+ && [ "$DISABLE_MINIFY" != "yes" ] && [ "$DISABLE_MINIFY" != "YES" ] \
13
&& [ "$DISABLE_MINIFY" != "true" ] && [ "$DISABLE_MINIFY" != "TRUE" ]; then \
13
- echo -e "\e[0;31;49mInvalid value for build argument DISABLE_MINIFY, possible values: yes/true\e[;0m"; exit 1; \
14
+ echo "Invalid value for build argument DISABLE_MINIFY, possible values: 'yes' or 'true'"; \
15
+ exit 1; \
16
fi
15
-RUN if ! [ -z "$DISABLE_TRANSLATE" ] && [ "$DISABLE_TRANSLATE" != "yes" ] && [ "$DISABLE_TRANSLATE" != "YES" ] \
17
+# Check if translations should be compiled.
18
+RUN if ! [ -z "$DISABLE_TRANSLATE" ] \
19
+ && [ "$DISABLE_TRANSLATE" != "yes" ] && [ "$DISABLE_TRANSLATE" != "YES" ] \
20
&& [ "$DISABLE_TRANSLATE" != "true" ] && [ "$DISABLE_TRANSLATE" != "TRUE" ]; then \
17
- echo -e "\e[0;31;49mInvalid value for build argument DISABLE_TRANSLATE, possible values: yes/true\e[;0m"; exit 1; \
21
+ echo "Invalid value for build argument DISABLE_TRANSLATE, possible values: 'yes' or 'true'"; \
22
+ exit 1; \
23
fi
24
20
-# install translate/minify modules if need too
25
+# Check the Docker build arguments and execute them accordingly.
26
RUN if [ -z "$DISABLE_MINIFY" ] || [ -z "$DISABLE_TRANSLATE" ]; then \
22
- cd meshcentral && npm install html-minifier@4.0.0 jsdom@26.0.0 esprima@4.0.1; \
23
- cd translate && node translate.js extractall; \
24
- fi
25
-# @minify-html/node@0.15.0
26
-
27
-# minify files
28
-RUN if [ -z "$DISABLE_MINIFY" ]; then \
29
- cd meshcentral/translate && node translate.js minifyall; \
30
- fi
31
-
32
-# translate
33
-RUN if [ -z "$DISABLE_TRANSLATE" ]; then \
34
- cd meshcentral/translate && node translate.js translateall; \
27
+ cd meshcentral && \
28
+ npm install html-minifier@4.0.0 jsdom@26.0.0 esprima@4.0.1 && \
29
+\
30
+ cd translate && \
31
+ node translate.js extractall && \
32
+\
33
+ if [ -z "$DISABLE_MINIFY" ]; then \
34
+ node translate.js minifyall; \
35
+ fi; \
36
+\
37
+ if [ -z "$DISABLE_TRANSLATE" ]; then \
38
+ node translate.js translateall; \
39
+ fi \
40
fi
41
+# Possible more updated alternative? @minify-html/node@0.15.0 -> https://www.npmjs.com/package/@minify-html/node
42
43
# cleanup
44
+RUN ls -l /opt/meshcentral/meshcentral
45
RUN rm -rf /opt/meshcentral/meshcentral/docker
46
RUN rm -rf /opt/meshcentral/meshcentral/node_modules
47
@@ -42,17 +49,6 @@ RUN rm -rf /opt/meshcentral/meshcentral/node_modules
49
50
FROM alpine:latest
51
45
-RUN mkdir -p /opt/meshcentral/meshcentral
46
-
47
-# meshcentral installation
48
-WORKDIR /opt/meshcentral
49
-
50
-RUN apk update \
51
- && apk add --no-cache --update \
52
- tzdata nodejs npm bash python3 postgresql-client make gcc g++ \
53
- && rm -rf /var/cache/apk/*
54
-RUN npm install -g npm@latest
55
-
52
ARG INCLUDE_MONGODBTOOLS=""
53
ARG PREINSTALL_LIBS="false"
54
@@ -72,19 +68,29 @@ ENV LOCALSESSIONRECORDING="true"
68
ENV MINIFY="false"
69
ENV WEBRTC="false"
70
ENV IFRAME="false"
75
-ENV SESSION_KEY=""
71
ENV REVERSE_PROXY="false"
72
ENV REVERSE_PROXY_TLS_PORT=""
73
ENV ARGS=""
74
ENV ALLOWED_ORIGIN="false"
75
81
-RUN if ! [ -z "$INCLUDE_MONGODBTOOLS" ] && [ "$INCLUDE_MONGODBTOOLS" != "yes" ] && [ "$INCLUDE_MONGODBTOOLS" != "YES" ] \
76
+RUN mkdir -p /opt/meshcentral/meshcentral
77
+
78
+# meshcentral installation
79
+WORKDIR /opt/meshcentral
80
+
81
+RUN apk update \
82
+ && apk add --no-cache --update tzdata nodejs npm bash python3 postgresql-client make gcc g++ \
83
+ && rm -rf /var/cache/apk/*
84
+RUN npm install -g npm@latest
85
+
86
+# NOTE: ALL MODULES MUST HAVE A VERSION NUMBER AND THE VERSION MUST MATCH THAT USED IN meshcentral.js mainStart()
87
+RUN if ! [ -z "$INCLUDE_MONGODBTOOLS" ] \
88
+ && [ "$INCLUDE_MONGODBTOOLS" != "yes" ] && [ "$INCLUDE_MONGODBTOOLS" != "YES" ] \
89
&& [ "$INCLUDE_MONGODBTOOLS" != "true" ] && [ "$INCLUDE_MONGODBTOOLS" != "TRUE" ]; then \
90
echo -e "\e[0;31;49mInvalid value for build argument INCLUDE_MONGODBTOOLS, possible values: yes/true\e[;0m"; exit 1; \
84
- fi
85
-
86
-RUN if ! [ -z "$INCLUDE_MONGODBTOOLS" ]; then \
91
+ else \
92
apk add --no-cache mongodb-tools; \
93
+ cd meshcentral && npm install mongodb@6.15.0 saslprep@1.0.3; \
94
fi
95
96
# copy files from builder-image
@@ -95,12 +101,8 @@ COPY ./docker/config.json.template /opt/meshcentral/config.json.template
101
# install dependencies from package.json
102
RUN cd meshcentral && npm install
103
98
-# NOTE: ALL MODULES MUST HAVE A VERSION NUMBER AND THE VERSION MUST MATCH THAT USED IN meshcentral.js mainStart()
99
-RUN if ! [ -z "$INCLUDE_MONGODBTOOLS" ]; then \
100
- cd meshcentral && npm install mongodb@6.15.0 saslprep@1.0.3; \
101
- fi
102
-
103
-RUN if ! [ -z "$PREINSTALL_LIBS" ] && [ "$PREINSTALL_LIBS" == "true" ]; then \
104
+RUN if ! [ -z "$PREINSTALL_LIBS" ] \
105
+ && [ "$PREINSTALL_LIBS" == "true" ]; then \
106
cd meshcentral && 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; \
107
fi
108
@@ -112,4 +114,5 @@ VOLUME /opt/meshcentral/meshcentral-files
114
VOLUME /opt/meshcentral/meshcentral-web
115
VOLUME /opt/meshcentral/meshcentral-backups
116
117
+WORKDIR /opt/meshcentral
118
CMD ["bash", "/opt/meshcentral/entrypoint.sh"]