diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 54c712e..beb3d81 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,6 +14,7 @@ jobs: features: - actionlint - google-cloud-cli + - node - postgresql-client - shellcheck baseImage: @@ -33,6 +34,7 @@ jobs: features: - actionlint - google-cloud-cli + - node - postgresql-client - shellcheck continue-on-error: true diff --git a/src/node/README.md b/src/node/README.md new file mode 100644 index 0000000..7997db9 --- /dev/null +++ b/src/node/README.md @@ -0,0 +1,21 @@ +# node + +Install [Node.js](https://nodejs.org) from [Nodesource's DEB repository](https://deb.nodesource.com). + +## Usage + +```json +"features": { + "ghcr.io/CargoSense/devcontainer-features/node:1": {} +} +``` + +## Options + +| Option ID | Description | Type | Default Value | +|:----------|:--------------------------------|:-------|:--------------| +| `version` | The Node.js version to install. | string | `22` | + +## OS Support + +This Feature should work on recent versions of Debian/Ubuntu and Linux distributions using the [apt](https://wiki.debian.org/AptCLI) management tool. diff --git a/src/node/devcontainer-feature.json b/src/node/devcontainer-feature.json new file mode 100644 index 0000000..28f628d --- /dev/null +++ b/src/node/devcontainer-feature.json @@ -0,0 +1,23 @@ +{ + "name": "Node.js", + "id": "node", + "version": "1.0.0", + "description": "Install Node.js from Nodesource's DEB repository.", + "options": { + "version": { + "type": "string", + "enum": [ + "18", + "20", + "21", + "22", + "23" + ], + "default": "22", + "description": "Select or enter a Node.js version." + } + }, + "installsAfter": [ + "ghcr.io/devcontainers/features/common-utils" + ] +} diff --git a/src/node/install.sh b/src/node/install.sh new file mode 100755 index 0000000..89dafb8 --- /dev/null +++ b/src/node/install.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env sh + +set -e + +NODE_VERSION="${VERSION:-"22"}" + +curl_installed="" + +if ! type curl >/dev/null 2>&1; then + apt update --yes + apt install --no-install-recommends --yes curl ca-certificates + + curl_installed="true" +fi + +curl -fsSL https://deb.nodesource.com/setup_"${NODE_VERSION}".x | bash - + +apt update --yes +apt install --no-install-recommends --yes nodejs + +if [ -n "${curl_installed}" ]; then + apt purge curl --autoremove --yes +fi diff --git a/test/node/node-20.sh b/test/node/node-20.sh new file mode 100755 index 0000000..1f3492b --- /dev/null +++ b/test/node/node-20.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +set -e + +# Optional: Import test library bundled with the devcontainer CLI +# shellcheck source=/dev/null +source dev-container-features-test-lib + +# Feature-specific tests +check "version" bash -c "node --version | grep -E 'v20\..+'" + +# Report result +reportResults diff --git a/test/node/scenarios.json b/test/node/scenarios.json new file mode 100644 index 0000000..469f26f --- /dev/null +++ b/test/node/scenarios.json @@ -0,0 +1,10 @@ +{ + "node-20": { + "image": "debian:latest", + "features": { + "node": { + "version": "20" + } + } + } +} diff --git a/test/node/test.sh b/test/node/test.sh new file mode 100755 index 0000000..66952ca --- /dev/null +++ b/test/node/test.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +set -e + +# Optional: Import test library bundled with the devcontainer CLI +# shellcheck source=/dev/null +source dev-container-features-test-lib + +# Feature-specific tests +check "version" node --version +check "which node" bash -c "which node | grep /usr/bin/node" + +# Report result +reportResults