Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.

Commit

Permalink
fix: mongosh for mongo >=6.0 provision.sh support
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielVZ96 committed Feb 28, 2024
1 parent 1fd52d1 commit c7b0715
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 3 deletions.
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ services:
# We use WiredTiger in all environments. In development environments we use small files
# to conserve disk space, and disable the journal for a minor performance gain.
# See https://docs.mongodb.com/v3.0/reference/program/mongod/#options for complete details.
command: mongod --nojournal --storageEngine wiredTiger
# --nojournal is not available in recent mongo versions, it's always enabled.
command: mongod --storageEngine wiredTiger
container_name: "edx.${COMPOSE_PROJECT_NAME:-devstack}.mongo"
hostname: mongo.devstack.edx
image: mongo:${MONGO_VERSION:-5.0.24}
Expand Down
9 changes: 8 additions & 1 deletion provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,19 @@ docker compose exec -T mysql80 bash -e -c "mysql -uroot mysql" < provision-mysql
# If necessary, ensure the MongoDB server is online and usable
# and create its users.
if needs_mongo "$to_provision_ordered"; then
set +e
MONGO_SHELL=$(docker-compose exec -T mongo which mongosh)
set -e
echo -e "${GREEN}Waiting for MongoDB...${NC}"
# mongo container and mongo process/shell inside the container
make dev.wait-for.mongo
echo -e "${GREEN}MongoDB ready.${NC}"
echo -e "${GREEN}Creating MongoDB users...${NC}"
docker compose exec -T mongo bash -e -c "mongo" < mongo-provision.js
if [ -z $MONGO_SHELL ]; then
docker-compose exec -T mongo bash -e -c "mongo" < mongo-provision.js;
else
docker-compose exec -T mongo bash -e -c "mongosh" < mongo-provision.js;
fi
else
echo -e "${GREEN}MongoDB preparation not required; skipping.${NC}"
fi
Expand Down
2 changes: 1 addition & 1 deletion upgrade_mongo_5_0.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -eu -o pipefail

# This script will upgrade a devstack that was previosly running Mongo DB 4.4 to MongoDB 5.0.24
# This script will upgrade a devstack that was previosly running Mongo DB 4.x to MongoDB 5.x

. scripts/colors.sh

Expand Down
31 changes: 31 additions & 0 deletions upgrade_mongo_6_0.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
set -eu -o pipefail

# This script will upgrade a devstack that was previosly running Mongo DB 5.x to MongoDB 6.x

. scripts/colors.sh

# Upgrade to mongo 6.0
export MONGO_VERSION=6.0.12

echo
echo -e "${GREEN}Restarting Mongo on version ${MONGO_VERSION}${NC}"
make dev.up.mongo
mongo_container="$(make --silent --no-print-directory dev.print-container.mongo)"

echo -e "${GREEN}Waiting for MongoDB...${NC}"
until docker exec "$mongo_container" mongosh --eval 'db.serverStatus()' &> /dev/null
do
printf "."
sleep 1
done

echo -e "${GREEN}MongoDB ready.${NC}"
MONGO_VERSION_LIVE=$(docker exec -it "$mongo_container" mongosh --quiet --eval "printjson(db.version())")
MONGO_VERSION_COMPAT=$(docker exec -it "$mongo_container" mongosh --quiet \
--eval "printjson(db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )['featureCompatibilityVersion'])")
echo -e "${GREEN}Mongo Server version: ${MONGO_VERSION_LIVE}${NC}"
echo -e "${GREEN}Mongo FeatureCompatibilityVersion version: ${MONGO_VERSION_COMPAT}${NC}"

echo -e "${GREEN}Upgrading FeatureCompatibilityVersion to 6.0${NC}"
docker exec -it "$mongo_container" mongosh --eval "db.adminCommand( { setFeatureCompatibilityVersion: \"6.0\" } )"
31 changes: 31 additions & 0 deletions upgrade_mongo_7_0.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
set -eu -o pipefail

# This script will upgrade a devstack that was previosly running Mongo DB 6.x to MongoDB 7.x

. scripts/colors.sh

# Upgrade to mongo 7.0
export MONGO_VERSION=7.0.5

echo
echo -e "${GREEN}Restarting Mongo on version ${MONGO_VERSION}${NC}"
make dev.up.mongo
mongo_container="$(make --silent --no-print-directory dev.print-container.mongo)"

echo -e "${GREEN}Waiting for MongoDB...${NC}"
until docker exec "$mongo_container" mongosh --eval 'db.serverStatus()' &> /dev/null
do
printf "."
sleep 1
done

echo -e "${GREEN}MongoDB ready.${NC}"
MONGO_VERSION_LIVE=$(docker exec -it "$mongo_container" mongosh --quiet --eval "printjson(db.version())")
MONGO_VERSION_COMPAT=$(docker exec -it "$mongo_container" mongosh --quiet \
--eval "printjson(db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )['featureCompatibilityVersion'])")
echo -e "${GREEN}Mongo Server version: ${MONGO_VERSION_LIVE}${NC}"
echo -e "${GREEN}Mongo FeatureCompatibilityVersion version: ${MONGO_VERSION_COMPAT}${NC}"

echo -e "${GREEN}Upgrading FeatureCompatibilityVersion to 7.0${NC}"
docker exec -it "$mongo_container" mongosh --eval "db.adminCommand( { setFeatureCompatibilityVersion: \"7.0\" } )"

0 comments on commit c7b0715

Please sign in to comment.