Skip to content

Commit 99a3f1c

Browse files
fix(java): Add retry logic for transient SDKMAN bootstrap failures (#1688)
* Implement retry logic for SDK installation Added a retry mechanism for SDK installation and SDKMAN CLI installation. * Update Java version from 1.8.0 to 1.8.1 Mandatory minor bump for fixing the sdkman transient error * Update expected Java version in installation script Java version updated due to upstream update from sdkman. * Fix string quotes in install_latest_version.sh * Change curl option from -sSL to -fsSL in install.sh
1 parent 529a88d commit 99a3f1c

3 files changed

Lines changed: 29 additions & 5 deletions

File tree

src/java/devcontainer-feature.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "java",
3-
"version": "1.8.0",
3+
"version": "1.8.1",
44
"name": "Java (via SDKMAN!)",
55
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/java",
66
"description": "Installs Java, SDKMAN! (if not installed), and needed dependencies.",

src/java/install.sh

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,29 @@ updaterc() {
195195
fi
196196
}
197197

198+
run_with_retries() {
199+
local max_attempts="$1"
200+
local wait_seconds="$2"
201+
local operation="$3"
202+
local attempt=1
203+
shift 3
204+
205+
until "$@"; do
206+
if [ "${attempt}" -ge "${max_attempts}" ]; then
207+
echo "(!) ${operation} failed after ${max_attempts} attempts."
208+
return 1
209+
fi
210+
211+
echo "(*) ${operation} failed on attempt ${attempt}. Retrying in ${wait_seconds}s..."
212+
attempt=$((attempt + 1))
213+
sleep "${wait_seconds}"
214+
done
215+
}
216+
217+
install_sdkman_cli() {
218+
bash -o pipefail -c 'curl -fsSL "https://get.sdkman.io?rcupdate=false" | bash'
219+
}
220+
198221
find_version_list() {
199222
prefix="$1"
200223
suffix="$2"
@@ -284,7 +307,8 @@ sdk_install() {
284307
JAVA_VERSION=${requested_version}
285308
fi
286309

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

290314
export DEBIAN_FRONTEND=noninteractive
@@ -323,7 +347,7 @@ if [ ! -d "${SDKMAN_DIR}" ]; then
323347
if [ "${ADJUSTED_ID}" = "rhel" ] && [ "${MAJOR_VERSION_ID}" = "8" ]; then
324348
export SDKMAN_NATIVE_VERSION="false"
325349
fi
326-
curl -sSL "https://get.sdkman.io?rcupdate=false" | bash
350+
run_with_retries 5 10 "Installing SDKMAN" install_sdkman_cli
327351
# For RHEL 8 systems, also disable native CLI in config file and remove native binaries
328352
if [ "${ADJUSTED_ID}" = "rhel" ] && [ "${MAJOR_VERSION_ID}" = "8" ]; then
329353
# Disable native CLI in config to prevent future usage

test/java/install_latest_version.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ source dev-container-features-test-lib
88
echo 'public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); } }' > HelloWorld.java
99
javac HelloWorld.java
1010

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

1414
# Report result
1515
reportResults

0 commit comments

Comments
 (0)