Skip to content

Commit ea345b5

Browse files
Add Node.js feature (#8)
2 parents 9eff3d4 + ff6df36 commit ea345b5

File tree

7 files changed

+106
-0
lines changed

7 files changed

+106
-0
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ jobs:
1414
features:
1515
- actionlint
1616
- google-cloud-cli
17+
- node
1718
- postgresql-client
1819
- shellcheck
1920
baseImage:
@@ -33,6 +34,7 @@ jobs:
3334
features:
3435
- actionlint
3536
- google-cloud-cli
37+
- node
3638
- postgresql-client
3739
- shellcheck
3840
continue-on-error: true

src/node/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# node
2+
3+
Install [Node.js](https://nodejs.org) from [Nodesource's DEB repository](https://deb.nodesource.com).
4+
5+
## Usage
6+
7+
```json
8+
"features": {
9+
"ghcr.io/CargoSense/devcontainer-features/node:1": {}
10+
}
11+
```
12+
13+
## Options
14+
15+
| Option ID | Description | Type | Default Value |
16+
|:----------|:--------------------------------|:-------|:--------------|
17+
| `version` | The Node.js version to install. | string | `22` |
18+
19+
## OS Support
20+
21+
This Feature should work on recent versions of Debian/Ubuntu and Linux distributions using the [apt](https://wiki.debian.org/AptCLI) management tool.

src/node/devcontainer-feature.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "Node.js",
3+
"id": "node",
4+
"version": "1.0.0",
5+
"description": "Install Node.js from Nodesource's DEB repository.",
6+
"options": {
7+
"version": {
8+
"type": "string",
9+
"enum": [
10+
"18",
11+
"20",
12+
"21",
13+
"22",
14+
"23"
15+
],
16+
"default": "22",
17+
"description": "Select or enter a Node.js version."
18+
}
19+
},
20+
"installsAfter": [
21+
"ghcr.io/devcontainers/features/common-utils"
22+
]
23+
}

src/node/install.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env sh
2+
3+
set -e
4+
5+
NODE_VERSION="${VERSION:-"22"}"
6+
7+
curl_installed=""
8+
9+
if ! type curl >/dev/null 2>&1; then
10+
apt update --yes
11+
apt install --no-install-recommends --yes curl ca-certificates
12+
13+
curl_installed="true"
14+
fi
15+
16+
curl -fsSL https://deb.nodesource.com/setup_"${NODE_VERSION}".x | bash -
17+
18+
apt update --yes
19+
apt install --no-install-recommends --yes nodejs
20+
21+
if [ -n "${curl_installed}" ]; then
22+
apt purge curl --autoremove --yes
23+
fi

test/node/node-20.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
# Optional: Import test library bundled with the devcontainer CLI
6+
# shellcheck source=/dev/null
7+
source dev-container-features-test-lib
8+
9+
# Feature-specific tests
10+
check "version" bash -c "node --version | grep -E 'v20\..+'"
11+
12+
# Report result
13+
reportResults

test/node/scenarios.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"node-20": {
3+
"image": "debian:latest",
4+
"features": {
5+
"node": {
6+
"version": "20"
7+
}
8+
}
9+
}
10+
}

test/node/test.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
# Optional: Import test library bundled with the devcontainer CLI
6+
# shellcheck source=/dev/null
7+
source dev-container-features-test-lib
8+
9+
# Feature-specific tests
10+
check "version" node --version
11+
check "which node" bash -c "which node | grep /usr/bin/node"
12+
13+
# Report result
14+
reportResults

0 commit comments

Comments
 (0)