Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: upgrade MongoDB to 7.0.2 release #3197

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,14 @@ upgrade_mongodb:
start_mongodb() {
# Convert version to suitable format for 'setFeatureCompatibilityVersion'
SERIES_VERSION=$$(echo $$1 | sed 's,\.[0-9]\+$$,,g')
MAJOR_VERSION=$$(echo $$1 | cut -d. -f1)

export EXTRA_COMPOSE_FILE=$$(mktemp)
echo "$$COMPOSE_TEMPLATE" | sed "s,_VERSION_,$$1,g" > $$EXTRA_COMPOSE_FILE

$(DOCKER_COMPOSE) stop mongo
$(DOCKER_COMPOSE) up -d mongo

wait_for_mongo

# Command used to set compatibility version
MONGO_SET_COMPAT_VERSION_CMD=$$(cat <<-EOF
db.adminCommand({
Expand All @@ -104,6 +103,23 @@ upgrade_mongodb:
EOF
)

# The legacy mongo shell is removed from MongoDB 6.0. The replacement is mongosh
if [ $$MAJOR_VERSION -ge 6 ]; then
$(DOCKER_COMPOSE) exec mongo ln -sf /usr/bin/mongosh /usr/bin/mongo
fi

if [ $$MAJOR_VERSION -ge 7 ]; then
MONGO_SET_COMPAT_VERSION_CMD=$$(cat <<-EOF
db.adminCommand({
setFeatureCompatibilityVersion: '$$SERIES_VERSION',
confirm: true
})
EOF
)
fi

wait_for_mongo

$(DOCKER_COMPOSE) exec mongo mongo --quiet --eval "quit($${MONGO_SET_COMPAT_VERSION_CMD}.ok ? 0 : 1)"
}

Expand Down Expand Up @@ -164,6 +180,18 @@ upgrade_mongodb:
start_mongodb 4.4.8
;;
4.4*)
echo "Upgrading MongoDB from 4.4-series to 5.0-series..."
start_mongodb 5.0.6
;;
5.0*)
echo "Upgrading MongoDB from 5.0-series to 6.0-series..."
start_mongodb 6.0.2
;;
6.0*)
echo "Upgrading MongoDB from 6.0-series to 7.0-series..."
start_mongodb 7.0.2
;;
7.0*)
echo "MongoDB upgrade successful!"
break
;;
Expand Down
2 changes: 1 addition & 1 deletion bin/docker-compose
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ set -o allexport

env_override=${ENV_OVERRIDE:-./.env.override}
if [ -f "$env_override" ]; then
echo "INFO: Loading $env_override"
echo "INFO: Loading $env_override" 1>&2;
. "$env_override"
fi

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ services:
networks:
- shellhub
mongo:
image: mongo:4.4.8
image: mongo:7.0.2
restart: unless-stopped
healthcheck:
test: 'test $$(echo "rs.initiate({ _id: ''rs'', members: [ { _id: 0, host: ''mongo:27017'' } ] }).ok || rs.status().ok" | mongo --quiet) -eq 1'
Expand Down