Skip to content

Commit cfd40d1

Browse files
committed
ci(NODE-5082): download node to local directory
1 parent a45e0e1 commit cfd40d1

File tree

5 files changed

+101
-105
lines changed

5 files changed

+101
-105
lines changed

.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: 89 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,104 @@
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
5+
NODE_ARTIFACTS_PATH="${PROJECT_DIRECTORY:-$(pwd)}/node-artifacts"
6+
if [[ "$OS" = "Windows_NT" ]]; then
7+
NODE_ARTIFACTS_PATH=$(cygpath --unix "$NODE_ARTIFACTS_PATH")
8+
fi
9+
10+
mkdir -p "$NODE_ARTIFACTS_PATH/npm_global"
11+
12+
# Comparisons are all case insensitive
13+
shopt -s nocasematch
14+
15+
# index.tab is a sorted tab separated values file with the following headers
16+
# 0 1 2 3 4 5 6 7 8 9 10
17+
# version date files npm v8 uv zlib openssl modules lts security
18+
curl --retry 8 -sS "https://nodejs.org/dist/index.tab" --max-time 300 --output node_index.tab
19+
20+
while IFS=$'\t' read -r -a row; do
21+
node_index_version="${row[0]}"
22+
node_index_date="${row[1]}"
23+
node_index_lts="${row[9]}"
24+
[[ "$node_index_version" = "version" ]] && continue # skip tsv header
25+
[[ "$NODE_LTS_NAME" = "latest" ]] && break # first line is latest
26+
[[ "$NODE_LTS_NAME" = "$node_index_lts" ]] && break # case insensitive compare
27+
done < node_index.tab
28+
6229
cat <<EOT > deps-expansion.yml
63-
NODE_VERSION: "$NODE_VERSION"
30+
NODE_VERSION: "${node_index_version:1}" # :1 gets rid of the leading 'v'
6431
EOT
6532

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"
33+
if [[ "$OS" = "Windows_NT" ]]; then
34+
operating_system="win"
35+
elif [[ $(uname) = "darwin" ]]; then
36+
operating_system="darwin"
37+
elif [[ $(uname) = "linux" ]]; then
38+
operating_system="linux"
39+
else
40+
echo "Unable to determine operating system: $operating_system"
41+
exit 1
42+
fi
7043

44+
architecture=$(uname -m)
45+
if [[ $architecture = "x86_64" ]]; then
46+
architecture="x64"
47+
elif [[ $architecture = "arm64" ]]; then
48+
architecture="arm64"
49+
elif [[ $architecture == s390* ]]; then
50+
architecture="s390x"
51+
elif [[ $architecture == ppc* ]]; then
52+
architecture="ppc64le"
53+
else
54+
echo "Unable to determine operating system: $architecture"
55+
exit 1
56+
fi
7157

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
58+
if [[ "$OS" = "Windows_NT" ]]; then
59+
file_extension="zip"
60+
else
61+
file_extension="tar.gz"
62+
fi
8063

81-
curl -L $NVM_WINDOWS_URL -o nvm.zip
82-
unzip -d "$NVM_DIR" nvm.zip
83-
rm nvm.zip
64+
node_directory="node-${node_index_version}-${operating_system}-${architecture}"
65+
node_archive="${node_directory}.${file_extension}"
66+
node_archive_path="$NODE_ARTIFACTS_PATH/${node_archive}"
67+
node_download_url="https://nodejs.org/dist/${node_index_version}/${node_archive}"
8468

85-
chmod 777 "$NVM_DIR"
86-
chmod -R a+rx "$NVM_DIR"
69+
echo "Node.js ${node_index_version} for ${operating_system}-${architecture} released on ${node_index_date}"
8770

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
71+
set -o xtrace
9772

98-
# install Node.js on Linux/MacOS
73+
curl --fail --retry 8 -sS "${node_download_url}" --max-time 300 --output "$node_archive_path"
74+
75+
if [[ "$file_extension" = "zip" ]]; then
76+
unzip -q "$node_archive_path" -d "${NODE_ARTIFACTS_PATH}"
77+
mkdir -p "${NODE_ARTIFACTS_PATH}/nodejs"
78+
# Windows "bins" are at the top level
79+
mv "${NODE_ARTIFACTS_PATH}/${node_directory}" "${NODE_ARTIFACTS_PATH}/nodejs/bin"
80+
# Need to add executable flag ourselves
81+
chmod +x "${NODE_ARTIFACTS_PATH}/nodejs/bin/node.exe"
82+
chmod +x "${NODE_ARTIFACTS_PATH}/nodejs/bin/npm"
9983
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"
84+
tar -xf "$node_archive_path" -C "${NODE_ARTIFACTS_PATH}"
85+
mv "${NODE_ARTIFACTS_PATH}/${node_directory}" "${NODE_ARTIFACTS_PATH}/nodejs"
86+
fi
87+
88+
export PATH="$NODE_ARTIFACTS_PATH/npm_global/bin:$NODE_ARTIFACTS_PATH/nodejs/bin:$PATH"
89+
hash -r
90+
91+
# Set npm -g prefix to our local artifacts directory
92+
cat <<EOT > .npmrc
93+
prefix=$NODE_ARTIFACTS_PATH/npm_global
94+
EOT
95+
96+
if [[ $operating_system != "win" ]]; then
97+
# Update npm to latest when we can
98+
npm install --global npm@latest
99+
hash -r
103100
fi
104101

105-
npm install ${NPM_OPTIONS}
102+
echo "npm version: $(npm -v)"
103+
104+
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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,8 @@ etc/docs/build
8888
!docs/**/*.css
8989
!docs/**/*.js
9090
.nvmrc
91+
92+
node_index.tab
93+
node-artifacts
94+
deps-expansion.yml
95+
.npmrc

0 commit comments

Comments
 (0)