Skip to content

Commit

Permalink
chore(NODE-6402): migrate node download script to drivers-tools (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
nbbeeken authored Oct 15, 2024
1 parent c35b125 commit 178adab
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 146 deletions.
34 changes: 10 additions & 24 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,13 @@ functions:
- command: git.get_project
params:
directory: src
- command: shell.exec
- command: subprocess.exec
params:
working_dir: src
script: |
# Get the current unique version of this checkout
if [ "${is_patch}" = "true" ]; then
CURRENT_VERSION=$(git describe)-patch-${version_id}
else
CURRENT_VERSION=latest
fi
export PROJECT_DIRECTORY="$(pwd)"
# Python has cygwin path problems on Windows. Detect prospective mongo-orchestration home directory
if [ "Windows_NT" = "$OS" ]; then # Magic variable in cygwin
export PROJECT_DIRECTORY=$(cygpath -m $PROJECT_DIRECTORY)
fi
cat <<EOT > expansion.yml
CURRENT_VERSION: "$CURRENT_VERSION"
PROJECT_DIRECTORY: "$PROJECT_DIRECTORY"
PREPARE_SHELL: |
set -o errexit
set -o xtrace
export PROJECT_DIRECTORY="$PROJECT_DIRECTORY"
export PROJECT="${project}"
EOT
# See what we've done
cat expansion.yml
binary: bash
add_expansions_to_env: true
args:
- '.evergreen/prepare-shell.sh'
- command: expansions.update
params:
file: src/expansion.yml
Expand Down Expand Up @@ -73,11 +54,15 @@ functions:
- '--interactive'
- '--volume'
- ${PROJECT_DIRECTORY}:/app
- '--volume'
- ${DRIVERS_TOOLS}:/drivers-tools
- '--workdir'
- /app
- '--env'
- PROJECT_DIRECTORY=/app
- '--env'
- DRIVERS_TOOLS=/drivers-tools
- '--env'
- GYP_DEFINES
- 'ubuntu:22.04'
- /bin/bash
Expand All @@ -99,6 +84,7 @@ functions:
params:
working_dir: src
binary: bash
add_expansions_to_env: true
args:
- .evergreen/install-dependencies.sh
env:
Expand Down
21 changes: 0 additions & 21 deletions .evergreen/init-node-and-npm-env.sh

This file was deleted.

106 changes: 7 additions & 99 deletions .evergreen/install-dependencies.sh
Original file line number Diff line number Diff line change
@@ -1,108 +1,16 @@
#!/usr/bin/env bash
set -o errexit # Exit the script with error if any of the commands fail

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

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

if [[ -z "${npm_global_prefix}" ]]; then echo "npm_global_prefix is unset" && exit 1; fi
if [[ -z "${NODE_ARTIFACTS_PATH}" ]]; then echo "NODE_ARTIFACTS_PATH is unset" && exit 1; fi

CURL_FLAGS=(
--fail # Exit code 1 if request fails
--compressed # Request a compressed response should keep fetching fast
--location # Follow a redirect
--retry 8 # Retry HTTP 408, 429, 500, 502, 503 or 504, 8 times
--silent # Do not print a progress bar
--show-error # Despite the silent flag still print out errors
--max-time 900 # 900 seconds is 15 minutes, evergreen times out at 20
--continue-at - # If a download is interrupted it can figure out where to resume
)

mkdir -p "$NODE_ARTIFACTS_PATH/npm_global"

# Comparisons are all case insensitive
shopt -s nocasematch

# index.tab is a sorted tab separated values file with the following headers
# 0 1 2 3 4 5 6 7 8 9 10
# version date files npm v8 uv zlib openssl modules lts security
curl "${CURL_FLAGS[@]}" "https://nodejs.org/dist/index.tab" --output node_index.tab

while IFS=$'\t' read -r -a row; do
node_index_version="${row[0]}"
node_index_major_version=$(echo $node_index_version | sed -E 's/^v([0-9]+).*$/\1/')
node_index_date="${row[1]}"
node_index_lts="${row[9]}"
[[ "$node_index_version" = "version" ]] && continue # skip tsv header
[[ "$NODE_LTS_VERSION" = "latest" ]] && break # first line is latest
[[ "$NODE_LTS_VERSION" = "$node_index_major_version" ]] && break # case insensitive compare
done < node_index.tab

if [[ "$OS" = "Windows_NT" ]]; then
operating_system="win"
elif [[ $(uname) = "darwin" ]]; then
operating_system="darwin"
elif [[ $(uname) = "linux" ]]; then
operating_system="linux"
else
echo "Unable to determine operating system: $operating_system"
exit 1
fi

architecture=$(uname -m)
if [[ $architecture = "x86_64" ]]; then
architecture="x64"
elif [[ $architecture = "arm64" ]]; then
architecture="arm64"
elif [[ $architecture = "aarch64" ]]; then
architecture="arm64"
elif [[ $architecture == s390* ]]; then
architecture="s390x"
elif [[ $architecture == ppc* ]]; then
architecture="ppc64le"
else
echo "Unable to determine operating system: $architecture"
exit 1
fi

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

node_directory="node-${node_index_version}-${operating_system}-${architecture}"
node_archive="${node_directory}.${file_extension}"
node_archive_path="$NODE_ARTIFACTS_PATH/${node_archive}"
node_download_url="https://nodejs.org/dist/${node_index_version}/${node_archive}"

echo "Node.js ${node_index_version} for ${operating_system}-${architecture} released on ${node_index_date}"

set -o xtrace

curl "${CURL_FLAGS[@]}" "${node_download_url}" --output "$node_archive_path"

if [[ "$file_extension" = "zip" ]]; then
unzip -q "$node_archive_path" -d "${NODE_ARTIFACTS_PATH}"
mkdir -p "${NODE_ARTIFACTS_PATH}/nodejs"
# Windows "bins" are at the top level
mv "${NODE_ARTIFACTS_PATH}/${node_directory}" "${NODE_ARTIFACTS_PATH}/nodejs/bin"
# Need to add executable flag ourselves
chmod +x "${NODE_ARTIFACTS_PATH}/nodejs/bin/node.exe"
chmod +x "${NODE_ARTIFACTS_PATH}/nodejs/bin/npm"
else
tar -xf "$node_archive_path" -C "${NODE_ARTIFACTS_PATH}"
mv "${NODE_ARTIFACTS_PATH}/${node_directory}" "${NODE_ARTIFACTS_PATH}/nodejs"
fi

if [[ $operating_system != "win" ]]; then
npm install --global npm@$NPM_VERSION
hash -r
fi

echo "npm location: $(which npm)"
echo "npm version: $(npm -v)"
source $DRIVERS_TOOLS/.evergreen/install-node.sh

npm install --build-from-source
ldd build/*/kerberos.node || true
45 changes: 45 additions & 0 deletions .evergreen/prepare-shell.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#! /usr/bin/env bash

# Only set errexit and xtrace if shell is NOT interactive
[[ $- == *i* ]] || set -o xtrace
[[ $- == *i* ]] || set -o errexit

PROJECT_DIRECTORY="$(pwd)"
DRIVERS_TOOLS=$(cd .. && echo "$(pwd)/drivers-tools")
export PROJECT_DIRECTORY
export DRIVERS_TOOLS

if [ ! -d "$DRIVERS_TOOLS" ]; then
# Only clone driver tools if it does not exist
git clone --depth=1 "https://github.com/mongodb-labs/drivers-evergreen-tools.git" "${DRIVERS_TOOLS}"
fi

echo "installed DRIVERS_TOOLS from commit $(git -C "${DRIVERS_TOOLS}" rev-parse HEAD)"


# Get the current unique version of this checkout
if [ "${is_patch}" = "true" ]; then
CURRENT_VERSION=$(git describe)-patch-${version_id}
else
CURRENT_VERSION=latest
fi

# Python has cygwin path problems on Windows. Detect prospective mongo-orchestration home directory
if [ "Windows_NT" = "$OS" ]; then # Magic variable in cygwin
export PROJECT_DIRECTORY=$(cygpath -m "$PROJECT_DIRECTORY")
fi

cat <<EOT > expansion.yml
CURRENT_VERSION: "$CURRENT_VERSION"
PROJECT_DIRECTORY: "$PROJECT_DIRECTORY"
DRIVERS_TOOLS: "$DRIVERS_TOOLS"
PREPARE_SHELL: |
set -o errexit
set -o xtrace
export PROJECT_DIRECTORY="$PROJECT_DIRECTORY"
export PROJECT="${project}"
export DRIVERS_TOOLS="$DRIVERS_TOOLS"
EOT

# See what we've done
cat expansion.yml
2 changes: 1 addition & 1 deletion .evergreen/run-prebuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -o errexit # Exit the script with error if any of the commands fail
set -o xtrace

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

# mongodbtoolchain is necessary for building on Windows
export PATH="/opt/mongodbtoolchain/v2/bin:$PATH"
Expand Down
2 changes: 1 addition & 1 deletion .evergreen/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -o errexit # Exit the script with error if any of the commands fail
set -o xtrace

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

npm run check:lint
npm test
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ bindings
.npmrc

*.tgz

expansion.yml
.drivers-tools/

0 comments on commit 178adab

Please sign in to comment.