Skip to content

Commit 79d774e

Browse files
authored
ci(NODE-5090): download node to local directory (#3591)
1 parent 2d3576b commit 79d774e

File tree

8 files changed

+116
-124
lines changed

8 files changed

+116
-124
lines changed

.evergreen/config.in.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ functions:
138138
MONGODB_URI="${MONGODB_URI}" \
139139
AUTH=${AUTH} SSL=${SSL} TEST_CSFLE=true \
140140
MONGODB_API_VERSION="${MONGODB_API_VERSION}" \
141-
NODE_VERSION=${NODE_VERSION} SKIP_DEPS=${SKIP_DEPS|1} \
141+
SKIP_DEPS=${SKIP_DEPS|1} \
142142
bash ${PROJECT_DIRECTORY}/.evergreen/run-tests.sh
143143
144144
"run serverless tests":
@@ -238,7 +238,6 @@ functions:
238238
AUTH=${AUTH} \
239239
SSL=${SSL} \
240240
MONGODB_API_VERSION="${MONGODB_API_VERSION}" \
241-
NODE_VERSION=${NODE_VERSION} \
242241
SINGLE_MONGOS_LB_URI="${SINGLE_MONGOS_LB_URI}" \
243242
MULTI_MONGOS_LB_URI="${MULTI_MONGOS_LB_URI}" \
244243
TOPOLOGY="${TOPOLOGY}" \
@@ -259,7 +258,6 @@ functions:
259258
AUTH=${AUTH} \
260259
SSL=${SSL} \
261260
MONGODB_API_VERSION="${MONGODB_API_VERSION}" \
262-
NODE_VERSION=${NODE_VERSION} \
263261
TOPOLOGY="${TOPOLOGY}" \
264262
COMPRESSOR="${COMPRESSOR}" \
265263
SKIP_DEPS=${SKIP_DEPS|1} \
@@ -404,9 +402,6 @@ functions:
404402
${PREPARE_SHELL}
405403
NODE_LTS_NAME=${NODE_LTS_NAME} NPM_OPTIONS=${NPM_OPTIONS}\
406404
bash ${PROJECT_DIRECTORY}/.evergreen/install-dependencies.sh
407-
- command: expansions.update
408-
params:
409-
file: src/deps-expansion.yml
410405
411406
"run atlas tests":
412407
- command: shell.exec

.evergreen/config.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ functions:
112112
MONGODB_URI="${MONGODB_URI}" \
113113
AUTH=${AUTH} SSL=${SSL} TEST_CSFLE=true \
114114
MONGODB_API_VERSION="${MONGODB_API_VERSION}" \
115-
NODE_VERSION=${NODE_VERSION} SKIP_DEPS=${SKIP_DEPS|1} \
115+
SKIP_DEPS=${SKIP_DEPS|1} \
116116
bash ${PROJECT_DIRECTORY}/.evergreen/run-tests.sh
117117
run serverless tests:
118118
- command: timeout.update
@@ -208,7 +208,6 @@ functions:
208208
AUTH=${AUTH} \
209209
SSL=${SSL} \
210210
MONGODB_API_VERSION="${MONGODB_API_VERSION}" \
211-
NODE_VERSION=${NODE_VERSION} \
212211
SINGLE_MONGOS_LB_URI="${SINGLE_MONGOS_LB_URI}" \
213212
MULTI_MONGOS_LB_URI="${MULTI_MONGOS_LB_URI}" \
214213
TOPOLOGY="${TOPOLOGY}" \
@@ -228,7 +227,6 @@ functions:
228227
AUTH=${AUTH} \
229228
SSL=${SSL} \
230229
MONGODB_API_VERSION="${MONGODB_API_VERSION}" \
231-
NODE_VERSION=${NODE_VERSION} \
232230
TOPOLOGY="${TOPOLOGY}" \
233231
COMPRESSOR="${COMPRESSOR}" \
234232
SKIP_DEPS=${SKIP_DEPS|1} \
@@ -358,9 +356,6 @@ functions:
358356
${PREPARE_SHELL}
359357
NODE_LTS_NAME=${NODE_LTS_NAME} NPM_OPTIONS=${NPM_OPTIONS}\
360358
bash ${PROJECT_DIRECTORY}/.evergreen/install-dependencies.sh
361-
- command: expansions.update
362-
params:
363-
file: src/deps-expansion.yml
364359
run atlas tests:
365360
- command: shell.exec
366361
type: test

.evergreen/init-nvm.sh

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
#! /usr/bin/env bash
22

33
export PATH="/opt/mongodbtoolchain/v2/bin:$PATH"
4-
NODE_ARTIFACTS_PATH="${PROJECT_DIRECTORY}/node-artifacts"
5-
export NVM_DIR="${NODE_ARTIFACTS_PATH}/nvm"
64

5+
NODE_ARTIFACTS_PATH="${PROJECT_DIRECTORY}/node-artifacts"
76
if [[ "$OS" == "Windows_NT" ]]; then
8-
NVM_HOME=$(cygpath -w "$NVM_DIR")
9-
export NVM_HOME
10-
NVM_SYMLINK=$(cygpath -w "$NODE_ARTIFACTS_PATH/bin")
11-
export NVM_SYMLINK
12-
NVM_ARTIFACTS_PATH=$(cygpath -w "$NODE_ARTIFACTS_PATH/bin")
13-
export NVM_ARTIFACTS_PATH
14-
PATH=$(cygpath $NVM_SYMLINK):$(cygpath $NVM_HOME):$PATH
15-
export PATH
16-
echo "updated path on windows PATH=$PATH"
17-
else
18-
[ -s "$NVM_DIR/nvm.sh" ] && source "$NVM_DIR/nvm.sh"
7+
NODE_ARTIFACTS_PATH=$(cygpath --unix "$NODE_ARTIFACTS_PATH")
198
fi
209

10+
export PATH="$NODE_ARTIFACTS_PATH/npm_global/bin:$NODE_ARTIFACTS_PATH/nodejs/bin:$PATH"
11+
hash -r
12+
2113
export NODE_OPTIONS="--trace-deprecation --trace-warnings"

.evergreen/install-dependencies.sh

Lines changed: 101 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,113 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
set -o errexit # Exit the script with error if any of the commands fail
33

4-
NVM_WINDOWS_URL="https://github.com/coreybutler/nvm-windows/releases/download/1.1.9/nvm-noinstall.zip"
5-
NVM_URL="https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh"
6-
7-
NODE_LTS_NAME=${NODE_LTS_NAME:-fermium}
8-
NODE_ARTIFACTS_PATH="${PROJECT_DIRECTORY}/node-artifacts"
9-
10-
# this needs to be explicitly exported for the nvm install below
11-
export NVM_DIR="${NODE_ARTIFACTS_PATH}/nvm"
12-
export XDG_CONFIG_HOME=${NODE_ARTIFACTS_PATH}
13-
14-
# create node artifacts path if needed
15-
mkdir -p "${NODE_ARTIFACTS_PATH}"
16-
17-
function node_lts_to_version() {
18-
case $1 in
19-
"erbium")
20-
echo 12
21-
;;
22-
"fermium")
23-
echo 14
24-
;;
25-
"gallium")
26-
echo 16
27-
;;
28-
"hydrogen")
29-
echo 18
30-
;;
31-
"iron")
32-
echo 20
33-
;;
34-
"latest")
35-
echo 'latest'
36-
;;
37-
*)
38-
echo "Unsupported Node LTS version $1"
39-
;;
40-
esac
41-
}
42-
43-
function latest_version_for_node_major() {
44-
local __NODE_MAJOR_VERSION=$1
45-
local NODE_DOWNLOAD_URI="https://nodejs.org/download/release/latest-v${__NODE_MAJOR_VERSION}.x/SHASUMS256.txt"
46-
47-
if [ $__NODE_MAJOR_VERSION == 'latest' ]
48-
then
49-
NODE_DOWNLOAD_URI="https://nodejs.org/download/release/latest/SHASUMS256.txt"
50-
fi
51-
52-
# check that the requested version does exist
53-
curl --silent --fail $NODE_DOWNLOAD_URI &> /dev/null
54-
55-
echo $(curl --retry 8 --retry-delay 5 --max-time 50 --silent -o- $NODE_DOWNLOAD_URI | head -n 1 | awk '{print $2};' | cut -d- -f2)
56-
}
57-
58-
NODE_MAJOR_VERSION=$(node_lts_to_version $NODE_LTS_NAME)
59-
NODE_VERSION=$(latest_version_for_node_major $NODE_MAJOR_VERSION)
60-
NODE_VERSION=${NODE_VERSION:1} # :1 gets rid of the leading 'v'
61-
62-
echo "set version to $NODE_VERSION"
63-
64-
# output node version to expansions file for use in subsequent scripts
65-
cat <<EOT > deps-expansion.yml
66-
NODE_VERSION: "$NODE_VERSION"
67-
EOT
4+
NODE_LTS_NAME=${NODE_LTS_NAME:-erbium}
5+
NODE_ARTIFACTS_PATH="${PROJECT_DIRECTORY:-$(pwd)}/node-artifacts"
6+
if [[ "$OS" = "Windows_NT" ]]; then NODE_ARTIFACTS_PATH=$(cygpath --unix "$NODE_ARTIFACTS_PATH"); fi
7+
8+
CURL_FLAGS=(
9+
--fail # Exit code 1 if request fails
10+
--compressed # Request a compressed response should keep fetching fast
11+
--location # Follow a redirect
12+
--retry 8 # Retry HTTP 408, 429, 500, 502, 503 or 504, 8 times
13+
--silent # Do not print a progress bar
14+
--show-error # Despite the silent flag still print out errors
15+
--max-time 900 # 900 seconds is 15 minutes, evergreen times out at 20
16+
--continue-at - # If a download is interrupted it can figure out where to resume
17+
)
18+
19+
mkdir -p "$NODE_ARTIFACTS_PATH/npm_global"
20+
21+
# Comparisons are all case insensitive
22+
shopt -s nocasematch
23+
24+
# index.tab is a sorted tab separated values file with the following headers
25+
# 0 1 2 3 4 5 6 7 8 9 10
26+
# version date files npm v8 uv zlib openssl modules lts security
27+
curl "${CURL_FLAGS[@]}" "https://nodejs.org/dist/index.tab" --output node_index.tab
28+
29+
while IFS=$'\t' read -r -a row; do
30+
node_index_version="${row[0]}"
31+
node_index_date="${row[1]}"
32+
node_index_lts="${row[9]}"
33+
[[ "$node_index_version" = "version" ]] && continue # skip tsv header
34+
[[ "$NODE_LTS_NAME" = "latest" ]] && break # first line is latest
35+
[[ "$NODE_LTS_NAME" = "$node_index_lts" ]] && break # case insensitive compare
36+
done < node_index.tab
37+
38+
if [[ "$OS" = "Windows_NT" ]]; then
39+
operating_system="win"
40+
elif [[ $(uname) = "darwin" ]]; then
41+
operating_system="darwin"
42+
elif [[ $(uname) = "linux" ]]; then
43+
operating_system="linux"
44+
else
45+
echo "Unable to determine operating system: $operating_system"
46+
exit 1
47+
fi
6848

