From 8c6393c6ae2c260811d44bcb0debcbcc010b333b Mon Sep 17 00:00:00 2001 From: Jason Garber Date: Mon, 14 Apr 2025 15:49:37 -0400 Subject: [PATCH 1/3] Add Node.js feature --- .github/workflows/test.yml | 2 ++ src/node/README.md | 21 +++++++++++++ src/node/devcontainer-feature.json | 23 +++++++++++++++ src/node/install.sh | 23 +++++++++++++++ test/node/node-20.sh | 46 +++++++++++++++++++++++++++++ test/node/scenarios.json | 10 +++++++ test/node/test.sh | 47 ++++++++++++++++++++++++++++++ 7 files changed, 172 insertions(+) create mode 100644 src/node/README.md create mode 100644 src/node/devcontainer-feature.json create mode 100755 src/node/install.sh create mode 100755 test/node/node-20.sh create mode 100644 test/node/scenarios.json create mode 100755 test/node/test.sh 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..28636fd --- /dev/null +++ b/test/node/node-20.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash + +# This test file will be executed against an auto-generated devcontainer.json that +# includes the 'node' Feature with no options. +# +# For more information, see: https://github.com/devcontainers/cli/blob/main/docs/features/test.md +# +# Eg: +# { +# "image": "<..some-base-image...>", +# "features": { +# "node": {} +# }, +# "remoteUser": "root" +# } +# +# Thus, the value of all options will fall back to the default value in the +# Feature's 'devcontainer-feature.json'. +# +# These scripts are run as 'root' by default. Although that can be changed +# with the '--remote-user' flag. +# +# This test can be run with the following command: +# +# devcontainer features test \ +# --features node \ +# --remote-user root \ +# --skip-scenarios \ +# --base-image mcr.microsoft.com/devcontainers/base:ubuntu \ +# /path/to/this/repo + +set -e + +# Optional: Import test library bundled with the devcontainer CLI +# See https://github.com/devcontainers/cli/blob/HEAD/docs/features/test.md#dev-container-features-test-lib +# Provides the 'check' and 'reportResults' commands. +source dev-container-features-test-lib + +# Feature-specific tests +# The 'check' command comes from the dev-container-features-test-lib. Syntax is... +# check