-
Notifications
You must be signed in to change notification settings - Fork 916
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow selecting the Node.js binary OSD uses
* The startup scripts check `OSD_NODE_HOME` and `NODE_HOME` before falling back to use the bundled or system-wide Node.js binary. * Update `package.json` to replace `node` with `use_node`. * Update the build scripts to copy `use_node` into releases * Make tests that execute node internally, honor the binary being used. Signed-off-by: Miki <[email protected]>
- Loading branch information
Showing
13 changed files
with
282 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#!/bin/sh | ||
|
||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# The OpenSearch Contributors require contributions made to | ||
# this file be licensed under the Apache-2.0 license or a | ||
# compatible open source license. | ||
# | ||
# Any modifications Copyright OpenSearch Contributors. See | ||
# GitHub history for details. | ||
# | ||
|
||
# This script will find the appropriate Node.js runtime binary and execute it with any | ||
# parameters passed in. | ||
# | ||
# Set a variable named OSD_USE_NODE_JS_FILE_PATH to have it prefixed with OSD_HOME and executed | ||
# Example: SET OSD_USE_NODE_JS_FILE_PATH=\src\cli\dist | ||
# | ||
# NODE_OPTIONS is built using config/node.options and overridden by any previously set NODE_OPTIONS. | ||
# To pass in any specific defaults that can be overridden by both of them, use OSD_NODE_OPTS_PREFIX. | ||
|
||
SCRIPT="$0" | ||
|
||
UNAME=$(uname -s) | ||
if [ $UNAME = "FreeBSD" ]; then | ||
OS="freebsd" | ||
elif [ $UNAME = "Darwin" ]; then | ||
OS="darwin" | ||
else | ||
OS="other" | ||
fi | ||
|
||
# SCRIPT may be an arbitrarily deep series of symlinks. Loop until we have the concrete path. | ||
while [ -h "$SCRIPT" ] ; do | ||
ls=$(ls -ld "$SCRIPT") | ||
# Drop everything prior to -> | ||
link=$(expr "$ls" : '.*-> \(.*\)$') | ||
if expr "$link" : '/.*' > /dev/null; then | ||
SCRIPT="$link" | ||
else | ||
SCRIPT=$(dirname "$SCRIPT")/"$link" | ||
fi | ||
done | ||
|
||
# Get an absolute path for OSD_HOME | ||
OSD_HOME="$(cd "$(dirname "${SCRIPT}")/.."; pwd)" | ||
CONFIG_DIR=${OSD_PATH_CONF:-"OSD_HOME/config"} | ||
|
||
# Places to look for the Node.js binary in order: OSD_NODE_HOME > NODE_HOME > bundled with OSD > system-wide | ||
if [ ! -z "$OSD_NODE_HOME" ]; then | ||
NODE="$OSD_NODE_HOME/bin/node" | ||
NODE_ERROR_MSG="in OSD_NODE_HOME" | ||
NODE_ERROR_SHOW=true | ||
elif [ ! -z "$NODE_HOME" ]; then | ||
NODE="$NODE_HOME/bin/node" | ||
NODE_ERROR_MSG="in NODE_HOME" | ||
NODE_ERROR_SHOW=true | ||
else | ||
NODE="$OSD_HOME/node/bin/node" | ||
NODE_ERROR_MSG="bundled with OpenSearch Dashboards" | ||
# A bin folder at the root is only present in release builds that have a bundled Node.js binary | ||
if [ -x "OSD_HOME/bin" ]; then | ||
NODE_ERROR_SHOW=true | ||
fi | ||
fi | ||
|
||
if [ -x "$NODE" ]; then | ||
# Node.js binary was found where it was expected; no need to show an error | ||
NODE_ERROR_SHOW= | ||
elif [ $OS = "freebsd" ]; then | ||
NODE="${LOCALBASE}/bin/node" | ||
else | ||
NODE="$(which node)" | ||
fi | ||
|
||
if [ ! -x "$NODE" ]; then | ||
# Irrespective of NODE_ERROR_SHOW, show the error | ||
echo "Could not find a Node.js runtime binary $NODE_ERROR_MSG or on the system" >&2 | ||
exit 1 | ||
fi | ||
|
||
# Node.js binary was found but not where it was told to be, so show a warning | ||
if [ ! -z "$NODE_ERROR_SHOW" ]; then | ||
echo "Could not find a Node.js runtime binary $NODE_ERROR_MSG but found one at $NODE" >&2 | ||
fi | ||
|
||
if [ -f "${CONFIG_DIR}/node.options" ]; then | ||
OSD_NODE_OPTS="$(grep -v ^# < ${CONFIG_DIR}/node.options | xargs)" | ||
fi | ||
# If a file path was provided for execution, prefix with OSD_HOME; use relative paths to avoid the need for this. | ||
if [ ! -z "$OSD_USE_NODE_JS_FILE_PATH" ]; then | ||
NODE_OPTIONS="$OSD_NODE_OPTS_PREFIX $OSD_NODE_OPTS $NODE_OPTIONS" "${NODE}" "${OSD_HOME}${OSD_USE_NODE_JS_FILE_PATH}" "${@}" | ||
elif [ $# -ne 0 ]; then | ||
NODE_OPTIONS="$OSD_NODE_OPTS_PREFIX $OSD_NODE_OPTS $NODE_OPTIONS" "${NODE}" "${@}" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
@ECHO OFF | ||
|
||
:: | ||
:: SPDX-License-Identifier: Apache-2.0 | ||
:: | ||
:: The OpenSearch Contributors require contributions made to | ||
:: this file be licensed under the Apache-2.0 license or a | ||
:: compatible open source license. | ||
:: | ||
:: Any modifications Copyright OpenSearch Contributors. See | ||
:: GitHub history for details. | ||
:: | ||
|
||
:: This script will find the appropriate Node.js runtime binary and execute it with any | ||
:: parameters passed in. | ||
:: | ||
:: Set a variable named OSD_USE_NODE_JS_FILE_PATH to have it prefixed with OSD_HOME and executed | ||
:: Example: SET OSD_USE_NODE_JS_FILE_PATH=\src\cli\dist | ||
:: | ||
:: NODE_OPTIONS is built using config/node.options and overridden by any previously set NODE_OPTIONS. | ||
:: To pass in any specific defaults that can be overridden by both of them, use OSD_NODE_OPTS_PREFIX. | ||
|
||
SETLOCAL ENABLEDELAYEDEXPANSION | ||
|
||
SET SCRIPT_DIR=%~dp0 | ||
FOR %%I IN ("%SCRIPT_DIR%..") DO SET OSD_HOME=%%~dpfI | ||
|
||
SET CONFIG_DIR=%OSD_PATH_CONF% | ||
IF NOT DEFINED OSD_PATH_CONF ( | ||
SET "CONFIG_DIR=%OSD_HOME%\config" | ||
) | ||
|
||
:: Places to look for the Node.js binary in order: OSD_NODE_HOME > NODE_HOME > bundled with OSD > system-wide | ||
IF DEFINED OSD_NODE_HOME ( | ||
SET "NODE=%OSD_NODE_HOME%\node.exe" | ||
SET NODE_ERROR_MSG=in OSD_NODE_HOME | ||
SET NODE_ERROR_SHOW=true | ||
GOTO CheckNode | ||
) | ||
IF DEFINED NODE_HOME ( | ||
SET "NODE=%NODE_HOME%\node.exe" | ||
SET NODE_ERROR_MSG=in NODE_HOME | ||
SET NODE_ERROR_SHOW=true | ||
GOTO CheckNode | ||
) | ||
|
||
SET NODE=%OSD_HOME%\node\node.exe | ||
SET NODE_ERROR_MSG=bundled with OpenSearch Dashboards | ||
:: A bin folder at the root is only present in release builds that have a bundled Node.js binary | ||
IF EXIST "%OSD_HOME%\bin" ( | ||
SET NODE_ERROR_SHOW=true | ||
) | ||
|
||
:CheckNode | ||
|
||
IF EXIST "%NODE%" ( | ||
:: Node.js binary was found where it was expected; no need to show an error | ||
SET "NODE_ERROR_SHOW=" | ||
) ELSE ( | ||
:: Try finding the system-wide Node.js binary | ||
FOR /F "tokens=* USEBACKQ" %%F IN (`where node.exe`) DO ( | ||
SET "NODE=%%F" | ||
:: Bail out after finding the first one | ||
GOTO CheckNodeAgain | ||
) | ||
) | ||
|
||
:CheckNodeAgain | ||
|
||
IF NOT EXIST "%NODE%" ( | ||
:: Irrespective of NODE_ERROR_SHOW, show the error; NODE_ERROR_MSG is guaranteed to be set | ||
ECHO Could not find a Node.js runtime binary %NODE_ERROR_MSG% or on the system >&2 | ||
EXIT /B 1 | ||
) | ||
|
||
:: Node.js binary was found but not where it was told to be, so show a warning | ||
IF DEFINED NODE_ERROR_SHOW ( | ||
ECHO Could not find a Node.js runtime binary %NODE_ERROR_MSG% but found one at %NODE% >&2 | ||
) | ||
|
||
IF EXIST "%CONFIG_DIR%\node.options" ( | ||
FOR /F "eol=# tokens=*" %%i IN (%CONFIG_DIR%\node.options) DO ( | ||
:: This cannot accept spaces within a line of node.options | ||
IF [!OSD_NODE_OPTS!] == [] ( | ||
SET "OSD_NODE_OPTS=%%i" | ||
) ELSE ( | ||
SET "OSD_NODE_OPTS=!OSD_NODE_OPTS! %%i" | ||
) | ||
) | ||
) | ||
|
||
SET "NODE_OPTIONS=%OSD_NODE_OPTS_PREFIX% %OSD_NODE_OPTS% %NODE_OPTIONS%" | ||
|
||
:: If a file path was provided for execution, prefix with OSD_HOME; use relative paths to avoid the need for this. | ||
IF DEFINED OSD_USE_NODE_JS_FILE_PATH ( | ||
"%NODE%" "%OSD_HOME%%OSD_USE_NODE_JS_FILE_PATH%" %* | ||
) ELSE IF NOT "%~1" == "" ( | ||
"%NODE%" %* | ||
) | ||
|
||
ENDLOCAL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.