Skip to content

Commit 178adab

Browse files
authored
chore(NODE-6402): migrate node download script to drivers-tools (#208)
1 parent c35b125 commit 178adab

File tree

7 files changed

+67
-146
lines changed

7 files changed

+67
-146
lines changed

.evergreen/config.yml

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,13 @@ functions:
1919
- command: git.get_project
2020
params:
2121
directory: src
22-
- command: shell.exec
22+
- command: subprocess.exec
2323
params:
2424
working_dir: src
25-
script: |
26-
# Get the current unique version of this checkout
27-
if [ "${is_patch}" = "true" ]; then
28-
CURRENT_VERSION=$(git describe)-patch-${version_id}
29-
else
30-
CURRENT_VERSION=latest
31-
fi
32-
export PROJECT_DIRECTORY="$(pwd)"
33-
# Python has cygwin path problems on Windows. Detect prospective mongo-orchestration home directory
34-
if [ "Windows_NT" = "$OS" ]; then # Magic variable in cygwin
35-
export PROJECT_DIRECTORY=$(cygpath -m $PROJECT_DIRECTORY)
36-
fi
37-
cat <<EOT > expansion.yml
38-
CURRENT_VERSION: "$CURRENT_VERSION"
39-
PROJECT_DIRECTORY: "$PROJECT_DIRECTORY"
40-
PREPARE_SHELL: |
41-
set -o errexit
42-
set -o xtrace
43-
export PROJECT_DIRECTORY="$PROJECT_DIRECTORY"
44-
export PROJECT="${project}"
45-
EOT
46-
# See what we've done
47-
cat expansion.yml
25+
binary: bash
26+
add_expansions_to_env: true
27+
args:
28+
- '.evergreen/prepare-shell.sh'
4829
- command: expansions.update
4930
params:
5031
file: src/expansion.yml
@@ -73,11 +54,15 @@ functions:
7354
- '--interactive'
7455
- '--volume'
7556
- ${PROJECT_DIRECTORY}:/app
57+
- '--volume'
58+
- ${DRIVERS_TOOLS}:/drivers-tools
7659
- '--workdir'
7760
- /app
7861
- '--env'
7962
- PROJECT_DIRECTORY=/app
8063
- '--env'
64+
- DRIVERS_TOOLS=/drivers-tools
65+
- '--env'
8166
- GYP_DEFINES
8267
- 'ubuntu:22.04'
8368
- /bin/bash
@@ -99,6 +84,7 @@ functions:
9984
params:
10085
working_dir: src
10186
binary: bash
87+
add_expansions_to_env: true
10288
args:
10389
- .evergreen/install-dependencies.sh
10490
env:

.evergreen/init-node-and-npm-env.sh

Lines changed: 0 additions & 21 deletions
This file was deleted.

.evergreen/install-dependencies.sh

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

4-
NODE_LTS_VERSION=${NODE_LTS_VERSION:-14}
4+
# allowed values:
5+
## a nodejs major version (i.e., 16)
6+
## 'latest'
7+
## a full nodejs version, in the format v<major>.<minor>.patch
8+
export NODE_LTS_VERSION=${NODE_LTS_VERSION:-14}
59
# npm version can be defined in the environment for cases where we need to install
610
# a version lower than latest to support EOL Node versions.
7-
NPM_VERSION=${NPM_VERSION:-latest}
11+
export NPM_VERSION=${NPM_VERSION:-latest}
812

9-
source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh"
10-
11-
if [[ -z "${npm_global_prefix}" ]]; then echo "npm_global_prefix is unset" && exit 1; fi
12-
if [[ -z "${NODE_ARTIFACTS_PATH}" ]]; then echo "NODE_ARTIFACTS_PATH is unset" && exit 1; fi
13-
14-
CURL_FLAGS=(
15-
--fail # Exit code 1 if request fails
16-
--compressed # Request a compressed response should keep fetching fast
17-
--location # Follow a redirect
18-
--retry 8 # Retry HTTP 408, 429, 500, 502, 503 or 504, 8 times
19-
--silent # Do not print a progress bar
20-
--show-error # Despite the silent flag still print out errors
21-
--max-time 900 # 900 seconds is 15 minutes, evergreen times out at 20
22-
--continue-at - # If a download is interrupted it can figure out where to resume
23-
)
24-
25-
mkdir -p "$NODE_ARTIFACTS_PATH/npm_global"
26-
27-
# Comparisons are all case insensitive
28-
shopt -s nocasematch
29-
30-
# index.tab is a sorted tab separated values file with the following headers
31-
# 0 1 2 3 4 5 6 7 8 9 10
32-
# version date files npm v8 uv zlib openssl modules lts security
33-
curl "${CURL_FLAGS[@]}" "https://nodejs.org/dist/index.tab" --output node_index.tab
34-
35-
while IFS=$'\t' read -r -a row; do
36-
node_index_version="${row[0]}"
37-
node_index_major_version=$(echo $node_index_version | sed -E 's/^v([0-9]+).*$/\1/')
38-
node_index_date="${row[1]}"
39-
node_index_lts="${row[9]}"
40-
[[ "$node_index_version" = "version" ]] && continue # skip tsv header
41-
[[ "$NODE_LTS_VERSION" = "latest" ]] && break # first line is latest
42-
[[ "$NODE_LTS_VERSION" = "$node_index_major_version" ]] && break # case insensitive compare
43-
done < node_index.tab
44-
45-
if [[ "$OS" = "Windows_NT" ]]; then
46-
operating_system="win"
47-
elif [[ $(uname) = "darwin" ]]; then
48-
operating_system="darwin"
49-
elif [[ $(uname) = "linux" ]]; then
50-
operating_system="linux"
51-
else
52-
echo "Unable to determine operating system: $operating_system"
53-
exit 1
54-
fi
55-
56-
architecture=$(uname -m)
57-
if [[ $architecture = "x86_64" ]]; then
58-
architecture="x64"
59-
elif [[ $architecture = "arm64" ]]; then
60-
architecture="arm64"
61-
elif [[ $architecture = "aarch64" ]]; then
62-
architecture="arm64"
63-
elif [[ $architecture == s390* ]]; then
64-
architecture="s390x"
65-
elif [[ $architecture == ppc* ]]; then
66-
architecture="ppc64le"
67-
else
68-
echo "Unable to determine operating system: $architecture"
69-
exit 1
70-
fi
71-
72-
file_extension="tar.gz"
73-
if [[ "$OS" = "Windows_NT" ]]; then file_extension="zip"; fi
74-
75-
node_directory="node-${node_index_version}-${operating_system}-${architecture}"
76-
node_archive="${node_directory}.${file_extension}"
77-
node_archive_path="$NODE_ARTIFACTS_PATH/${node_archive}"
78-
node_download_url="https://nodejs.org/dist/${node_index_version}/${node_archive}"
79-
80-
echo "Node.js ${node_index_version} for ${operating_system}-${architecture} released on ${node_index_date}"
81-
82-
set -o xtrace
83-
84-
curl "${CURL_FLAGS[@]}" "${node_download_url}" --output "$node_archive_path"
85-
86-
if [[ "$file_extension" = "zip" ]]; then
87-
unzip -q "$node_archive_path" -d "${NODE_ARTIFACTS_PATH}"
88-
mkdir -p "${NODE_ARTIFACTS_PATH}/nodejs"
89-
# Windows "bins" are at the top level
90-
mv "${NODE_ARTIFACTS_PATH}/${node_directory}" "${NODE_ARTIFACTS_PATH}/nodejs/bin"
91-
# Need to add executable flag ourselves
92-
chmod +x "${NODE_ARTIFACTS_PATH}/nodejs/bin/node.exe"
93-
chmod +x "${NODE_ARTIFACTS_PATH}/nodejs/bin/npm"
94-
else
95-
tar -xf "$node_archive_path" -C "${NODE_ARTIFACTS_PATH}"
96-
mv "${NODE_ARTIFACTS_PATH}/${node_directory}" "${NODE_ARTIFACTS_PATH}/nodejs"
97-
fi
98-
99-
if [[ $operating_system != "win" ]]; then
100-
npm install --global npm@$NPM_VERSION
101-
hash -r
102-
fi
103-
104-
echo "npm location: $(which npm)"
105-
echo "npm version: $(npm -v)"
13+
source $DRIVERS_TOOLS/.evergreen/install-node.sh
10614

10715
npm install --build-from-source
10816
ldd build/*/kerberos.node || true

.evergreen/prepare-shell.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#! /usr/bin/env bash
2+
3+
# Only set errexit and xtrace if shell is NOT interactive
4+
[[ $- == *i* ]] || set -o xtrace
5+
[[ $- == *i* ]] || set -o errexit
6+
7+
PROJECT_DIRECTORY="$(pwd)"
8+
DRIVERS_TOOLS=$(cd .. && echo "$(pwd)/drivers-tools")
9+
export PROJECT_DIRECTORY
10+
export DRIVERS_TOOLS
11+
12+
if [ ! -d "$DRIVERS_TOOLS" ]; then
13+
# Only clone driver tools if it does not exist
14+
git clone --depth=1 "https://github.com/mongodb-labs/drivers-evergreen-tools.git" "${DRIVERS_TOOLS}"
15+
fi
16+
17+
echo "installed DRIVERS_TOOLS from commit $(git -C "${DRIVERS_TOOLS}" rev-parse HEAD)"
18+
19+
20+
# Get the current unique version of this checkout
21+
if [ "${is_patch}" = "true" ]; then
22+
CURRENT_VERSION=$(git describe)-patch-${version_id}
23+
else
24+
CURRENT_VERSION=latest
25+
fi
26+
27+
# Python has cygwin path problems on Windows. Detect prospective mongo-orchestration home directory
28+
if [ "Windows_NT" = "$OS" ]; then # Magic variable in cygwin
29+
export PROJECT_DIRECTORY=$(cygpath -m "$PROJECT_DIRECTORY")
30+
fi
31+
32+
cat <<EOT > expansion.yml
33+
CURRENT_VERSION: "$CURRENT_VERSION"
34+
PROJECT_DIRECTORY: "$PROJECT_DIRECTORY"
35+
DRIVERS_TOOLS: "$DRIVERS_TOOLS"
36+
PREPARE_SHELL: |
37+
set -o errexit
38+
set -o xtrace
39+
export PROJECT_DIRECTORY="$PROJECT_DIRECTORY"
40+
export PROJECT="${project}"
41+
export DRIVERS_TOOLS="$DRIVERS_TOOLS"
42+
EOT
43+
44+
# See what we've done
45+
cat expansion.yml

.evergreen/run-prebuild.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
set -o errexit # Exit the script with error if any of the commands fail
44
set -o xtrace
55

6-
source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh"
6+
source $DRIVERS_TOOLS/.evergreen/init-node-and-npm-env.sh
77

88
# mongodbtoolchain is necessary for building on Windows
99
export PATH="/opt/mongodbtoolchain/v2/bin:$PATH"

.evergreen/run-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
set -o errexit # Exit the script with error if any of the commands fail
44
set -o xtrace
55

6-
source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh"
6+
source $DRIVERS_TOOLS/.evergreen/init-node-and-npm-env.sh
77

88
npm run check:lint
99
npm test

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ bindings
2424
.npmrc
2525

2626
*.tgz
27+
28+
expansion.yml
29+
.drivers-tools/

0 commit comments

Comments
 (0)