Skip to content

Commit edc8bf8

Browse files
authored
ci(NODE-5088): download node to local directory (#585)
1 parent 45f0bea commit edc8bf8

File tree

4 files changed

+129
-85
lines changed

4 files changed

+129
-85
lines changed

.evergreen/init-nvm.sh

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#! /usr/bin/env bash
2+
3+
export PATH="/opt/mongodbtoolchain/v2/bin:$PATH"
4+
5+
NODE_ARTIFACTS_PATH="${PROJECT_DIRECTORY}/node-artifacts"
6+
if [[ "$OS" == "Windows_NT" ]]; then
7+
NODE_ARTIFACTS_PATH=$(cygpath --unix "$NODE_ARTIFACTS_PATH")
8+
fi
9+
10+
export PATH="$NODE_ARTIFACTS_PATH/npm_global/bin:$NODE_ARTIFACTS_PATH/nodejs/bin:$PATH"
11+
hash -r
12+
13+
export NODE_OPTIONS="--trace-deprecation --trace-warnings"

.evergreen/install-dependencies.sh

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#!/usr/bin/env bash
2+
set -o errexit # Exit the script with error if any of the commands fail
3+
4+
NODE_LTS_NAME=${NODE_LTS_NAME:-fermium}
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
48+
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
64+
65+
file_extension="tar.gz"
66+
if [[ "$OS" = "Windows_NT" ]]; then file_extension="zip"; fi
67+
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}"
72+
73+
echo "Node.js ${node_index_version} for ${operating_system}-${architecture} released on ${node_index_date}"
74+
75+
set -o xtrace
76+
77+
curl "${CURL_FLAGS[@]}" "${node_download_url}" --output "$node_archive_path"
78+
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"
87+
else
88+
tar -xf "$node_archive_path" -C "${NODE_ARTIFACTS_PATH}"
89+
mv "${NODE_ARTIFACTS_PATH}/${node_directory}" "${NODE_ARTIFACTS_PATH}/nodejs"
90+
fi
91+
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+
if [[ $operating_system != "win" ]]; then
101+
# Update npm to latest when we can
102+
npm install --global npm@latest
103+
hash -r
104+
fi
105+
106+
echo "npm version: $(npm -v)"
107+
108+
npm install "${NPM_OPTIONS}"

.evergreen/setup_environment.sh

-84
This file was deleted.

.evergreen/test.sh

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@
44
set -o errexit # Exit the script with error if any of the commands fail
55

66
echo "Setting up environment"
7-
. ./.evergreen/setup_environment.sh
7+
8+
export PATH="/opt/mongodbtoolchain/v2/bin:$PATH"
9+
hash -r
10+
11+
export NODE_LTS_NAME="gallium"
12+
source ./.evergreen/install-dependencies.sh
13+
14+
815

916
# Handle the circular dependency when testing with a real client.
1017
MONGODB_CLIENT_ENCRYPTION_OVERRIDE="$(pwd)"

0 commit comments

Comments
 (0)