69-
# install Node.js on Windows
70-
if [[ "$OS" == "Windows_NT" ]]; then
71-
# Delete pre-existing node to avoid version conflicts
72-
rm -rf "/cygdrive/c/Program Files/nodejs"
49+
architecture=$(uname -m)
50+
if [[ $architecture = "x86_64" ]]; then
51+
architecture="x64"
52+
elif [[ $architecture = "arm64" ]]; then
53+
architecture="arm64"
54+
elif [[ $architecture = "aarch64" ]]; then
55+
architecture="arm64"
56+
elif [[ $architecture == s390* ]]; then
57+
architecture="s390x"
58+
elif [[ $architecture == ppc* ]]; then
59+
architecture="ppc64le"
60+
else
61+
echo "Unable to determine operating system: $architecture"
62+
exit 1
63+
fi
7364

65+
file_extension="tar.gz"
66+
if [[ "$OS" = "Windows_NT" ]]; then file_extension="zip"; fi
7467

75-
NVM_HOME=$(cygpath -w "$NVM_DIR")
76-
export NVM_HOME
77-
NVM_SYMLINK=$(cygpath -w "$NODE_ARTIFACTS_PATH/bin")
78-
export NVM_SYMLINK
79-
NVM_ARTIFACTS_PATH=$(cygpath -w "$NODE_ARTIFACTS_PATH/bin")
80-
export NVM_ARTIFACTS_PATH
81-
PATH=$(cygpath $NVM_SYMLINK):$(cygpath $NVM_HOME):$PATH
82-
export PATH
68+
node_directory="node-${node_index_version}-${operating_system}-${architecture}"
69+
node_archive="${node_directory}.${file_extension}"
70+
node_archive_path="$NODE_ARTIFACTS_PATH/${node_archive}"
71+
node_download_url="https://nodejs.org/dist/${node_index_version}/${node_archive}"
8372

