From 705f4d6f472aa3efcc1064cce8eb5c2ac809b526 Mon Sep 17 00:00:00 2001 From: quelist Date: Thu, 28 Nov 2024 12:54:54 +0530 Subject: [PATCH] Add MongoDB shell version detection to before scripts Update before_script.sh and before_script_docker.sh to automatically detect and use the appropriate MongoDB shell command (mongo or mongosh) based on availability. This ensures compatibility with both: - Legacy MongoDB versions using 'mongo' shell - Modern MongoDB versions (5.0+) using 'mongosh' The scripts now: - Check for command availability - Use the appropriate shell - Exit with helpful error if no shell is found --- bin/ci/before_script.sh | 18 ++++++++++++++---- bin/ci/before_script_docker.sh | 18 ++++++++++++++---- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/bin/ci/before_script.sh b/bin/ci/before_script.sh index fae6dd8..6967877 100755 --- a/bin/ci/before_script.sh +++ b/bin/ci/before_script.sh @@ -1,8 +1,18 @@ #!/bin/sh +# Check which MongoDB shell is available +if command -v mongosh >/dev/null 2>&1; then + MONGO_SHELL="mongosh" +elif command -v mongo >/dev/null 2>&1; then + MONGO_SHELL="mongo" +else + echo "Error: Neither mongo nor mongosh shell found. Please install MongoDB shell." + exit 1 +fi + # MongoDB Java driver won't run authentication twice on the same DB instance, # so we need to use multiple DBs. -mongo --eval 'db.createUser({"user": "clojurewerkz/monger", "pwd": "monger", roles: ["dbAdmin"], mechanisms: ["SCRAM-SHA-1"], passwordDigestor: "client"})' monger-test -mongo --eval 'db.createUser({"user": "clojurewerkz/monger", "pwd": "monger", roles: ["dbAdmin"], mechanisms: ["SCRAM-SHA-1"], passwordDigestor: "client"})' monger-test2 -mongo --eval 'db.createUser({"user": "clojurewerkz/monger", "pwd": "monger", roles: ["dbAdmin"], mechanisms: ["SCRAM-SHA-1"], passwordDigestor: "client"})' monger-test3 -mongo --eval 'db.createUser({"user": "clojurewerkz/monger", "pwd": "monger", roles: ["dbAdmin"], mechanisms: ["SCRAM-SHA-1"], passwordDigestor: "client"})' monger-test4 +$MONGO_SHELL --eval 'db.createUser({"user": "clojurewerkz/monger", "pwd": "monger", roles: ["dbAdmin"], mechanisms: ["SCRAM-SHA-1"], passwordDigestor: "client"})' monger-test +$MONGO_SHELL --eval 'db.createUser({"user": "clojurewerkz/monger", "pwd": "monger", roles: ["dbAdmin"], mechanisms: ["SCRAM-SHA-1"], passwordDigestor: "client"})' monger-test2 +$MONGO_SHELL --eval 'db.createUser({"user": "clojurewerkz/monger", "pwd": "monger", roles: ["dbAdmin"], mechanisms: ["SCRAM-SHA-1"], passwordDigestor: "client"})' monger-test3 +$MONGO_SHELL --eval 'db.createUser({"user": "clojurewerkz/monger", "pwd": "monger", roles: ["dbAdmin"], mechanisms: ["SCRAM-SHA-1"], passwordDigestor: "client"})' monger-test4 \ No newline at end of file diff --git a/bin/ci/before_script_docker.sh b/bin/ci/before_script_docker.sh index 3cca428..42086e3 100755 --- a/bin/ci/before_script_docker.sh +++ b/bin/ci/before_script_docker.sh @@ -1,8 +1,18 @@ #!/bin/sh +# Check which MongoDB shell is available in the container +if docker exec mongo_test which mongosh >/dev/null 2>&1; then + MONGO_SHELL="mongosh" +elif docker exec mongo_test which mongo >/dev/null 2>&1; then + MONGO_SHELL="mongo" +else + echo "Error: Neither mongo nor mongosh shell found in the container." + exit 1 +fi + # MongoDB Java driver won't run authentication twice on the same DB instance, # so we need to use multiple DBs. -docker exec mongo_test mongosh --eval 'db.createUser({"user": "clojurewerkz/monger", "pwd": "monger", roles: ["dbAdmin"], mechanisms: ["SCRAM-SHA-1"], passwordDigestor: "client"})' monger-test -docker exec mongo_test mongosh --eval 'db.createUser({"user": "clojurewerkz/monger", "pwd": "monger", roles: ["dbAdmin"], mechanisms: ["SCRAM-SHA-1"], passwordDigestor: "client"})' monger-test2 -docker exec mongo_test mongosh --eval 'db.createUser({"user": "clojurewerkz/monger", "pwd": "monger", roles: ["dbAdmin"], mechanisms: ["SCRAM-SHA-1"], passwordDigestor: "client"})' monger-test3 -docker exec mongo_test mongosh --eval 'db.createUser({"user": "clojurewerkz/monger", "pwd": "monger", roles: ["dbAdmin"], mechanisms: ["SCRAM-SHA-1"], passwordDigestor: "client"})' monger-test4 +docker exec mongo_test $MONGO_SHELL --eval 'db.createUser({"user": "clojurewerkz/monger", "pwd": "monger", roles: ["dbAdmin"], mechanisms: ["SCRAM-SHA-1"], passwordDigestor: "client"})' monger-test +docker exec mongo_test $MONGO_SHELL --eval 'db.createUser({"user": "clojurewerkz/monger", "pwd": "monger", roles: ["dbAdmin"], mechanisms: ["SCRAM-SHA-1"], passwordDigestor: "client"})' monger-test2 +docker exec mongo_test $MONGO_SHELL --eval 'db.createUser({"user": "clojurewerkz/monger", "pwd": "monger", roles: ["dbAdmin"], mechanisms: ["SCRAM-SHA-1"], passwordDigestor: "client"})' monger-test3 +docker exec mongo_test $MONGO_SHELL --eval 'db.createUser({"user": "clojurewerkz/monger", "pwd": "monger", roles: ["dbAdmin"], mechanisms: ["SCRAM-SHA-1"], passwordDigestor: "client"})' monger-test4 \ No newline at end of file