diff --git a/Makefile b/Makefile index bf0985bb21b..398340bd9e5 100644 --- a/Makefile +++ b/Makefile @@ -87,6 +87,7 @@ 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 @@ -94,8 +95,6 @@ upgrade_mongodb: $(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({ @@ -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)" } @@ -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 ;; diff --git a/bin/docker-compose b/bin/docker-compose index 46565c25e4b..bff55947c23 100755 --- a/bin/docker-compose +++ b/bin/docker-compose @@ -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 diff --git a/docker-compose.yml b/docker-compose.yml index 49c52a41a07..83cbf5085b7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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'