From 32cb93d1358d0ce8edaa07cd30f45067871d22a3 Mon Sep 17 00:00:00 2001 From: Prabhjot Singh Sethi Date: Mon, 7 Apr 2025 10:11:00 +0000 Subject: [PATCH] Enable Change streams for the dev mongodb deployment Signed-off-by: Prabhjot Singh Sethi --- scripts/.gitignore | 3 +++ scripts/mongod.conf | 4 ++++ scripts/run-mongodb-dev.sh | 21 ++++++++++++++++++++- 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 scripts/.gitignore create mode 100644 scripts/mongod.conf diff --git a/scripts/.gitignore b/scripts/.gitignore new file mode 100644 index 0000000..d7aac37 --- /dev/null +++ b/scripts/.gitignore @@ -0,0 +1,3 @@ +# generated key file, for mongodb auth +# avoid pushing to repo +mongod_key diff --git a/scripts/mongod.conf b/scripts/mongod.conf new file mode 100644 index 0000000..b0fa332 --- /dev/null +++ b/scripts/mongod.conf @@ -0,0 +1,4 @@ +security: + keyFile: /etc/mymongo/mongod_key +replication: + replSetName: "rs0" \ No newline at end of file diff --git a/scripts/run-mongodb-dev.sh b/scripts/run-mongodb-dev.sh index bd16a37..f7c3b6a 100755 --- a/scripts/run-mongodb-dev.sh +++ b/scripts/run-mongodb-dev.sh @@ -2,4 +2,23 @@ set -ex -sudo docker run -d --network host --name mongodb -e MONGO_INITDB_ROOT_USERNAME=root -e MONGO_INITDB_ROOT_PASSWORD=password mongo:8.0.6 +SCRIPT_DIR=$(dirname $0) + +if test -e "$SCRIPT_DIR/mongod.conf" +then + CONFIG_FLAG="--config /etc/mymongo/mongod.conf" + VOLUME_FLAG="-v $SCRIPT_DIR:/etc/mymongo" + + if test -e "$SCRIPT_DIR/mongod_key" + then + echo "skipping key generation" + else + openssl rand -base64 756 > $SCRIPT_DIR/mongod_key + chmod 400 $SCRIPT_DIR/mongod_key + fi + sudo chown 999:999 $SCRIPT_DIR/mongod_key +fi + +sudo docker run -d --network host --name mongodb ${VOLUME_FLAG} -e MONGO_INITDB_ROOT_USERNAME=root -e MONGO_INITDB_ROOT_PASSWORD=password mongo:8.0.6 ${CONFIG_FLAG} +sleep 10 +sudo docker exec -i mongodb mongosh -u root -p password --eval 'rs.initiate()'