fix(docker): allow usage of external mongodb
tryao committed
Mar 8, 2023 at 11:30 UTC
d2d6e95dd95b91a022064ad060a59e61666cb28d
3 files changed
+37
-27
docker/Dockerfile
+1
@@ -58,6 +58,7 @@ ENV CONFIG_FILE="config.json"
58
ENV USE_MONGODB="false"
59
ENV MONGO_INITDB_ROOT_USERNAME="root"
60
ENV MONGO_INITDB_ROOT_PASSWORD="pass"
61
+ENV MONGO_URL=""
62
ENV HOSTNAME="localhost"
63
ENV ALLOW_NEW_ACCOUNTS="true"
64
ENV ALLOWPLUGINS="false"
docker/readme.md
+6
-3
@@ -13,11 +13,15 @@
13
# Templates
14
15
## .env
16
+You can place the `config.json` file directly under `./meshcentral/data/`, or use the following `.env` file instead.
17
18
```ini
19
NODE_ENV=production
20
20
-# initial mongodb-variables
21
+USE_MONGODB=false
22
+# set already exist mongo connection string url here
23
+MONGO_URL=
24
+# or set following init params for new mongodb, use it with docker-compose file with mongodb version
25
MONGO_INITDB_ROOT_USERNAME=mongodbadmin
26
MONGO_INITDB_ROOT_PASSWORD=mongodbpasswd
27
@@ -26,8 +30,7 @@ MONGO_INITDB_ROOT_PASSWORD=mongodbpasswd
30
31
# your hostname
32
HOSTNAME=my.domain.com
29
-USE_MONGODB=false
30
-# set to your reverse proxy IP if you want to put meshcentral behind a reverse proxy
33
+# set to your reverse proxy IP if you want to put meshcentral behind a reverse proxy
34
REVERSE_PROXY=false
35
REVERSE_PROXY_TLS_PORT=
36
# set to true if you wish to enable iframe support
docker/startup.sh
+30
-24
@@ -1,28 +1,34 @@
1
#!/bin/bash
2
3
-if [ -f "meshcentral-data/${CONFIG_FILE}" ]
4
- then
5
- node meshcentral/meshcentral --configfile ${CONFIG_FILE}
6
- else
7
- cp config.json.template meshcentral-data/${CONFIG_FILE}
8
- if ! [ -z "$USE_MONGODB" ] && [ "$USE_MONGODB" == "true" ]; then
9
- sed -i "s/\"_mongoDb\": null/\"mongoDb\": \"mongodb:\/\/$MONGO_INITDB_ROOT_USERNAME:$MONGO_INITDB_ROOT_PASSWORD@mongodb:27017\"/" meshcentral-data/${CONFIG_FILE}
3
+if [ -f "meshcentral-data/${CONFIG_FILE}" ]; then
4
+ node meshcentral/meshcentral --configfile "${CONFIG_FILE}"
5
+else
6
+ cp config.json.template meshcentral-data/"${CONFIG_FILE}"
7
+ if [ -n "$USE_MONGODB" ] && [ "$USE_MONGODB" == "true" ]; then
8
+ if [ -z "$MONGO_URL" ]; then
9
+ prefix=""
10
+ if [ -n "$MONGO_INITDB_ROOT_USERNAME" ] && [ -n "$MONGO_INITDB_ROOT_PASSWORD" ]; then
11
+ prefix="$MONGO_INITDB_ROOT_USERNAME:$MONGO_INITDB_ROOT_PASSWORD@"
12
+ fi
13
+ MONGO_URL="${prefix}mongodb:27017"
14
fi
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 [ -z "$SESSION_KEY" ]; then
19
- SESSION_KEY="$(cat /dev/urandom | tr -dc 'A-Za-z0-9!#$%&()*+,-./:;<=>?@[\]^_`{|}~' | fold -w 32 | head -n 1)";
20
- fi
21
- sed -i "s/\"_sessionKey\": \"MyReallySecretPassword1\"/\"sessionKey\": \"$SESSION_KEY\"/" meshcentral-data/${CONFIG_FILE}
22
- if [ "$REVERSE_PROXY" != "false" ]; then
23
- sed -i "s/\"_certUrl\": \"my\.reverse\.proxy\"/\"certUrl\": \"https:\/\/$REVERSE_PROXY:$REVERSE_PROXY_TLS_PORT\"/" meshcentral-data/${CONFIG_FILE}
24
- node meshcentral/meshcentral --configfile ${CONFIG_FILE}
25
- exit
26
- fi
27
- node meshcentral/meshcentral --configfile ${CONFIG_FILE} --cert "$HOSTNAME"
15
+ sed -i "s/\"_mongoDb\": null/\"mongoDb\": \"mongodb:\/\/$MONGO_URL\"/" meshcentral-data/"${CONFIG_FILE}"
16
+ fi
17
+ sed -i "s/\"cert\": \"myserver.mydomain.com\"/\"cert\": \"$HOSTNAME\"/" meshcentral-data/"${CONFIG_FILE}"
18
+ sed -i "s/\"NewAccounts\": true/\"NewAccounts\": $ALLOW_NEW_ACCOUNTS/" meshcentral-data/"${CONFIG_FILE}"
19
+ sed -i "s/\"enabled\": false/\"enabled\": $ALLOWPLUGINS/" meshcentral-data/"${CONFIG_FILE}"
20
+ sed -i "s/\"localSessionRecording\": false/\"localSessionRecording\": $LOCALSESSIONRECORDING/" meshcentral-data/"${CONFIG_FILE}"
21
+ sed -i "s/\"minify\": true/\"minify\": $MINIFY/" meshcentral-data/"${CONFIG_FILE}"
22
+ sed -i "s/\"WebRTC\": false/\"WebRTC\": $WEBRTC/" meshcentral-data/"${CONFIG_FILE}"
23
+ sed -i "s/\"AllowFraming\": false/\"AllowFraming\": $IFRAME/" meshcentral-data/"${CONFIG_FILE}"
24
+ if [ -z "$SESSION_KEY" ]; then
25
+ SESSION_KEY="$(cat /dev/urandom | tr -dc 'A-Za-z0-9!#$%&()*+,-./:;<=>?@[\]^_`{|}~' | fold -w 32 | head -n 1)"
26
+ fi
27
+ sed -i "s/\"_sessionKey\": \"MyReallySecretPassword1\"/\"sessionKey\": \"$SESSION_KEY\"/" meshcentral-data/"${CONFIG_FILE}"
28
+ if [ "$REVERSE_PROXY" != "false" ]; then
29
+ sed -i "s/\"_certUrl\": \"my\.reverse\.proxy\"/\"certUrl\": \"https:\/\/$REVERSE_PROXY:$REVERSE_PROXY_TLS_PORT\"/" meshcentral-data/"${CONFIG_FILE}"
30
+ node meshcentral/meshcentral --configfile "${CONFIG_FILE}"
31
+ exit
32
+ fi
33
+ node meshcentral/meshcentral --configfile "${CONFIG_FILE}" --cert "$HOSTNAME"
34
fi