Modified Dockerfile for readability Renamed startup.sh to entrypoint.sh

Modified Dockerfile for readability Renamed startup.sh to entrypoint.sh

Daan Selen committed Mar 19, 2025 at 15:32 UTC da5ef522f8c64bd500eba8de9df4a7dd9fb90147
2 files changed +33 -20
docker/Dockerfile
+33 -20
@@ -1,49 +1,55 @@
1 -FROM --platform=$BUILDPLATFORM node:22-alpine AS builder
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
7
8 ARG DISABLE_MINIFY=""
8 -ARG DISABLE_TRANSLATE=""
9 -
9 +ARG DISABLE_TRANSLATE="yes"
10
11 RUN if ! [ -z "$DISABLE_MINIFY" ] && [ "$DISABLE_MINIFY" != "yes" ] && [ "$DISABLE_MINIFY" != "YES" ] \
12 && [ "$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; \
13 + echo -e "\e[0;31;49mInvalid value for build argument DISABLE_MINIFY, possible values: yes/true\e[;0m"; exit 1; \
14 fi
15 RUN if ! [ -z "$DISABLE_TRANSLATE" ] && [ "$DISABLE_TRANSLATE" != "yes" ] && [ "$DISABLE_TRANSLATE" != "YES" ] \
16 && [ "$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; \
17 + echo -e "\e[0;31;49mInvalid value for build argument DISABLE_TRANSLATE, possible values: yes/true\e[;0m"; exit 1; \
18 fi
19
20 # install translate/minify modules if need too
21 -RUN if [ -z "$DISABLE_MINIFY" ] || [ -z "$DISABLE_TRANSLATE" ]; then cd meshcentral && npm install html-minifier@4.0.0 jsdom@22.1.0 esprima@4.0.1; fi
22 -
23 -# first extractall if need too
24 -RUN if [ -z "$DISABLE_MINIFY" ] || [ -z "$DISABLE_TRANSLATE" ]; then cd meshcentral/translate && node translate.js extractall; fi
21 +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
27 -RUN if [ -z "$DISABLE_MINIFY" ]; then cd meshcentral/translate && node translate.js minifyall; fi
28 +RUN if [ -z "$DISABLE_MINIFY" ]; then \
29 + cd meshcentral/translate && node translate.js minifyall; \
30 + fi
31
32 # translate
30 -RUN if [ -z "$DISABLE_TRANSLATE" ]; then cd meshcentral/translate && node translate.js translateall; fi
33 +RUN if [ -z "$DISABLE_TRANSLATE" ]; then \
34 + cd meshcentral/translate && node translate.js translateall; \
35 + fi
36
37 # cleanup
38 RUN rm -rf /opt/meshcentral/meshcentral/docker
39 RUN rm -rf /opt/meshcentral/meshcentral/node_modules
40
41 +### STAGE 2 BUILDING.
42
37 -FROM --platform=$TARGETPLATFORM alpine:3.21
43 +FROM alpine:latest
44
39 -#Add non-root user, add installation directories and assign proper permissions
45 RUN mkdir -p /opt/meshcentral/meshcentral
46
47 # meshcentral installation
48 WORKDIR /opt/meshcentral
49
50 RUN apk update \
46 - && apk add --no-cache --update tzdata nodejs npm bash python3 make gcc g++ \
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
@@ -74,22 +80,29 @@ ENV ALLOWED_ORIGIN="false"
80
81 RUN if ! [ -z "$INCLUDE_MONGODBTOOLS" ] && [ "$INCLUDE_MONGODBTOOLS" != "yes" ] && [ "$INCLUDE_MONGODBTOOLS" != "YES" ] \
82 && [ "$INCLUDE_MONGODBTOOLS" != "true" ] && [ "$INCLUDE_MONGODBTOOLS" != "TRUE" ]; then \
77 - echo -e "\e[0;31;49mInvalid value for build argument INCLUDE_MONGODBTOOLS, possible values: yes/true\e[;0m"; exit 1; \
83 + echo -e "\e[0;31;49mInvalid value for build argument INCLUDE_MONGODBTOOLS, possible values: yes/true\e[;0m"; exit 1; \
84 fi
85
80 -RUN if ! [ -z "$INCLUDE_MONGODBTOOLS" ]; then apk add --no-cache mongodb-tools; fi
86 +RUN if ! [ -z "$INCLUDE_MONGODBTOOLS" ]; then \
87 + apk add --no-cache mongodb-tools; \
88 + fi
89
90 # copy files from builder-image
91 COPY --from=builder /opt/meshcentral/meshcentral /opt/meshcentral/meshcentral
84 -COPY ./docker/startup.sh ./startup.sh
92 +COPY ./docker/entrypoint.sh ./entrypoint.sh
93 COPY ./docker/config.json.template /opt/meshcentral/config.json.template
94
95 # install dependencies from package.json
96 RUN cd meshcentral && npm install
97
98 # NOTE: ALL MODULES MUST HAVE A VERSION NUMBER AND THE VERSION MUST MATCH THAT USED IN meshcentral.js mainStart()
91 -RUN if ! [ -z "$INCLUDE_MONGODBTOOLS" ]; then cd meshcentral && npm install mongodb@4.13.0 saslprep@1.0.3; fi
92 -RUN if ! [ -z "$PREINSTALL_LIBS" ] && [ "$PREINSTALL_LIBS" == "true" ]; then cd meshcentral && npm install ssh2@1.16.0 semver@7.5.4 nodemailer@6.9.15 image-size@1.1.1 wildleek@2.0.0 otplib@10.2.3 yubikeyotp@0.2.0; fi
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 + 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; \
105 + fi
106
107 EXPOSE 80 443 4433
108
@@ -99,4 +112,4 @@ VOLUME /opt/meshcentral/meshcentral-files
112 VOLUME /opt/meshcentral/meshcentral-web
113 VOLUME /opt/meshcentral/meshcentral-backups
114
102 -CMD ["bash", "/opt/meshcentral/startup.sh"]
115 +CMD ["bash", "/opt/meshcentral/entrypoint.sh"]
docker/entrypoint.sh renamed