84-
curl -L $NVM_WINDOWS_URL -o nvm.zip
85-
unzip -d "$NVM_DIR" nvm.zip
86-
rm nvm.zip
73+
echo "Node.js ${node_index_version} for ${operating_system}-${architecture} released on ${node_index_date}"
8774

88-
chmod 777 "$NVM_DIR"
89-
chmod -R a+rx "$NVM_DIR"
75+
set -o xtrace
9076

91-
cat <<EOT > "$NVM_DIR/settings.txt"
92-
root: $NVM_HOME
93-
path: $NVM_SYMLINK
94-
EOT
95-
nvm install "$NODE_VERSION"
96-
nvm use "$NODE_VERSION"
97-
which node || echo "node not found, PATH=$PATH"
98-
which npm || echo "npm not found, PATH=$PATH"
99-
npm cache clear --force # Fixes: Cannot read properties of null (reading 'pickAlgorithm') error on windows
77+
curl "${CURL_FLAGS[@]}" "${node_download_url}" --output "$node_archive_path"
10078

101-
# install Node.js on Linux/MacOS
79+
if [[ "$file_extension" = "zip" ]]; then
80+
unzip -q "$node_archive_path" -d "${NODE_ARTIFACTS_PATH}"
81+
mkdir -p "${NODE_ARTIFACTS_PATH}/nodejs"
82+
# Windows "bins" are at the top level
83+
mv "${NODE_ARTIFACTS_PATH}/${node_directory}" "${NODE_ARTIFACTS_PATH}/nodejs/bin"
84+
# Need to add executable flag ourselves
85+
chmod +x "${NODE_ARTIFACTS_PATH}/nodejs/bin/node.exe"
86+
chmod +x "${NODE_ARTIFACTS_PATH}/nodejs/bin/npm"
10287
else
103-
curl -o- $NVM_URL | bash
104-
[ -s "${NVM_DIR}/nvm.sh" ] && source "${NVM_DIR}/nvm.sh"
105-
nvm install --no-progress "$NODE_VERSION"
88+
tar -xf "$node_archive_path" -C "${NODE_ARTIFACTS_PATH}"
89+
mv "${NODE_ARTIFACTS_PATH}/${node_directory}" "${NODE_ARTIFACTS_PATH}/nodejs"
10690
fi
10791

