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
2 changes: 1 addition & 1 deletion src/java/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "java",
"version": "1.8.0",
"version": "1.8.1",
"name": "Java (via SDKMAN!)",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/java",
"description": "Installs Java, SDKMAN! (if not installed), and needed dependencies.",
Expand Down
28 changes: 26 additions & 2 deletions src/java/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,29 @@ updaterc() {
fi
}

run_with_retries() {
local max_attempts="$1"
local wait_seconds="$2"
local operation="$3"
local attempt=1
shift 3

until "$@"; do
if [ "${attempt}" -ge "${max_attempts}" ]; then
echo "(!) ${operation} failed after ${max_attempts} attempts."
return 1
fi

echo "(*) ${operation} failed on attempt ${attempt}. Retrying in ${wait_seconds}s..."
attempt=$((attempt + 1))
sleep "${wait_seconds}"
done
}

install_sdkman_cli() {
bash -o pipefail -c 'curl -fsSL "https://get.sdkman.io?rcupdate=false" | bash'
}

find_version_list() {
prefix="$1"
suffix="$2"
Expand Down Expand Up @@ -284,7 +307,8 @@ sdk_install() {
JAVA_VERSION=${requested_version}
fi

su ${USERNAME} -c "umask 0002 && . ${SDKMAN_DIR}/bin/sdkman-init.sh && sdk install ${install_type} ${requested_version} && sdk flush archives && sdk flush temp"
run_with_retries 5 10 "Installing ${install_type} ${requested_version} via SDKMAN" \
su ${USERNAME} -c "umask 0002 && . ${SDKMAN_DIR}/bin/sdkman-init.sh && sdk install ${install_type} ${requested_version} && sdk flush archives && sdk flush temp"
}

export DEBIAN_FRONTEND=noninteractive
Expand Down Expand Up @@ -323,7 +347,7 @@ if [ ! -d "${SDKMAN_DIR}" ]; then
if [ "${ADJUSTED_ID}" = "rhel" ] && [ "${MAJOR_VERSION_ID}" = "8" ]; then
export SDKMAN_NATIVE_VERSION="false"
fi
curl -sSL "https://get.sdkman.io?rcupdate=false" | bash
run_with_retries 5 10 "Installing SDKMAN" install_sdkman_cli
# For RHEL 8 systems, also disable native CLI in config file and remove native binaries
if [ "${ADJUSTED_ID}" = "rhel" ] && [ "${MAJOR_VERSION_ID}" = "8" ]; then
# Disable native CLI in config to prevent future usage
Expand Down
6 changes: 2 additions & 4 deletions src/nix/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,8 @@ fi
chmod +x,o+r ${FEATURE_DIR} ${FEATURE_DIR}/post-install-steps.sh
if [ "${MULTIUSER}" = "true" ]; then
/usr/local/share/nix-entrypoint.sh
su ${USERNAME} -c "
. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
${FEATURE_DIR}/post-install-steps.sh
"
. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
NIX_FEATURE_INSTALL_PROFILE=/nix/var/nix/profiles/default ${FEATURE_DIR}/post-install-steps.sh
else
su ${USERNAME} -c "
. \$HOME/.nix-profile/etc/profile.d/nix.sh
Expand Down
14 changes: 11 additions & 3 deletions src/nix/post-install-steps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
set -e
echo "(*) Executing post-installation steps..."

# In multi-user mode, install into the default profile that is on PATH.
NIX_ENV_PROFILE_ARGS=()
NIX_PROFILE_INSTALL_ARGS=()
if [ -n "${NIX_FEATURE_INSTALL_PROFILE}" ]; then
NIX_ENV_PROFILE_ARGS=(-p "${NIX_FEATURE_INSTALL_PROFILE}")
NIX_PROFILE_INSTALL_ARGS=(--profile "${NIX_FEATURE_INSTALL_PROFILE}")
fi

# if not starts with "nixpkgs." add it as prefix to package name
add_nixpkgs_prefix() {
local packages=$1
Expand All @@ -20,17 +28,17 @@ if [ ! -z "${PACKAGES}" ] && [ "${PACKAGES}" != "none" ]; then
if [ "${USEATTRIBUTEPATH}" = "true" ]; then
PACKAGES=$(add_nixpkgs_prefix "$PACKAGES")
echo "Installing packages \"${PACKAGES}\" in profile..."
nix-env -iA ${PACKAGES}
nix-env "${NIX_ENV_PROFILE_ARGS[@]}" -iA ${PACKAGES}
else
echo "Installing packages \"${PACKAGES}\" in profile..."
nix-env --install ${PACKAGES}
nix-env "${NIX_ENV_PROFILE_ARGS[@]}" --install ${PACKAGES}
fi
fi

# Install Nix flake in profile if specified
if [ ! -z "${FLAKEURI}" ] && [ "${FLAKEURI}" != "none" ]; then
echo "Installing flake ${FLAKEURI} in profile..."
nix profile install "${FLAKEURI}"
nix profile install "${NIX_PROFILE_INSTALL_ARGS[@]}" "${FLAKEURI}"
fi

nix-collect-garbage --delete-old
Expand Down
24 changes: 24 additions & 0 deletions src/node/NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,27 @@ Debian/Ubuntu, RedHat Enterprise Linux, Fedora, Alma, and Rocky Linux distributi
**Note**: RedHat 7 Family (RedHat, CentOS, etc.) must use Node versions less than 18 due to its system libraries and long-term support (LTS) policies.

`bash` is required to execute the `install.sh` script.

## Pre-bundled items

> [!NOTE]
> Beyond the core install, this feature also sets up a few items by default for convenience — recommended VS Code extensions (such as a linter) and supporting tools. This is intentional behavior shared across features in this repository.

## Excluding pre-bundled items

Exclude a bundled **VS Code extension** by prefixing its ID with `-`, or (when supported by a feature option) disable a bundled **tool** by setting its version option to `none` (for example, `pnpmVersion`: `none`):

```json
{
"features": {
"ghcr.io/devcontainers/features/node:2": {
"pnpmVersion": "none"
}
},
"customizations": {
"vscode": {
"extensions": [ "-dbaeumer.vscode-eslint" ]
}
}
}
```
4 changes: 2 additions & 2 deletions test/java/install_latest_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ source dev-container-features-test-lib
echo 'public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); } }' > HelloWorld.java
javac HelloWorld.java

check "hello world" /bin/bash -c "java HelloWorld | grep "Hello, World!""
check "java version latest installed" grep "25" <(java --version)
check "hello world" /bin/bash -c 'java HelloWorld | grep "Hello, World!"'
check "java version latest installed" grep "26" <(java --version)

# Report result
reportResults
1 change: 1 addition & 0 deletions test/nix/packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ check "nix-env" type nix-env
check "vim_installed" type vim
check "node_installed" type node
check "yarn_installed" type yarn
check "vim_in_default_profile" bash -lc "nix-env -p /nix/var/nix/profiles/default -q | grep -q '^vim'"

# Report result
# If any of the checks above exited with a non-zero exit code, the test will fail.
Expand Down
2 changes: 1 addition & 1 deletion test/nix/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"remoteUser": "vscode",
"features": {
"nix": {
"packages": "nodePackages.nodejs,nixpkgs.vim,nixpkgs.yarn",
"packages": "nodejs,nixpkgs.vim,nixpkgs.yarn",
"useAttributePath": true
}
}
Expand Down
Loading