Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/node/NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,15 @@ Debian/Ubuntu, RedHat Enterprise Linux, Fedora, Alma, and Rocky Linux distributi
**Note**: RedHat 7 Family (RedHat, CentOS, etc.) must use Node versions less than 18 due to its system libraries and long-term support (LTS) policies.

`bash` is required to execute the `install.sh` script.

## Setting a private Node.js mirror

If you need to use a private mirror for downloading Node.js binaries (e.g. in an air-gapped environment), you can use the `nvmNodeJsOrgMirror` option:

```json
"features": {
"ghcr.io/devcontainers/features/node:1": {
"nvmNodeJsOrgMirror": "https://my-private-registry.com/node-dist"
}
}
```
13 changes: 13 additions & 0 deletions src/node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Installs Node.js, nvm, yarn, pnpm, and needed dependencies.
| nvmInstallPath | The path where NVM will be installed. | string | /usr/local/share/nvm |
| pnpmVersion | Select or enter the PNPM version to install | string | latest |
| nvmVersion | Version of NVM to install. | string | latest |
| nvmNodeJsOrgMirror | The mirror of the Node.js binaries. Use this to point to a private mirror. | string | - |
| installYarnUsingApt | On Debian and Ubuntu systems, you have the option to install Yarn globally via APT. If you choose not to use this option, Yarn will be set up using Corepack instead. This choice is specific to Debian and Ubuntu; for other Linux distributions, Yarn is always installed using Corepack, with a fallback to installation via NPM if an error occurs. | boolean | true |

## Customizations
Expand Down Expand Up @@ -56,6 +57,18 @@ Debian/Ubuntu, RedHat Enterprise Linux, Fedora, Alma, and Rocky Linux distributi

`bash` is required to execute the `install.sh` script.

## Setting a private Node.js mirror

If you need to use a private mirror for downloading Node.js binaries (e.g. in an air-gapped environment), you can use the `nvmNodeJsOrgMirror` option:

```json
"features": {
"ghcr.io/devcontainers/features/node:1": {
"nvmNodeJsOrgMirror": "https://my-private-registry.com/node-dist"
}
}
```


---

Expand Down
6 changes: 5 additions & 1 deletion src/node/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "node",
"version": "1.6.3",
"version": "1.6.4",
"name": "Node.js (via nvm), yarn and pnpm",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/node",
"description": "Installs Node.js, nvm, yarn, pnpm, and needed dependencies.",
Expand Down Expand Up @@ -50,6 +50,10 @@
"default": "latest",
"description": "Version of NVM to install."
},
"nvmNodeJsOrgMirror": {
"type": "string",
"description": "The mirror of the Node.js binaries. Use this to point to a private mirror."
},
"installYarnUsingApt": {
"type": "boolean",
"default": true,
Expand Down
7 changes: 5 additions & 2 deletions src/node/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export NODE_VERSION="${VERSION:-"lts"}"
export PNPM_VERSION="${PNPMVERSION:-"latest"}"
export NVM_VERSION="${NVMVERSION:-"latest"}"
export NVM_DIR="${NVMINSTALLPATH:-"/usr/local/share/nvm"}"
export NVM_NODEJS_ORG_MIRROR="${NVMNODEJSORGMIRROR:-}"
INSTALL_TOOLS_FOR_NODE_GYP="${NODEGYPDEPENDENCIES:-true}"
export INSTALL_YARN_USING_APT="${INSTALLYARNUSINGAPT:-true}" # only concerns Debian-based systems

Expand Down Expand Up @@ -302,6 +303,7 @@ find_version_from_git_tags NVM_VERSION "https://github.com/nvm-sh/nvm"
nvm_install_snippet="$(cat << EOF
set -e
umask 0002
${NVM_NODEJS_ORG_MIRROR:+export NVM_NODEJS_ORG_MIRROR="${NVM_NODEJS_ORG_MIRROR}"}
# Do not update profile - we'll do this manually
export PROFILE=/dev/null
curl -so- "https://raw.githubusercontent.com/nvm-sh/nvm/v${NVM_VERSION}/install.sh" | bash || {
Expand All @@ -318,6 +320,7 @@ EOF

# Snippet that should be added into rc / profiles
nvm_rc_snippet="$(cat << EOF
${NVM_NODEJS_ORG_MIRROR:+export NVM_NODEJS_ORG_MIRROR="${NVM_NODEJS_ORG_MIRROR}"}
export NVM_DIR="${NVM_DIR}"
[ -s "\$NVM_DIR/nvm.sh" ] && . "\$NVM_DIR/nvm.sh"
[ -s "\$NVM_DIR/bash_completion" ] && . "\$NVM_DIR/bash_completion"
Expand Down Expand Up @@ -350,7 +353,7 @@ if [ ! -d "${NVM_DIR}" ]; then
else
echo "NVM already installed."
if [ "${NODE_VERSION}" != "" ]; then
su ${USERNAME} -c "umask 0002 && . '$NVM_DIR/nvm.sh' && nvm install '${NODE_VERSION}' && nvm alias default '${NODE_VERSION}'"
su ${USERNAME} -c "umask 0002 && . '$NVM_DIR/nvm.sh' && ${NVM_NODEJS_ORG_MIRROR:+NVM_NODEJS_ORG_MIRROR=\"${NVM_NODEJS_ORG_MIRROR}\"} nvm install '${NODE_VERSION}' && nvm alias default '${NODE_VERSION}'"
fi
fi

Expand All @@ -366,7 +369,7 @@ if [ ! -z "${ADDITIONAL_VERSIONS}" ]; then
IFS=","
read -a additional_versions <<< "$ADDITIONAL_VERSIONS"
for ver in "${additional_versions[@]}"; do
su ${USERNAME} -c "umask 0002 && . '$NVM_DIR/nvm.sh' && nvm install '${ver}'"
su ${USERNAME} -c "umask 0002 && . '$NVM_DIR/nvm.sh' && ${NVM_NODEJS_ORG_MIRROR:+NVM_NODEJS_ORG_MIRROR=\"${NVM_NODEJS_ORG_MIRROR}\"} nvm install '${ver}'"
# possibly install yarn (puts yarn in per-Node install on RHEL, uses system yarn on Debian)
install_yarn "${ver}"
done
Expand Down
8 changes: 8 additions & 0 deletions test/node/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
}
}
},
"test_registry_override": {
"image": "debian:11",
"features": {
"node": {
"nvmNodeJsOrgMirror": "https://nodejs.org/dist"
}
}
},
"install_additional_node": {
"image": "debian:11",
"features": {
Expand Down
14 changes: 14 additions & 0 deletions test/node/test_registry_override.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

set -e

# Import test library
source dev-container-features-test-lib

# Check if env var is set
check "NVM_NODEJS_ORG_MIRROR is set" bash -c "echo $NVM_NODEJS_ORG_MIRROR | grep 'https://nodejs.org/dist'"

# Check if nvm can list remote versions (verifies network/config is vaguely sane)
check "nvm ls-remote" bash -c ". /usr/local/share/nvm/nvm.sh && nvm ls-remote | head"

reportResults