Skip to content
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 1 commit into from
Mar 20, 2023

Conversation

AMoo-Miki
Copy link
Collaborator

@AMoo-Miki AMoo-Miki commented Feb 28, 2023

Description

New reusable use_node scripts take care of selecting the correct Node.js binary based OSD_NODE_HOME, OSD_HOME, and whatever is in the PATH. It also takes care of finding the binary on FreeBSD.

  • 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.

Issues Resolved

Fixes #1219
Fixes #3502
Partially serves #3095

Check List

  • All tests pass
    • yarn test:jest
    • yarn test:jest_integration
    • yarn test:ftr
  • New functionality includes testing.
  • New functionality has been documented.
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

@AMoo-Miki AMoo-Miki requested a review from a team as a code owner February 28, 2023 20:37
Copy link
Member

@peterzhuamazon peterzhuamazon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @AMoo-Miki,

Great change and I have a few questions.

Thanks.

scripts/use_node Show resolved Hide resolved
scripts/use_node Outdated Show resolved Hide resolved
@@ -0,0 +1,97 @@
#!/bin/sh
Copy link
Member

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 to sh.

Copy link
Collaborator Author

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?

Copy link
Member

@peterzhuamazon peterzhuamazon Feb 28, 2023

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 install env by default as well.
On debian I have already force a #!/bin/bash just to avoid.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Collaborator Author

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/

Copy link
Member

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.

Copy link
Member

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?

Copy link
Member

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 ^

Copy link
Collaborator Author

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.

scripts/use_node Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Feb 28, 2023

Codecov Report

Merging #3508 (90ef3d6) into main (1e127b0) will increase coverage by 0.05%.
The diff coverage is n/a.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##             main    #3508      +/-   ##
==========================================
+ Coverage   66.41%   66.47%   +0.05%     
==========================================
  Files        3206     3206              
  Lines       61597    61597              
  Branches     9503     9503              
==========================================
+ Hits        40909    40944      +35     
+ Misses      18410    18380      -30     
+ Partials     2278     2273       -5     
Flag Coverage Δ
Linux 66.41% <ø> (+<0.01%) ⬆️
Windows 66.41% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

see 8 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Member

@peterzhuamazon peterzhuamazon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a nitpik

scripts/use_node Outdated Show resolved Hide resolved
scripts/use_node Outdated

SCRIPT="$0"

OS=$(uname -s | awk '{print tolower}')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awk '{print tolower}'

is failing for me so I don't get an OS. $OS outputs as empty for me on my Ubuntu

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Peter made this suggestion. I will revert back to what we had before.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reverted this piece.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@peterzhuamazon I had to revert this change.

@AMoo-Miki AMoo-Miki force-pushed the allow-alt-node branch 2 times, most recently from 0762642 to 8e0d6a3 Compare March 13, 2023 22:50
@kavilla
Copy link
Member

kavilla commented Mar 14, 2023

Did we want to update stuff where we reference node like these and update the plugin generation scripts:

And update the packages package.json like:

"build": "node ./scripts/build.js",

@AMoo-Miki AMoo-Miki force-pushed the allow-alt-node branch 2 times, most recently from 8c38067 to 88f95e3 Compare March 14, 2023 19:35
@AMoo-Miki
Copy link
Collaborator Author

AMoo-Miki commented Mar 14, 2023

I did not change the instructions since use_node is meant for internal execution and users get to choose which node they want when they use it to execute individual js files.

New reusable use_node scripts take care of selecting the correct Node.js binary based OSD_NODE_HOME, OSD_HOME, and whatever is in the PATH. It also takes care of finding the binary on FreeBSD.
* 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 file templates and shell scripts to internally use `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]>
Copy link
Member

@kavilla kavilla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

Barring the creation of the follow standardization and some dev documentation. LGTM!

Copy link
Member

@joshuarrrr joshuarrrr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bash-fu is incredibly limited, so I'm not sure I'm able to catch much in the actual implementation, but looks good to me!


ENDLOCAL
ENDLOCAL
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit - missing blank line?

@joshuarrrr
Copy link
Member

@AMoo-Miki @kavilla This is just targeting 2.x, right? No need to backport to 1.x?

@joshuarrrr joshuarrrr merged commit cb472dc into opensearch-project:main Mar 20, 2023
opensearch-trigger-bot bot pushed a commit that referenced this pull request Mar 20, 2023
New reusable use_node scripts take care of selecting the correct Node.js binary based OSD_NODE_HOME, OSD_HOME, and whatever is in the PATH. It also takes care of finding the binary on FreeBSD.
* 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 file templates and shell scripts to internally use `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]>
(cherry picked from commit cb472dc)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md
kappassov pushed a commit to kappassov/OpenSearch-Dashboards that referenced this pull request Mar 21, 2023
New reusable use_node scripts take care of selecting the correct Node.js binary based OSD_NODE_HOME, OSD_HOME, and whatever is in the PATH. It also takes care of finding the binary on FreeBSD.
* 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 file templates and shell scripts to internally use `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]>
@AMoo-Miki
Copy link
Collaborator Author

@AMoo-Miki @kavilla This is just targeting 2.x, right? No need to backport to 1.x?

Correct. 1.x will need some extra love to use this.

pjfitzgibbons pushed a commit to pjfitzgibbons/OpenSearch-Dashboards that referenced this pull request Mar 22, 2023
New reusable use_node scripts take care of selecting the correct Node.js binary based OSD_NODE_HOME, OSD_HOME, and whatever is in the PATH. It also takes care of finding the binary on FreeBSD.
* 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 file templates and shell scripts to internally use `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]>
abbyhu2000 pushed a commit that referenced this pull request Mar 22, 2023
…3633)

