Skip to content

Commit 84fab70

Browse files
authored
ci(NODE-5098): download node to local directory (#3583)
1 parent 4a7b5ec commit 84fab70

File tree

7 files changed

+95
-119
lines changed

7 files changed

+95
-119
lines changed

.evergreen/config.in.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ functions:
191191
MONGODB_URI="${MONGODB_URI}" \
192192
AUTH=${AUTH} SSL=${SSL} TEST_CSFLE=true \
193193
MONGODB_API_VERSION="${MONGODB_API_VERSION}" \
194-
NODE_VERSION=${NODE_VERSION} SKIP_DEPS=${SKIP_DEPS|1} \
194+
SKIP_DEPS=${SKIP_DEPS|1} \
195195
bash ${PROJECT_DIRECTORY}/.evergreen/run-tests.sh
196196
197197
"run serverless tests":
@@ -291,7 +291,6 @@ functions:
291291
AUTH=${AUTH} \
292292
SSL=${SSL} \
293293
MONGODB_API_VERSION="${MONGODB_API_VERSION}" \
294-
NODE_VERSION=${NODE_VERSION} \
295294
SINGLE_MONGOS_LB_URI="${SINGLE_MONGOS_LB_URI}" \
296295
MULTI_MONGOS_LB_URI="${MULTI_MONGOS_LB_URI}" \
297296
TOPOLOGY="${TOPOLOGY}" \
@@ -312,7 +311,6 @@ functions:
312311
AUTH=${AUTH} \
313312
SSL=${SSL} \
314313
MONGODB_API_VERSION="${MONGODB_API_VERSION}" \
315-
NODE_VERSION=${NODE_VERSION} \
316314
TOPOLOGY="${TOPOLOGY}" \
317315
COMPRESSOR="${COMPRESSOR}" \
318316
SKIP_DEPS=${SKIP_DEPS|1} \
@@ -457,9 +455,6 @@ functions:
457455
${PREPARE_SHELL}
458456
NODE_LTS_NAME=${NODE_LTS_NAME} NPM_OPTIONS=${NPM_OPTIONS}\
459457
bash ${PROJECT_DIRECTORY}/.evergreen/install-dependencies.sh
460-
- command: expansions.update
461-
params:
462-
file: src/deps-expansion.yml
463458
464459
"install aws-credential-providers":
465460
- command: shell.exec

.evergreen/config.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ functions:
161161
MONGODB_URI="${MONGODB_URI}" \
162162
AUTH=${AUTH} SSL=${SSL} TEST_CSFLE=true \
163163
MONGODB_API_VERSION="${MONGODB_API_VERSION}" \
164-
NODE_VERSION=${NODE_VERSION} SKIP_DEPS=${SKIP_DEPS|1} \
164+
SKIP_DEPS=${SKIP_DEPS|1} \
165165
bash ${PROJECT_DIRECTORY}/.evergreen/run-tests.sh
166166
run serverless tests:
167167
- command: timeout.update
@@ -257,7 +257,6 @@ functions:
257257
AUTH=${AUTH} \
258258
SSL=${SSL} \
259259
MONGODB_API_VERSION="${MONGODB_API_VERSION}" \
260-
NODE_VERSION=${NODE_VERSION} \
261260
SINGLE_MONGOS_LB_URI="${SINGLE_MONGOS_LB_URI}" \
262261
MULTI_MONGOS_LB_URI="${MULTI_MONGOS_LB_URI}" \
263262
TOPOLOGY="${TOPOLOGY}" \
@@ -277,7 +276,6 @@ functions:
277276
AUTH=${AUTH} \
278277
SSL=${SSL} \
279278
MONGODB_API_VERSION="${MONGODB_API_VERSION}" \
280-
NODE_VERSION=${NODE_VERSION} \
281279
TOPOLOGY="${TOPOLOGY}" \
282280
COMPRESSOR="${COMPRESSOR}" \
283281
SKIP_DEPS=${SKIP_DEPS|1} \
@@ -407,9 +405,6 @@ functions:
407405
${PREPARE_SHELL}
408406
NODE_LTS_NAME=${NODE_LTS_NAME} NPM_OPTIONS=${NPM_OPTIONS}\
409407
bash ${PROJECT_DIRECTORY}/.evergreen/install-dependencies.sh
410-
- command: expansions.update
411-
params:
412-
file: src/deps-expansion.yml
413408
install aws-credential-providers:
414409
- command: shell.exec
415410
type: setup

.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: 82 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,95 @@
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-
74
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-
"fermium")
20-
echo 14
21-
;;
22-
"gallium")
23-
echo 16
24-
;;
25-
"hydrogen")
26-
echo 18
27-
;;
28-
"iron")
29-
echo 20
30-
;;
31-
"latest")
32-
echo 'latest'
33-
;;
34-
*)
35-
echo "Unsupported Node LTS version $1"
36-
;;
37-
esac
38-
}
39-
40-
function latest_version_for_node_major() {
41-
local __NODE_MAJOR_VERSION=$1
42-
local NODE_DOWNLOAD_URI="https://nodejs.org/download/release/latest-v${__NODE_MAJOR_VERSION}.x/SHASUMS256.txt"
43-
44-
if [ $__NODE_MAJOR_VERSION == 'latest' ]
45-
then
46-
NODE_DOWNLOAD_URI="https://nodejs.org/download/release/latest/SHASUMS256.txt"
47-
fi
48-
49-
# check that the requested version does exist
50-
curl --silent --fail $NODE_DOWNLOAD_URI &> /dev/null
51-
52-
echo $(curl --retry 8 --retry-delay 5 --max-time 50 --silent -o- $NODE_DOWNLOAD_URI | head -n 1 | awk '{print $2};' | cut -d- -f2)
53-
}
54-
55-
NODE_MAJOR_VERSION=$(node_lts_to_version $NODE_LTS_NAME)
56-
NODE_VERSION=$(latest_version_for_node_major $NODE_MAJOR_VERSION)
57-
NODE_VERSION=${NODE_VERSION:1} # :1 gets rid of the leading 'v'
58-
59-
echo "set version to $NODE_VERSION"
60-
61-
# output node version to expansions file for use in subsequent scripts
62-
cat <<EOT > deps-expansion.yml
63-
NODE_VERSION: "$NODE_VERSION"
64-
EOT
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+
mkdir -p "$NODE_ARTIFACTS_PATH/npm_global"
9+
10+
# Comparisons are all case insensitive
11+
shopt -s nocasematch
12+
13+
# index.tab is a sorted tab separated values file with the following headers
14+
# 0 1 2 3 4 5 6 7 8 9 10
15+
# version date files npm v8 uv zlib openssl modules lts security
16+
curl --retry 8 -sS "https://nodejs.org/dist/index.tab" --max-time 300 --output node_index.tab
17+
18+
while IFS=$'\t' read -r -a row; do
19+
node_index_version="${row[0]}"
20+
node_index_date="${row[1]}"
21+
node_index_lts="${row[9]}"
22+
[[ "$node_index_version" = "version" ]] && continue # skip tsv header
23+
[[ "$NODE_LTS_NAME" = "latest" ]] && break # first line is latest
24+
[[ "$NODE_LTS_NAME" = "$node_index_lts" ]] && break # case insensitive compare
25+
done < node_index.tab
26+
27+
if [[ "$OS" = "Windows_NT" ]]; then
28+
operating_system="win"
29+
elif [[ $(uname) = "darwin" ]]; then
30+
operating_system="darwin"
31+
elif [[ $(uname) = "linux" ]]; then
32+
operating_system="linux"
33+
else
34+
echo "Unable to determine operating system: $operating_system"
35+
exit 1
36+
fi
6537

66-
# install Node.js on Windows
67-
if [[ "$OS" == "Windows_NT" ]]; then
68-
# Delete pre-existing node to avoid version conflicts
69-
rm -rf "/cygdrive/c/Program Files/nodejs"
38+
architecture=$(uname -m)
39+
if [[ $architecture = "x86_64" ]]; then
40+
architecture="x64"
41+
elif [[ $architecture = "arm64" ]]; then
42+
architecture="arm64"
43+
elif [[ $architecture == s390* ]]; then
44+
architecture="s390x"
45+
elif [[ $architecture == ppc* ]]; then
46+
architecture="ppc64le"
47+
else
48+
echo "Unable to determine operating system: $architecture"
49+
exit 1
50+
fi
7051

52+
file_extension="tar.gz"
53+
if [[ "$OS" = "Windows_NT" ]]; then file_extension="zip"; fi
7154

72-
NVM_HOME=$(cygpath -w "$NVM_DIR")
73-
export NVM_HOME
74-
NVM_SYMLINK=$(cygpath -w "$NODE_ARTIFACTS_PATH/bin")
75-
export NVM_SYMLINK
76-
NVM_ARTIFACTS_PATH=$(cygpath -w "$NODE_ARTIFACTS_PATH/bin")
77-
export NVM_ARTIFACTS_PATH
78-
PATH=$(cygpath $NVM_SYMLINK):$(cygpath $NVM_HOME):$PATH
79-
export PATH
55+
node_directory="node-${node_index_version}-${operating_system}-${architecture}"
56+
node_archive="${node_directory}.${file_extension}"
57+
node_archive_path="$NODE_ARTIFACTS_PATH/${node_archive}"
58+
node_download_url="https://nodejs.org/dist/${node_index_version}/${node_archive}"
8059

81-
curl -L $NVM_WINDOWS_URL -o nvm.zip
82-
unzip -d "$NVM_DIR" nvm.zip
83-
rm nvm.zip
60+
echo "Node.js ${node_index_version} for ${operating_system}-${architecture} released on ${node_index_date}"
8461

85-
chmod 777 "$NVM_DIR"
86-
chmod -R a+rx "$NVM_DIR"
62+
set -o xtrace
8763

88-
cat <<EOT > "$NVM_DIR/settings.txt"
89-
root: $NVM_HOME
90-
path: $NVM_SYMLINK
91-
EOT
92-
nvm install "$NODE_VERSION"
93-
nvm use "$NODE_VERSION"
94-
which node || echo "node not found, PATH=$PATH"
95-
which npm || echo "npm not found, PATH=$PATH"
96-
npm cache clear --force # Fixes: Cannot read properties of null (reading 'pickAlgorithm') error on windows
64+
curl --fail --retry 8 -sS "${node_download_url}" --max-time 300 --output "$node_archive_path"
9765

98-
# install Node.js on Linux/MacOS
66+
if [[ "$file_extension" = "zip" ]]; then
67+
unzip -q "$node_archive_path" -d "${NODE_ARTIFACTS_PATH}"
68+
mkdir -p "${NODE_ARTIFACTS_PATH}/nodejs"
69+
# Windows "bins" are at the top level
70+
mv "${NODE_ARTIFACTS_PATH}/${node_directory}" "${NODE_ARTIFACTS_PATH}/nodejs/bin"
71+
# Need to add executable flag ourselves
72+
chmod +x "${NODE_ARTIFACTS_PATH}/nodejs/bin/node.exe"
73+
chmod +x "${NODE_ARTIFACTS_PATH}/nodejs/bin/npm"
9974
else
100-
curl -o- $NVM_URL | bash
101-
[ -s "${NVM_DIR}/nvm.sh" ] && source "${NVM_DIR}/nvm.sh"
102-
nvm install --no-progress "$NODE_VERSION"
75+
tar -xf "$node_archive_path" -C "${NODE_ARTIFACTS_PATH}"
76+
mv "${NODE_ARTIFACTS_PATH}/${node_directory}" "${NODE_ARTIFACTS_PATH}/nodejs"
10377
fi
10478

105-
npm install ${NPM_OPTIONS}
79+
export PATH="$NODE_ARTIFACTS_PATH/npm_global/bin:$NODE_ARTIFACTS_PATH/nodejs/bin:$PATH"
80+
hash -r
81+
82+
# Set npm -g prefix to our local artifacts directory
83+
cat <<EOT > .npmrc
84+
prefix=$NODE_ARTIFACTS_PATH/npm_global
85+
EOT
86+
87+
if [[ $operating_system != "win" ]]; then
88+
# Update npm to latest when we can
89+
npm install --global npm@latest
90+
hash -r
91+
fi
92+
93+
echo "npm version: $(npm -v)"
94+
95+
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-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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,7 @@ etc/docs/build
8888
!docs/**/*.css
8989
!docs/**/*.js
9090
.nvmrc
91+
92+
node_index.tab
93+
node-artifacts
94+
.npmrc

0 commit comments

Comments
 (0)