-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
recognize L7_NODE_VERSION var; add test for nodejs version shims
- Loading branch information
Showing
11 changed files
with
86 additions
and
9 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
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 |
---|---|---|
@@ -1,3 +1,2 @@ | ||
#!/bin/bash | ||
export RUNNER_IMAGE=${NODE_RUNNER_IMAGE:-${RUNNER_IMAGE}} | ||
l7-run-node node ${@} |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#!/bin/bash | ||
export RUNNER_IMAGE="localhost/l7/node:16-bookworm" | ||
export L7_NODE_VERSION=16 | ||
l7-run-node node ${@} |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#!/bin/bash | ||
export RUNNER_IMAGE="localhost/l7/node:18-bookworm" | ||
export L7_NODE_VERSION=18 | ||
l7-run-node node ${@} |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#!/bin/bash | ||
export RUNNER_IMAGE="localhost/l7/node:20-bookworm" | ||
export L7_NODE_VERSION=20 | ||
l7-run-node node ${@} |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#!/bin/bash | ||
export RUNNER_IMAGE="localhost/l7/node:22-bookworm" | ||
export L7_NODE_VERSION=22 | ||
l7-run-node node ${@} |
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 |
---|---|---|
|
@@ -2,6 +2,25 @@ | |
|
||
During development, we often need to run various nodejs modules - be it workflow tools, linting, or even the application itself under test. In order to reduce impact of potentially untrusted code, Node.js commands are shimmed and proxied to a sibling container. While the sibling container has the same source directories available, it is not otherwise able to access the editor or host contexts. Each command is run in an ephemeral container. Apart from the `SRC_DIR`, caches are persisted for `npm`, `pnpm`, and `yarn`. | ||
|
||
## Node.js versions | ||
|
||
Inside the editor context, each invocation of `node` spawns a new container using the default Node.js version. If you want to run a different version of Node.js, there are two ways: | ||
|
||
``` | ||
> node --version | ||
v20.14.0 | ||
> node-18 --version | ||
v18.20.3 | ||
❯ L7_NODE_VERSION=18 node --version | ||
v18.20.3 | ||
``` | ||
|
||
The `node-xx` shims are provided for convenience. | ||
You can `export L7_NODE_VERSION=22` to have the desired version used by scripts. | ||
Using either of these methods is preferred over using third-party version managers like nvm or asdf. | ||
|
||
## Package manager versions | ||
|
||
Any supported package manager should be auto-detected as long as it's properly specified in the `packageManager` field in `package.json`: | ||
|
@@ -22,21 +41,41 @@ Any supported package manager should be auto-detected as long as it's properly s | |
4.2.2 | ||
``` | ||
|
||
If you need to manually call a specific version of a package manager, there are shims available: | ||
|
||
``` | ||
> npm<tab><tab> | ||
npm npm10 npm7 npm9 | ||
> npm --version | ||
9.9.3 | ||
> npm10 --version | ||
10.8.1 | ||
``` | ||
|
||
The prebundled package manager versions can be overridden by the `COREPACK_PMS` build-arg: | ||
|
||
``` | ||
$ make BUILD_OPTIONS='--build-arg COREPACK_PMS="[email protected] npm@10 ..."' images | ||
``` | ||
|
||
## The node runner container | ||
## The node runner containers | ||
|
||
You may shell into a node container if you need longer sessions or troubleshooting; | ||
|
||
``` | ||
> RUNNER_OPTS='-t ' l7-cnt-run zsh | ||
> l7-run-node bash | ||
``` | ||
|
||
`l7-cnt-run` is also the entrypoint for the node command shims like `node`, `npm`, `yarn`, `allow-scripts`, etc. Shims can be overridden by the `NODE_BINS` build-arg: | ||
You can override arguments passed to the container `run` command: | ||
``` | ||
# Run as root | ||
> RUNNER_OPTS='--user=root' l7-run-node bash | ||
``` | ||
|
||
|
||
`l7-run-node` is also the entrypoint for the node command shims like `node`, `npm`, `yarn`, `allow-scripts`, etc. Shims can be overridden by the `NODE_BINS` build-arg: | ||
|
||
``` | ||
$ make BUILD_OPTIONS='--build-arg NODE_BINS="allow-script npx ..."' images | ||
|
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,21 @@ | ||
#!/bin/bash | ||
# test shims for major nodejs versions | ||
export L7_SRC_DIR=$(pwd) | ||
for nv in 18 20 22; do | ||
version=$(NAME="l7ide-test-runner-nv" ./devenv.sh node-${nv} --version) | ||
# compare if major version is same as expected | ||
if [[ "$(echo "${version}" | grep -o '[0-9]*' | head -n1)" != "${nv}" ]]; then | ||
echo "FAIL: node-${nv} is ${version}" >&2 | ||
export TESTFAIL=1 | ||
if [[ -z "${version}" ]]; then | ||
echo "(Try 'make image_runner_node_${nv}')" | ||
fi | ||
continue | ||
fi | ||
echo "PASS: node-${nv} is ${version}" >&2 | ||
done | ||
if [[ -n "${TESTFAIL}" ]]; then | ||
echo "(Try 'make image_runner_node_all')" | ||
exit 1 | ||
fi | ||
|