From 41c947a8f0baf60cb18061d8ce66682079790598 Mon Sep 17 00:00:00 2001 From: Maksim Shilov <89912354+shilovmaksim@users.noreply.github.com> Date: Wed, 10 Nov 2021 19:30:25 +0300 Subject: [PATCH] [Ubuntu] Pin MongoDB to the specific version defined in the toolset (#4447) --- images/linux/scripts/installers/mongodb.sh | 12 ++++++++---- images/linux/scripts/tests/Databases.Tests.ps1 | 3 ++- images/linux/toolsets/toolset-1804.json | 5 ++++- images/linux/toolsets/toolset-2004.json | 5 ++++- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/images/linux/scripts/installers/mongodb.sh b/images/linux/scripts/installers/mongodb.sh index fd7287c46..524a211c3 100644 --- a/images/linux/scripts/installers/mongodb.sh +++ b/images/linux/scripts/installers/mongodb.sh @@ -6,17 +6,21 @@ # Source the helpers source $HELPER_SCRIPTS/os.sh +source $HELPER_SCRIPTS/install.sh REPO_URL="https://repo.mongodb.org/apt/ubuntu" +osLabel=$(getOSVersionLabel) +toolsetVersion=$(get_toolset_value '.mongodb.version') +latestVersion=$(curl $REPO_URL/dists/$osLabel/mongodb-org/ | awk -F'>|<' '{print $3}' | grep "^$toolsetVersion" | tail -1) # Install Mongo DB -wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add - -version=$(getOSVersionLabel) -echo "deb [ arch=amd64,arm64 ] $REPO_URL $version/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list +wget -qO - https://www.mongodb.org/static/pgp/server-$latestVersion.asc | sudo apt-key add - + +echo "deb [ arch=amd64,arm64 ] $REPO_URL $osLabel/mongodb-org/$latestVersion multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-$latestVersion.list sudo apt-get update sudo apt-get install -y mongodb-org -rm /etc/apt/sources.list.d/mongodb-org-5.0.list +rm /etc/apt/sources.list.d/mongodb-org-$latestVersion.list echo "mongodb $REPO_URL" >> $HELPER_SCRIPTS/apt-sources.txt diff --git a/images/linux/scripts/tests/Databases.Tests.ps1 b/images/linux/scripts/tests/Databases.Tests.ps1 index 9259c5a8f..6477a04e9 100644 --- a/images/linux/scripts/tests/Databases.Tests.ps1 +++ b/images/linux/scripts/tests/Databases.Tests.ps1 @@ -3,7 +3,8 @@ Describe "MongoDB" { @{ ToolName = "mongo" } @{ ToolName = "mongod" } ) { - "$ToolName --version" | Should -ReturnZeroExitCode + $toolsetVersion = (Get-ToolsetContent).mongodb.version + (&$ToolName --version)[2].Split('"')[-2] | Should -BeLike "$toolsetVersion*" } } diff --git a/images/linux/toolsets/toolset-1804.json b/images/linux/toolsets/toolset-1804.json index a61977a6f..6f6887878 100644 --- a/images/linux/toolsets/toolset-1804.json +++ b/images/linux/toolsets/toolset-1804.json @@ -329,5 +329,8 @@ "name": "yarn", "command": "yarn" } - ] + ], + "mongodb": { + "version": "5" + } } diff --git a/images/linux/toolsets/toolset-2004.json b/images/linux/toolsets/toolset-2004.json index 11ff9178b..c6b297bb4 100644 --- a/images/linux/toolsets/toolset-2004.json +++ b/images/linux/toolsets/toolset-2004.json @@ -334,5 +334,8 @@ "name": "yarn", "command": "yarn" } - ] + ], + "mongodb": { + "version": "5" + } }