* added prepare command

Signed-off-by: kappassov <[email protected]>

* Use mirrors to download Node.js binaries to escape sporadic 404 errors (#3619)

Issue Resolved:
#3618

Signed-off-by: Anan Zhuang <[email protected]>

* Allow selecting the Node.js binary OSD uses (#3508)

New reusable use_node scripts take care of selecting the correct Node.js binary based OSD_NODE_HOME, OSD_HOME, and whatever is in the PATH. It also takes care of finding the binary on FreeBSD.
* 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 file templates and shell scripts to internally use `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]>

* Clean up and rebuild @osd/pm (#3570)

* Fix the build failures
* Removed some unused packages
* Update gist url templates in Lychee's exclusion list

Signed-off-by: Miki <[email protected]>

* Refactor dev tool console to use opensearch-js client to send request (#3544)

Refactor dev tool console to use opensearch-js client to interact with OpenSearch

Signed-off-by: Su <[email protected]>

* updates after the 1st review

Signed-off-by: kappassov <[email protected]>

---------

Signed-off-by: kappassov <[email protected]>
Signed-off-by: Anan Zhuang <[email protected]>
Signed-off-by: Miki <[email protected]>
Signed-off-by: Su <[email protected]>
Co-authored-by: Anan Zhuang <[email protected]>
Co-authored-by: Miki <[email protected]>
Co-authored-by: Zhongnan Su <[email protected]>
opensearch-trigger-bot bot pushed a commit that referenced this pull request Mar 22, 2023
…3633)

* added prepare command

Signed-off-by: kappassov <[email protected]>

* Use mirrors to download Node.js binaries to escape sporadic 404 errors (#3619)

Issue Resolved:
#3618

Signed-off-by: Anan Zhuang <[email protected]>

* Allow selecting the Node.js binary OSD uses (#3508)

New reusable use_node scripts take care of selecting the correct Node.js binary based OSD_NODE_HOME, OSD_HOME, and whatever is in the PATH. It also takes care of finding the binary on FreeBSD.
* 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 file templates and shell scripts to internally use `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]>

* Clean up and rebuild @osd/pm (#3570)

* Fix the build failures
* Removed some unused packages
* Update gist url templates in Lychee's exclusion list

Signed-off-by: Miki <[email protected]>

* Refactor dev tool console to use opensearch-js client to send request (#3544)

Refactor dev tool console to use opensearch-js client to interact with OpenSearch

Signed-off-by: Su <[email protected]>

* updates after the 1st review

Signed-off-by: kappassov <[email protected]>

---------

Signed-off-by: kappassov <[email protected]>
Signed-off-by: Anan Zhuang <[email protected]>
Signed-off-by: Miki <[email protected]>
Signed-off-by: Su <[email protected]>
Co-authored-by: Anan Zhuang <[email protected]>
Co-authored-by: Miki <[email protected]>
Co-authored-by: Zhongnan Su <[email protected]>
(cherry picked from commit b0146e7)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
abbyhu2000 pushed a commit that referenced this pull request Mar 22, 2023
…3633) (#3651)

* added prepare command



* Use mirrors to download Node.js binaries to escape sporadic 404 errors (#3619)

Issue Resolved:
#3618



* Allow selecting the Node.js binary OSD uses (#3508)

New reusable use_node scripts take care of selecting the correct Node.js binary based OSD_NODE_HOME, OSD_HOME, and whatever is in the PATH. It also takes care of finding the binary on FreeBSD.
* 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 file templates and shell scripts to internally use `use_node`.
* Update the build scripts to copy `use_node` into releases
* Make tests that execute node internally, honor the binary being used.



* Clean up and rebuild @osd/pm (#3570)

* Fix the build failures
* Removed some unused packages
* Update gist url templates in Lychee's exclusion list



* Refactor dev tool console to use opensearch-js client to send request (#3544)

Refactor dev tool console to use opensearch-js client to interact with OpenSearch



* updates after the 1st review



---------








(cherry picked from commit b0146e7)

Signed-off-by: kappassov <[email protected]>
Signed-off-by: Anan Zhuang <[email protected]>
Signed-off-by: Miki <[email protected]>
Signed-off-by: Su <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Anan Zhuang <[email protected]>
Co-authored-by: Miki <[email protected]>
Co-authored-by: Zhongnan Su <[email protected]>
pjfitzgibbons pushed a commit to pjfitzgibbons/OpenSearch-Dashboards that referenced this pull request Mar 24, 2023
…pensearch-project#3633)

* added prepare command

Signed-off-by: kappassov <[email protected]>

* Use mirrors to download Node.js binaries to escape sporadic 404 errors (opensearch-project#3619)

Issue Resolved:
opensearch-project#3618

Signed-off-by: Anan Zhuang <[email protected]>

* Allow selecting the Node.js binary OSD uses (opensearch-project#3508)

New reusable use_node scripts take care of selecting the correct Node.js binary based OSD_NODE_HOME, OSD_HOME, and whatever is in the PATH. It also takes care of finding the binary on FreeBSD.
* 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 file templates and shell scripts to internally use `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]>

* Clean up and rebuild @osd/pm (opensearch-project#3570)

* Fix the build failures
* Removed some unused packages
* Update gist url templates in Lychee's exclusion list

Signed-off-by: Miki <[email protected]>

* Refactor dev tool console to use opensearch-js client to send request (opensearch-project#3544)

Refactor dev tool console to use opensearch-js client to interact with OpenSearch

Signed-off-by: Su <[email protected]>

* updates after the 1st review

Signed-off-by: kappassov <[email protected]>

---------

Signed-off-by: kappassov <[email protected]>
Signed-off-by: Anan Zhuang <[email protected]>
Signed-off-by: Miki <[email protected]>
Signed-off-by: Su <[email protected]>
Co-authored-by: Anan Zhuang <[email protected]>
Co-authored-by: Miki <[email protected]>
Co-authored-by: Zhongnan Su <[email protected]>
sikhote pushed a commit to sikhote/OpenSearch-Dashboards that referenced this pull request Apr 24, 2023
New reusable use_node scripts take care of selecting the correct Node.js binary based OSD_NODE_HOME, OSD_HOME, and whatever is in the PATH. It also takes care of finding the binary on FreeBSD.
* 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 file templates and shell scripts to internally use `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]>
Signed-off-by: David Sinclair <[email protected]>
sikhote pushed a commit to sikhote/OpenSearch-Dashboards that referenced this pull request Apr 24, 2023
…pensearch-project#3633)

* added prepare command

Signed-off-by: kappassov <[email protected]>

* Use mirrors to download Node.js binaries to escape sporadic 404 errors (opensearch-project#3619)

Issue Resolved:
opensearch-project#3618

Signed-off-by: Anan Zhuang <[email protected]>

* Allow selecting the Node.js binary OSD uses (opensearch-project#3508)

New reusable use_node scripts take care of selecting the correct Node.js binary based OSD_NODE_HOME, OSD_HOME, and whatever is in the PATH. It also takes care of finding the binary on FreeBSD.
* 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 file templates and shell scripts to internally use `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]>

* Clean up and rebuild @osd/pm (opensearch-project#3570)

* Fix the build failures
* Removed some unused packages
* Update gist url templates in Lychee's exclusion list

Signed-off-by: Miki <[email protected]>

* Refactor dev tool console to use opensearch-js client to send request (opensearch-project#3544)

Refactor dev tool console to use opensearch-js client to interact with OpenSearch

Signed-off-by: Su <[email protected]>

* updates after the 1st review

Signed-off-by: kappassov <[email protected]>

---------

Signed-off-by: kappassov <[email protected]>
Signed-off-by: Anan Zhuang <[email protected]>
Signed-off-by: Miki <[email protected]>
Signed-off-by: Su <[email protected]>
Co-authored-by: Anan Zhuang <[email protected]>
Co-authored-by: Miki <[email protected]>
Co-authored-by: Zhongnan Su <[email protected]>
Signed-off-by: David Sinclair <[email protected]>
while [ -h "$SCRIPT" ] ; do
loc=$(ls -ld "$SCRIPT")
# Drop everything prior to ->
link=$(expr "$loc" : '.*-> \(.*\)$')
Copy link
Member

@joshuali925 joshuali925 Jul 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not something like realpath "$SCRIPT"?

nvm i just found realpath is not part of posix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants