From 51ad698213ba20a0c0649ee9ffd9a3844fba7d4d Mon Sep 17 00:00:00 2001 From: Daan Date: Sun, 23 Mar 2025 22:45:09 +0100 Subject: [PATCH] Use jq with mongo. --- docker/BUILD.md | 29 ----------------------------- docker/entrypoint.sh | 6 ++++-- 2 files changed, 4 insertions(+), 31 deletions(-) delete mode 100644 docker/BUILD.md diff --git a/docker/BUILD.md b/docker/BUILD.md deleted file mode 100644 index 1b100795..00000000 --- a/docker/BUILD.md +++ /dev/null @@ -1,29 +0,0 @@ -# How to create a docker image for meshcentral - -``` -> git clone https://github.com/Ylianst/MeshCentral.git -> cd MeshCentral - -> docker build -f docker/Dockerfile --force-rm -t meshcentral . - -# alternative, if you want to include the mongodb-tools (mongodump, ...), you can add the 'INCLUDE_MONGODBTOOLS=yes' build argument -> docker build -f docker/Dockerfile --force-rm --build-arg INCLUDE_MONGODBTOOLS=yes -t meshcentral . - -# (optional) cleanup after docker build: -> cd .. -> rm -rf MeshCentral/ -``` - -> | Argument | Description | -> | :--- | :--- | -> | -f docker/Dockerfile | Path/Name of the Dockerfile | -> | --force-rm | Always remove intermediate containers | -> | -t meshcentral | Name and optionally a tag in the 'name:tag' format | - -### Optional build arguments -> | Argument | Description | -> | :--- | :--- | -> | 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/entrypoint.sh b/docker/entrypoint.sh index dd2bbe7d..2c7272b9 100644 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -35,9 +35,11 @@ if [[ "$DYNAMIC_CONFIG" =~ ^(true|yes)$ ]]; then MONGO_URL="${MONGO_URL:-$MONGO_USERNAME:$MONGO_PASS@}$MONGO_HOST:$MONGO_PORT" fi - ESCAPED_MONGO_URL=$(echo "$MONGO_URL" | sed 's/[\/&?=:]/\\&/g') + #ESCAPED_MONGO_URL=$(echo "$MONGO_URL" | sed 's/[\/&?=:]/\\&/g') sed -i 's/"_mongoDb"/"mongoDb"/' "$CONFIG_FILE" - sed -i "s/\"mongoDb\": *\"[^\"]*\"/\"mongoDb\": \"$ESCAPED_MONGO_URL\"/" "$CONFIG_FILE" + jq --arg mongo_url "$MONGO_URL" \ + '.settings.mongoDb = $mongo_url' \ + "$CONFIG_FILE" > temp_config.json && mv temp_config.json "$CONFIG_FILE" else echo "Disabling MongoDB-connector..." sed -i 's/"mongoDb"/"_mongoDb"/' "$CONFIG_FILE"