diff --git a/docker/Dockerfile b/docker/Dockerfile index f95bdf09..c10a7a4c 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -11,27 +11,41 @@ RUN apk add --no-cache bash FROM base AS builder -ARG DISABLE_TRANSLATE="" ARG DISABLE_MINIFY="" +ARG DISABLE_TRANSLATE="" RUN mkdir /opt/meshcentral/meshcentral COPY ./ /opt/meshcentral/meshcentral/ -# Extract all MeshCentral strings from web pages and generate the languages.json file. - first try throws Error: Cannot find module 'jsdom' -RUN cd meshcentral/translate && node translate.js extractall; exit 0; -RUN cd meshcentral/translate && node translate.js extractall +RUN if ! [ -z "$DISABLE_MINIFY" ] && [ "$DISABLE_MINIFY" != "yes" ] && [ "$DISABLE_MINIFY" != "YES" ] \ + && [ "$DISABLE_MINIFY" != "true" ] && [ "$DISABLE_MINIFY" != "TRUE" ]; then \ + echo -e "\e[0;31;49mInvalid value for build argument DISABLE_MINIFY, possible values: yes/true\e[;0m"; exit 1; \ + fi +RUN if ! [ -z "$DISABLE_TRANSLATE" ] && [ "$DISABLE_TRANSLATE" != "yes" ] && [ "$DISABLE_TRANSLATE" != "YES" ] \ + && [ "$DISABLE_TRANSLATE" != "true" ] && [ "$DISABLE_TRANSLATE" != "TRUE" ]; then \ + echo -e "\e[0;31;49mInvalid value for build argument DISABLE_TRANSLATE, possible values: yes/true\e[;0m"; exit 1; \ + fi + +# first try throws Error: Cannot find module 'jsdom' +RUN if [ -z "$DISABLE_MINIFY" ] || [ -z "$DISABLE_TRANSLATE" ]; then cd meshcentral/translate && node translate.js extractall; exit 0; fi # minify files -RUN if [ "$DISABLE_MINIFY" != "yes" ] && [ "$DISABLE_MINIFY" != "YES" ]; then cd meshcentral/translate && node translate.js minifyall; fi +RUN if [ -z "$DISABLE_MINIFY" ]; then cd meshcentral/translate && node translate.js minifyall; fi # translate -RUN if [ "$DISABLE_TRANSLATE" != "yes" ] && [ "$DISABLE_TRANSLATE" != "YES" ]; then cd meshcentral/translate && node translate.js translateall; fi +RUN if [ -z "$DISABLE_TRANSLATE" ]; then cd meshcentral/translate && node translate.js extractall; fi +RUN if [ -z "$DISABLE_TRANSLATE" ]; then cd meshcentral/translate && node translate.js translateall; fi FROM base ARG INCLUDE_MONGODBTOOLS="" -RUN if [ "$INCLUDE_MONGODBTOOLS" == "yes" ] || [ "$INCLUDE_MONGODBTOOLS" == "YES" ]; then apk add --no-cache mongodb-tools; fi +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; \ + fi + +RUN if ! [ -z "$INCLUDE_MONGODBTOOLS" ]; then apk add --no-cache mongodb-tools; fi # copy files from builder-image COPY --from=builder /opt/meshcentral/meshcentral /opt/meshcentral/meshcentral diff --git a/docker/docker.build.sh b/docker/docker.build.sh index 18eef84b..ddbc1b12 100644 --- a/docker/docker.build.sh +++ b/docker/docker.build.sh @@ -3,13 +3,16 @@ MSG=""; PRUNE="false"; +LOG_FILE="" +#LOG_FILE="$(dirname -- "$( readlink -f -- "$0"; )")/build.log"; + function appendOutput() { if [ -z "${MSG}" ]; then echo -e "\n" > /dev/tty; fi ARGS=$@; - LINE="${ARGS}\n" - echo -e "${LINE}" > /dev/tty; + LINE="${ARGS}\n"; + if [ -z "${LOG_FILE}" ]; then echo -e "${LINE}" > /dev/tty; else echo -e "${LINE}" &>> "${LOG_FILE}"; fi MSG="${MSG}${LINE}"; } @@ -24,7 +27,7 @@ function runDockerBuild() BUILD_CMD="docker build -f docker/Dockerfile --force-rm --no-cache ${ARGS} -t meshcentral ."; appendOutput "Current build: ${BUILD_CMD}"; - ${BUILD_CMD}; + if [ -z "${LOG_FILE}" ]; then ${BUILD_CMD}; else ${BUILD_CMD} &>> "${LOG_FILE}"; fi if [ $? -ne 0 ]; then exit $?; fi ENDTS=$(date +%s); @@ -42,15 +45,12 @@ function runDockerBuild() else appendOutput "\tBuild time: ${DIFSEC} sec"; fi IMG_SIZE=$(docker image inspect meshcentral | grep -e "\"Size\"" | tr -d '",' | sed -E "s/\s*Size:\s*//"); - expr $IMG_SIZE + 0; - appendOutput "\tImage size: ${IMG_SIZE} ($((${IMG_SIZE}/1024/1024))M)"; - - appendOutput "\n"; + expr $IMG_SIZE + 0 > /dev/null; + appendOutput "\tImage size: ${IMG_SIZE} ($((${IMG_SIZE}/1024/1024))M)\n"; return 0; } - parent_path=$(dirname -- $(dirname -- "$( readlink -f -- "$0"; )")); if [ "${parent_path}" != "$(pwd -P)" ]; then echo -e "change working directory to: ${parent_path}" > /dev/tty; @@ -59,17 +59,17 @@ fi if ! [ -z $1 ] && [ "${1}" == "prune" ]; then PRUNE="true"; fi -runDockerBuild; -#runDockerBuild --build-arg DISABLE_MINIFY=yes; -#runDockerBuild --build-arg DISABLE_TRANSLATE=yes; #runDockerBuild --build-arg DISABLE_MINIFY=yes --build-arg DISABLE_TRANSLATE=yes; +#runDockerBuild --build-arg DISABLE_TRANSLATE=yes; +#runDockerBuild --build-arg DISABLE_MINIFY=yes; +runDockerBuild; -#runDockerBuild --build-arg INCLUDE_MONGOTOOLS=yes; -#runDockerBuild --build-arg INCLUDE_MONGOTOOLS=yes --build-arg DISABLE_MINIFY=yes; -#runDockerBuild --build-arg INCLUDE_MONGOTOOLS=yes --build-arg DISABLE_TRANSLATE=yes; -#runDockerBuild --build-arg INCLUDE_MONGOTOOLS=yes --build-arg DISABLE_MINIFY=yes --build-arg DISABLE_TRANSLATE=yes; +#runDockerBuild --build-arg INCLUDE_MONGODBTOOLS=yes --build-arg DISABLE_MINIFY=yes --build-arg DISABLE_TRANSLATE=yes; +#runDockerBuild --build-arg INCLUDE_MONGODBTOOLS=yes --build-arg DISABLE_TRANSLATE=yes; +#runDockerBuild --build-arg INCLUDE_MONGODBTOOLS=yes --build-arg DISABLE_MINIFY=yes; +#runDockerBuild --build-arg INCLUDE_MONGODBTOOLS=yes; echo ""; -echo -e $MSG; +echo -e "${MSG}"; exit 0; diff --git a/docker/readme.md b/docker/readme.md index ea0d09e9..c79d538b 100644 --- a/docker/readme.md +++ b/docker/readme.md @@ -24,7 +24,7 @@ ### Optional build arguments > | Argument | Description | > | :--- | :--- | -> | INCLUDE_MONGOTOOLS=yes | Includes mongodb-tools (mongodump, ...) in the image | +> | INCLUDE_MONGODBTOOLS=yes | Includes mongodb-tools (mongodump, ...) in the image | > | DISABLE_MINIFY=yes | Disables the minification of files | > | DISABLE_TRANSLATE=yes | Disables the translation of files | diff --git a/docker/startup.sh b/docker/startup.sh index 62b14c47..2510d033 100644 --- a/docker/startup.sh +++ b/docker/startup.sh @@ -17,7 +17,7 @@ if [ -f "meshcentral-data/config.json" ] node meshcentral/meshcentral else cp config.json.template meshcentral-data/config.json - if [ $USE_MONGODB == true ]; then + 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 fi sed -i "s/\"cert\": \"myserver.mydomain.com\"/\"cert\": \"$HOSTNAME\"/" meshcentral-data/config.json