Skip to content

Commit 7a72cde

Browse files
authored
Add bun devcontainer feature (#13)
1 parent 0b227f6 commit 7a72cde

9 files changed

Lines changed: 100 additions & 0 deletions

features/src/bun/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Bun (bun)
2+
3+
Installs [Bun](https://bun.com/) JavaScript runtime via the official installer.
4+
5+
## Usage
6+
7+
```json
8+
"features": {
9+
"ghcr.io/shokkunrf/devcontainer-features/bun": {}
10+
}
11+
```
12+
13+
## Requirements
14+
15+
- `curl` or `wget` must be available in the container
16+
- `bash` must be available in the container
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"id": "bun",
3+
"version": "1.0.0",
4+
"name": "Bun",
5+
"documentationURL": "https://github.com/shokkunrf/devcontainer/tree/develop/features/src/bun/README.md",
6+
"description": "Installs Bun JavaScript runtime via the official installer",
7+
"options": {},
8+
"installsAfter": ["ghcr.io/devcontainers/features/common-utils"]
9+
}

features/src/bun/install.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
# References:
3+
# - https://bun.com/docs/installation
4+
5+
set -eu
6+
7+
echo "Activating feature 'bun'"
8+
9+
_install_bun() {
10+
if command -v curl >/dev/null; then
11+
download_cmd="curl -fsSL https://bun.com/install"
12+
elif command -v wget >/dev/null; then
13+
download_cmd="wget -qO- https://bun.com/install"
14+
else
15+
echo "ERROR: curl or wget is required but neither was found!"
16+
return 1
17+
fi
18+
19+
# Install as remote user if running as root with non-root remote user
20+
if [ "$(id -u)" = "0" ] && [ -n "${_REMOTE_USER:-}" ] && [ "$_REMOTE_USER" != "root" ]; then
21+
su - "$_REMOTE_USER" -c "$download_cmd | bash"
22+
else
23+
$download_cmd | bash
24+
fi
25+
}
26+
27+
_install_bun
28+
29+
echo "Bun installed successfully!"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test.sh
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test.sh
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test.sh
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test.sh

features/test/bun/scenarios.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"official-debian": {
3+
"image": "debian:trixie",
4+
"features": {
5+
"ghcr.io/devcontainers/features/common-utils:2": {},
6+
"bun": {}
7+
}
8+
},
9+
"devcontainer-base-debian": {
10+
"image": "mcr.microsoft.com/devcontainers/base:debian",
11+
"features": {
12+
"bun": {}
13+
},
14+
"remoteUser": "vscode"
15+
},
16+
"devcontainer-base-ubuntu-root": {
17+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
18+
"features": {
19+
"bun": {}
20+
}
21+
},
22+
"devcontainer-base-ubuntu-remote-user": {
23+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
24+
"features": {
25+
"bun": {}
26+
},
27+
"remoteUser": "vscode"
28+
}
29+
}

features/test/bun/test.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Optional: Import test library
6+
source dev-container-features-test-lib
7+
8+
# Definition specific tests
9+
check "bun is installed" bun --version
10+
check "bun is upgradable" bun upgrade
11+
12+
# Report result
13+
reportResults

0 commit comments

Comments
 (0)