-
Notifications
You must be signed in to change notification settings - Fork 940
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow selecting the Node.js binary OSD uses #3508
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -9,9 +9,9 @@ | |
"author": "Ahmad Bamieh <[email protected]>", | ||
"license": "Apache-2.0", | ||
"scripts": { | ||
"build": "node scripts/build", | ||
"osd:bootstrap": "node scripts/build --source-maps", | ||
"osd:watch": "node scripts/build --source-maps --watch" | ||
"build": "../../scripts/use_node scripts/build", | ||
"osd:bootstrap": "../../scripts/use_node scripts/build --source-maps", | ||
"osd:watch": "../../scripts/use_node scripts/build --source-maps --watch" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.16.0", | ||
|
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
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
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
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" | ||
AMoo-Miki marked this conversation as resolved.
Show resolved
Hide resolved
|
||
else | ||
OS="other" | ||
fi | ||
|
||
# SCRIPT may be an arbitrarily deep series of symlinks. Loop until we have the concrete path. | ||
while [ -h "$SCRIPT" ] ; do | ||
loc=$(ls -ld "$SCRIPT") | ||
# Drop everything prior to -> | ||
link=$(expr "$loc" : '.*-> \(.*\)$') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not something like nvm i just found |
||
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 | ||
kavilla marked this conversation as resolved.
Show resolved
Hide resolved
|
||
NODE="${LOCALBASE}/bin/node" | ||
else | ||
NODE="$(command -v 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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not recommended as ubuntu is using
ash
linking tosh
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what OSD used before but I see that OS uses
#!/usr/bin/env bash
. Shall I use that?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhh, if that is the case better just keep
#!/bin
as not all the docker images installenv
by default as well.On debian I have already force a
#!/bin/bash
just to avoid.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really dont have too much solution to this generalized script tho.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If OS is already using env, then we probably can just use.
At least env is more common than which not being installed.
Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@peterzhuamazon I did some reading and most of what I found reasonable indicate a preference for using
#!/bin/sh
.https://stackoverflow.com/a/55927235
https://unix.stackexchange.com/a/496523
https://www.ixsystems.com/blog/migrating-from-linux-to-freebsd/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @AMoo-Miki !
I have no issue with that then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it was intentional to not make this use_node.sh and set as bin/bash? If so should we migrate the other shell scripts to this format?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AMoo-Miki any comment about the above ^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should standardize what we do. I will raise an issue for it.