From e913928d786c94755b3e12f0e683278abce793de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Sch=C3=B6n?= Date: Sat, 23 Jul 2022 13:21:19 +0200 Subject: [PATCH] [docker] added CONFIG_FILE environment variable to optionally use a different config.json file --- .gitattributes | 1 + docker/Dockerfile | 19 +++++++++++++++++++ docker/startup.sh | 42 +++++++++++++++--------------------------- 3 files changed, 35 insertions(+), 27 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..8cd5aff5 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.sh text eol=lf diff --git a/docker/Dockerfile b/docker/Dockerfile index 9335595e..87e078ea 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -48,6 +48,25 @@ RUN rm -rf /opt/meshcentral/meshcentral/node_modules FROM base ARG INCLUDE_MONGODBTOOLS="" + +# environment variables +ENV NODE_ENV="production" +ENV CONFIG_FILE="config.json" + +# environment variables for initial configuration file +ENV USE_MONGODB="false" +ENV MONGO_INITDB_ROOT_USERNAME="root" +ENV MONGO_INITDB_ROOT_PASSWORD="pass" +ENV HOSTNAME="localhost" +ENV ALLOW_NEW_ACCOUNTS="true" +ENV ALLOWPLUGINS="false" +ENV LOCALSESSIONRECORDING="false" +ENV MINIFY="true" +ENV WEBRTC="false" +ENV IFRAME="false" +ENV REVERSE_PROXY="false" +ENV REVERSE_PROXY_TLS_PORT="" + RUN if ! [ -z "$INCLUDE_MONGODBTOOLS" ] && [ "$INCLUDE_MONGODBTOOLS" != "yes" ] && [ "$INCLUDE_MONGODBTOOLS" != "YES" ] \ && [ "$INCLUDE_MONGODBTOOLS" != "true" ] && [ "$INCLUDE_MONGODBTOOLS" != "TRUE" ]; then \ echo -e "\e[0;31;49mInvalid value for build argument INCLUDE_MONGODBTOOLS, possible values: yes/true\e[;0m"; exit 1; \ diff --git a/docker/startup.sh b/docker/startup.sh index 2510d033..b34a5bdb 100644 --- a/docker/startup.sh +++ b/docker/startup.sh @@ -1,36 +1,24 @@ #!/bin/bash -export NODE_ENV=production - -export HOSTNAME -export REVERSE_PROXY -export REVERSE_PROXY_TLS_PORT -export IFRAME -export ALLOW_NEW_ACCOUNTS -export WEBRTC -export MONGO_INITDB_ROOT_USERNAME -export MONGO_INITDB_ROOT_PASSWORD -export USE_MONGODB - -if [ -f "meshcentral-data/config.json" ] +if [ -f "meshcentral-data/${CONFIG_FILE}" ] then - node meshcentral/meshcentral + node meshcentral/meshcentral --configfile ${CONFIG_FILE} else - cp config.json.template meshcentral-data/config.json + cp config.json.template meshcentral-data/${CONFIG_FILE} if ! [ -z "$USE_MONGODB" ] && [ "$USE_MONGODB" == "true" ]; then - sed -i "s/\"_mongoDb\": null/\"mongoDb\": \"mongodb:\/\/$MONGO_INITDB_ROOT_USERNAME:$MONGO_INITDB_ROOT_PASSWORD@mongodb:27017\"/" meshcentral-data/config.json + sed -i "s/\"_mongoDb\": null/\"mongoDb\": \"mongodb:\/\/$MONGO_INITDB_ROOT_USERNAME:$MONGO_INITDB_ROOT_PASSWORD@mongodb:27017\"/" meshcentral-data/${CONFIG_FILE} fi - sed -i "s/\"cert\": \"myserver.mydomain.com\"/\"cert\": \"$HOSTNAME\"/" meshcentral-data/config.json - sed -i "s/\"NewAccounts\": true/\"NewAccounts\": \"$ALLOW_NEW_ACCOUNTS\"/" meshcentral-data/config.json - sed -i "s/\"enabled\": false/\"enabled\": \"$ALLOWPLUGINS\"/" meshcentral-data/config.json - sed -i "s/\"localSessionRecording\": false/\"localSessionRecording\": \"$LOCALSESSIONRECORDING\"/" meshcentral-data/config.json - sed -i "s/\"minify\": true/\"minify\": \"$MINIFY\"/" meshcentral-data/config.json - sed -i "s/\"WebRTC\": false/\"WebRTC\": \"$WEBRTC\"/" meshcentral-data/config.json - sed -i "s/\"AllowFraming\": false/\"AllowFraming\": \"$IFRAME\"/" meshcentral-data/config.json + sed -i "s/\"cert\": \"myserver.mydomain.com\"/\"cert\": \"$HOSTNAME\"/" meshcentral-data/${CONFIG_FILE} + sed -i "s/\"NewAccounts\": true/\"NewAccounts\": $ALLOW_NEW_ACCOUNTS/" meshcentral-data/${CONFIG_FILE} + sed -i "s/\"enabled\": false/\"enabled\": $ALLOWPLUGINS/" meshcentral-data/${CONFIG_FILE} + sed -i "s/\"localSessionRecording\": false/\"localSessionRecording\": $LOCALSESSIONRECORDING/" meshcentral-data/${CONFIG_FILE} + sed -i "s/\"minify\": true/\"minify\": $MINIFY/" meshcentral-data/${CONFIG_FILE} + sed -i "s/\"WebRTC\": false/\"WebRTC\": $WEBRTC/" meshcentral-data/${CONFIG_FILE} + sed -i "s/\"AllowFraming\": false/\"AllowFraming\": $IFRAME/" meshcentral-data/${CONFIG_FILE} if [ "$REVERSE_PROXY" != "false" ]; then - sed -i "s/\"_certUrl\": \"my\.reverse\.proxy\"/\"certUrl\": \"https:\/\/$REVERSE_PROXY:$REVERSE_PROXY_TLS_PORT\"/" meshcentral-data/config.json - node meshcentral/meshcentral + sed -i "s/\"_certUrl\": \"my\.reverse\.proxy\"/\"certUrl\": \"https:\/\/$REVERSE_PROXY:$REVERSE_PROXY_TLS_PORT\"/" meshcentral-data/${CONFIG_FILE} + node meshcentral/meshcentral --configfile ${CONFIG_FILE} exit fi - node meshcentral/meshcentral --cert "$HOSTNAME" -fi \ No newline at end of file + node meshcentral/meshcentral --configfile ${CONFIG_FILE} --cert "$HOSTNAME" +fi