108-
npm install ${NPM_OPTIONS}
92+
export PATH="$NODE_ARTIFACTS_PATH/npm_global/bin:$NODE_ARTIFACTS_PATH/nodejs/bin:$PATH"
93+
hash -r
94+
95+
# Set npm -g prefix to our local artifacts directory
96+
cat <<EOT > .npmrc
97+
prefix=$NODE_ARTIFACTS_PATH/npm_global
98+
EOT
99+
100+
# Cannot upgrade npm version for node 12
101+
if [[ $operating_system != "win" ]] && [[ $NODE_LTS_NAME != "erbium" ]]; then
102+
# Update npm to latest when we can
103+
npm install --global npm@latest
104+
hash -r
105+
elif [[ $NODE_LTS_NAME == "erbium" ]]; then
106+
# Node.js 12 can run up to npm v8
107+
npm install --global npm@8
108+
hash -r
109+
fi
110+
111+
echo "npm version: $(npm -v)"
112+
113+
npm install "${NPM_OPTIONS}"

.evergreen/run-benchmarks.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#! /bin/bash
22

3-
[ -s "$PROJECT_DIRECTORY/node-artifacts/nvm/nvm.sh" ] && source "$PROJECT_DIRECTORY"/node-artifacts/nvm/nvm.sh
3+
source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh"
44

55
export MONGODB_URI=$MONGODB_URI
66

.evergreen/run-bson-ext-test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
[ -s "$PROJECT_DIRECTORY/node-artifacts/nvm/nvm.sh" ] && source "$PROJECT_DIRECTORY"/node-artifacts/nvm/nvm.sh
3+
source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh"
44

55
set -o xtrace # Write all commands first to stderr
66
set -o errexit # Exit the script with error if any of the commands fail

.evergreen/run-custom-csfle-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export CSFLE_KMS_PROVIDERS=${CSFLE_KMS_PROVIDERS}
1212
export CRYPT_SHARED_LIB_PATH=${CRYPT_SHARED_LIB_PATH}
1313
echo "csfle CRYPT_SHARED_LIB_PATH: $CRYPT_SHARED_LIB_PATH"
1414

15-
[ -s "$PROJECT_DIRECTORY/node-artifacts/nvm/nvm.sh" ] && source "$PROJECT_DIRECTORY"/node-artifacts/nvm/nvm.sh
15+
source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh"
1616

1717
set -o xtrace # Write all commands first to stderr
1818
set -o errexit # Exit the script with error if any of the commands fail

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,8 @@ etc/docs/build
8787
!docs/**/*.png
8888
!docs/**/*.css
8989
!docs/**/*.js
90+
.nvmrc
91+
92+
node_index.tab
93+
node-artifacts
94+
.npmrc

0 commit comments

Comments
 (0)