Skip to content
Merged
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
18 changes: 18 additions & 0 deletions src/webi-packages/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

# webi packages (webi-packages)

Install webi and use it to install specified packages

## Example Usage

```json
"features": {
"ghcr.io/devcontainers-extra/features/webi-packages:1": {}
}
```

## Options

| Options Id | Description | Type | Default Value |
|-----|-----|-----|-----|
| packages | List of packages to install, comma-separated (e.g., 'node@lts', 'deno'). | string | - |
17 changes: 17 additions & 0 deletions src/webi-packages/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"id": "webi-packages",
"version": "1.0.0",
"name": "webi packages",
"documentationURL": "http://github.com/devcontainers-extra/features/tree/main/src/webi-packages",
"description": "Install webi and use it to install specified packages",
"options": {
"packages": {
"type": "string",
"description": "List of packages to install, comma-separated (e.g., 'node@lts', 'deno')",
"default": ""
}
},
"installsAfter": [
"ghcr.io/devcontainers/features/common-utils"
]
}
17 changes: 17 additions & 0 deletions src/webi-packages/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

set -e

USERNAME="${USERNAME:-"${_REMOTE_USER:-"automatic"}"}"
Comment thread
koralowiec marked this conversation as resolved.
PACKAGES="${PACKAGES:-""}"

if [ "$(id -u)" -ne 0 ]; then
echo "Script must be run as root. Use sudo, su, or add \"USER root\" to your Dockerfile before running this script."
exit 1
fi

. ./utils.sh

install_webi "$(determine_user "$USERNAME")" "$PACKAGES"

clean
80 changes: 80 additions & 0 deletions src/webi-packages/utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/usr/bin/env bash

install_webi() {
local USERNAME="$1"
local PACKAGES="$2"

check_command curl

su - "${USERNAME}" <<EOF
if ! command -v webi &>/dev/null; then
echo "Installing webinstall.dev for user ${USERNAME}..."
curl -sS https://webi.sh/webi | sh
source ~/.config/envman/PATH.env
echo "Webinstall.dev installation completed for user ${USERNAME}"
fi

if [ -n "$PACKAGES" ]; then
echo "Installing specified packages: ${PACKAGES}"
webi $(echo "$PACKAGES" | tr ',' ' ')
fi
EOF
}

determine_user() {
local USERNAME="${1:-"auto"}"
if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then
USERNAME=""
check_command awk >/dev/null 2>&1
USERNAME_UID_1000="$(awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd)"
POSSIBLE_USERS=("vscode" "node" "codespace" "${USERNAME_UID_1000}")
for CURRENT_USER in "${POSSIBLE_USERS[@]}"; do
if id -u "${CURRENT_USER}" >/dev/null 2>&1; then
USERNAME=${CURRENT_USER}
break
fi
done
if [ "${USERNAME}" = "" ]; then
USERNAME=root
fi
elif [ "${USERNAME}" = "none" ] || ! id -u "${USERNAME}" >/dev/null 2>&1; then
USERNAME=root
fi

echo "${USERNAME}"
}

check_command() {
local cmd=$1

if command -v "$cmd" &>/dev/null; then
echo "$cmd is already installed"
return 0
fi

echo "$cmd not found, attempting to install..."

if command -v apt &>/dev/null; then
echo "Installing using apt..."
apt update
apt -y install --no-install-recommends "$cmd"
return $?
fi

if command -v apk &>/dev/null; then
echo "Installing using apk..."
apk update
apk add --no-cache "$cmd"
return $?
fi

echo "Error: No supported package manager found (apt/apk)"
return 1
}

clean() {
if command -v apt &>/dev/null; then
apt clean
rm -rf /var/lib/apt/lists/*
fi
}
18 changes: 18 additions & 0 deletions test/webi-packages/scenarios.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"test": {
"image": "mcr.microsoft.com/devcontainers/base:debian",
"features": {
"webi-packages": {
"packages": "node@18,deno"
}
}
},
"test_alpine": {
"image": "mcr.microsoft.com/devcontainers/base:alpine",
"features": {
"webi-packages": {
"packages": "node@18"
}
}
}
}
11 changes: 11 additions & 0 deletions test/webi-packages/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

set -e

source dev-container-features-test-lib

check "node version is equal to 18.*.*" sh -c "node --version | grep '18.*.*'"

check "deno --version" deno --version

reportResults
11 changes: 11 additions & 0 deletions test/webi-packages/test_alpine.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

set -e

source dev-container-features-test-lib

source ~/.config/envman/PATH.env
Comment thread
koralowiec marked this conversation as resolved.

check "node version is equal to 18.*.*" sh -c "node --version | grep '18.*.*'"

reportResults