[docker] added CONFIG_FILE environment variable to optionally use a different config.json file

Simon Schön committed Jul 23, 2022 at 13:21 UTC e913928d786c94755b3e12f0e683278abce793de
3 files changed +35 -27
.gitattributes new
+1
@@ -0,0 +1 @@
1 +*.sh text eol=lf
docker/Dockerfile
+19
@@ -48,6 +48,25 @@ RUN rm -rf /opt/meshcentral/meshcentral/node_modules
48 FROM base
49
50 ARG INCLUDE_MONGODBTOOLS=""
51 +
52 +# environment variables
53 +ENV NODE_ENV="production"
54 +ENV CONFIG_FILE="config.json"
55 +
56 +# environment variables for initial configuration file
57 +ENV USE_MONGODB="false"
58 +ENV MONGO_INITDB_ROOT_USERNAME="root"
59 +ENV MONGO_INITDB_ROOT_PASSWORD="pass"
60 +ENV HOSTNAME="localhost"
61 +ENV ALLOW_NEW_ACCOUNTS="true"
62 +ENV ALLOWPLUGINS="false"
63 +ENV LOCALSESSIONRECORDING="false"
64 +ENV MINIFY="true"
65 +ENV WEBRTC="false"
66 +ENV IFRAME="false"
67 +ENV REVERSE_PROXY="false"
68 +ENV REVERSE_PROXY_TLS_PORT=""
69 +
70 RUN if ! [ -z "$INCLUDE_MONGODBTOOLS" ] && [ "$INCLUDE_MONGODBTOOLS" != "yes" ] && [ "$INCLUDE_MONGODBTOOLS" != "YES" ] \
71 && [ "$INCLUDE_MONGODBTOOLS" != "true" ] && [ "$INCLUDE_MONGODBTOOLS" != "TRUE" ]; then \
72 echo -e "\e[0;31;49mInvalid value for build argument INCLUDE_MONGODBTOOLS, possible values: yes/true\e[;0m"; exit 1; \
docker/startup.sh
+15 -27
@@ -1,36 +1,24 @@
1 #!/bin/bash
2
3 -export NODE_ENV=production
4 -
5 -export HOSTNAME
6 -export REVERSE_PROXY
7 -export REVERSE_PROXY_TLS_PORT
8 -export IFRAME
9 -export ALLOW_NEW_ACCOUNTS
10 -export WEBRTC
11 -export MONGO_INITDB_ROOT_USERNAME
12 -export MONGO_INITDB_ROOT_PASSWORD
13 -export USE_MONGODB
14 -
15 -if [ -f "meshcentral-data/config.json" ]
3 +if [ -f "meshcentral-data/${CONFIG_FILE}" ]
4 then
17 - node meshcentral/meshcentral
5 + node meshcentral/meshcentral --configfile ${CONFIG_FILE}
6 else
19 - cp config.json.template meshcentral-data/config.json
7 + cp config.json.template meshcentral-data/${CONFIG_FILE}
8 if ! [ -z "$USE_MONGODB" ] && [ "$USE_MONGODB" == "true" ]; then
21 - sed -i "s/\"_mongoDb\": null/\"mongoDb\": \"mongodb:\/\/$MONGO_INITDB_ROOT_USERNAME:$MONGO_INITDB_ROOT_PASSWORD@mongodb:27017\"/" meshcentral-data/config.json
9 + sed -i "s/\"_mongoDb\": null/\"mongoDb\": \"mongodb:\/\/$MONGO_INITDB_ROOT_USERNAME:$MONGO_INITDB_ROOT_PASSWORD@mongodb:27017\"/" meshcentral-data/${CONFIG_FILE}
10 fi
23 - sed -i "s/\"cert\": \"myserver.mydomain.com\"/\"cert\": \"$HOSTNAME\"/" meshcentral-data/config.json
24 - sed -i "s/\"NewAccounts\": true/\"NewAccounts\": \"$ALLOW_NEW_ACCOUNTS\"/" meshcentral-data/config.json
25 - sed -i "s/\"enabled\": false/\"enabled\": \"$ALLOWPLUGINS\"/" meshcentral-data/config.json
26 - sed -i "s/\"localSessionRecording\": false/\"localSessionRecording\": \"$LOCALSESSIONRECORDING\"/" meshcentral-data/config.json
27 - sed -i "s/\"minify\": true/\"minify\": \"$MINIFY\"/" meshcentral-data/config.json
28 - sed -i "s/\"WebRTC\": false/\"WebRTC\": \"$WEBRTC\"/" meshcentral-data/config.json
29 - sed -i "s/\"AllowFraming\": false/\"AllowFraming\": \"$IFRAME\"/" meshcentral-data/config.json
11 + sed -i "s/\"cert\": \"myserver.mydomain.com\"/\"cert\": \"$HOSTNAME\"/" meshcentral-data/${CONFIG_FILE}
12 + sed -i "s/\"NewAccounts\": true/\"NewAccounts\": $ALLOW_NEW_ACCOUNTS/" meshcentral-data/${CONFIG_FILE}
13 + sed -i "s/\"enabled\": false/\"enabled\": $ALLOWPLUGINS/" meshcentral-data/${CONFIG_FILE}
14 + sed -i "s/\"localSessionRecording\": false/\"localSessionRecording\": $LOCALSESSIONRECORDING/" meshcentral-data/${CONFIG_FILE}
15 + sed -i "s/\"minify\": true/\"minify\": $MINIFY/" meshcentral-data/${CONFIG_FILE}
16 + sed -i "s/\"WebRTC\": false/\"WebRTC\": $WEBRTC/" meshcentral-data/${CONFIG_FILE}
17 + sed -i "s/\"AllowFraming\": false/\"AllowFraming\": $IFRAME/" meshcentral-data/${CONFIG_FILE}
18 if [ "$REVERSE_PROXY" != "false" ]; then
31 - sed -i "s/\"_certUrl\": \"my\.reverse\.proxy\"/\"certUrl\": \"https:\/\/$REVERSE_PROXY:$REVERSE_PROXY_TLS_PORT\"/" meshcentral-data/config.json
32 - node meshcentral/meshcentral
19 + sed -i "s/\"_certUrl\": \"my\.reverse\.proxy\"/\"certUrl\": \"https:\/\/$REVERSE_PROXY:$REVERSE_PROXY_TLS_PORT\"/" meshcentral-data/${CONFIG_FILE}
20 + node meshcentral/meshcentral --configfile ${CONFIG_FILE}
21 exit
22 fi
35 - node meshcentral/meshcentral --cert "$HOSTNAME"
36 -fi
\ No newline at end of file
23 + node meshcentral/meshcentral --configfile ${CONFIG_FILE} --cert "$HOSTNAME"
24 +fi