Unverified Commit 3063f5f1 authored by Jeff Putsch's avatar Jeff Putsch Committed by GitHub

Add RHEL support to Java feature (#821)

* Initial rhel update

* RHEL support added.

* Add tests

* quiet down test for ant/gradle/maven/groovy when they are not yet installed.

* revert README -- it is autobuilt

* Update src/java/NOTES.md

add "`" around package manager names.
Co-authored-by: 's avatarSamruddhi Khandale <samruddhikhandale@github.com>

* address PR feedback

---------
Co-authored-by: 's avatarJeff Putsch <jputsch@analog.com>
Co-authored-by: 's avatarSamruddhi Khandale <samruddhikhandale@github.com>
parent 67de3c27
...@@ -5,6 +5,6 @@ For the Java Feature from this repository, see [NOTICE.txt](https://github.com/d ...@@ -5,6 +5,6 @@ For the Java Feature from this repository, see [NOTICE.txt](https://github.com/d
## OS Support ## OS Support
This Feature should work on recent versions of Debian/Ubuntu-based distributions with the `apt` package manager installed. Debian/Ubuntu, RedHat Enterprise Linux, Fedora, Alma, and RockyLinux distributions with the `apt`, `yum`, `dnf`, or `microdnf` package manager installed.
`bash` is required to execute the `install.sh` script. `bash` is required to execute the `install.sh` script.
{ {
"id": "java", "id": "java",
"version": "1.3.0", "version": "1.4.0",
"name": "Java (via SDKMAN!)", "name": "Java (via SDKMAN!)",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/java", "documentationURL": "https://github.com/devcontainers/features/tree/main/src/java",
"description": "Installs Java, SDKMAN! (if not installed), and needed dependencies.", "description": "Installs Java, SDKMAN! (if not installed), and needed dependencies.",
......
...@@ -30,14 +30,65 @@ ADDITIONAL_VERSIONS="${ADDITIONALVERSIONS:-""}" ...@@ -30,14 +30,65 @@ ADDITIONAL_VERSIONS="${ADDITIONALVERSIONS:-""}"
set -e set -e
# Clean up
rm -rf /var/lib/apt/lists/*
if [ "$(id -u)" -ne 0 ]; then if [ "$(id -u)" -ne 0 ]; then
echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
exit 1 exit 1
fi fi
# Bring in ID, ID_LIKE, VERSION_ID, VERSION_CODENAME
. /etc/os-release
# Get an adjusted ID independent of distro variants
MAJOR_VERSION_ID=$(echo ${VERSION_ID} | cut -d . -f 1)
if [ "${ID}" = "debian" ] || [ "${ID_LIKE}" = "debian" ]; then
ADJUSTED_ID="debian"
elif [[ "${ID}" = "rhel" || "${ID}" = "fedora" || "${ID}" = "mariner" || "${ID_LIKE}" = *"rhel"* || "${ID_LIKE}" = *"fedora"* || "${ID_LIKE}" = *"mariner"* ]]; then
ADJUSTED_ID="rhel"
if [[ "${ID}" = "rhel" ]] || [[ "${ID}" = *"alma"* ]] || [[ "${ID}" = *"rocky"* ]]; then
VERSION_CODENAME="rhel${MAJOR_VERSION_ID}"
else
VERSION_CODENAME="${ID}${MAJOR_VERSION_ID}"
fi
else
echo "Linux distro ${ID} not supported."
exit 1
fi
# Setup INSTALL_CMD & PKG_MGR_CMD
if type apt-get > /dev/null 2>&1; then
PKG_MGR_CMD=apt-get
INSTALL_CMD="${PKG_MGR_CMD} -y install --no-install-recommends"
elif type microdnf > /dev/null 2>&1; then
PKG_MGR_CMD=microdnf
INSTALL_CMD="${PKG_MGR_CMD} -y install --refresh --best --nodocs --noplugins --setopt=install_weak_deps=0"
elif type dnf > /dev/null 2>&1; then
PKG_MGR_CMD=dnf
INSTALL_CMD="${PKG_MGR_CMD} -y install"
elif type yum > /dev/null 2>&1; then
PKG_MGR_CMD=yum
INSTALL_CMD="${PKG_MGR_CMD} -y install"
else
echo "(Error) Unable to find a supported package manager."
exit 1
fi
# Clean up
clean_up() {
local pkg
case ${ADJUSTED_ID} in
debian)
rm -rf /var/lib/apt/lists/*
;;
rhel)
for pkg in epel-release epel-release-latest packages-microsoft-prod; do
${PKG_MGR_CMD} -y remove $pkg 2>/dev/null || /bin/true
done
rm -rf /var/cache/dnf/* /var/cache/yum/*
rm -f /etc/yum.repos.d/docker-ce.repo
;;
esac
}
clean_up
# Ensure that login shells get the correct path if the user updated the PATH using ENV. # Ensure that login shells get the correct path if the user updated the PATH using ENV.
rm -f /etc/profile.d/00-restore-env.sh rm -f /etc/profile.d/00-restore-env.sh
echo "export PATH=${PATH//$(sh -lc 'echo $PATH')/\$PATH}" > /etc/profile.d/00-restore-env.sh echo "export PATH=${PATH//$(sh -lc 'echo $PATH')/\$PATH}" > /etc/profile.d/00-restore-env.sh
...@@ -61,31 +112,79 @@ elif [ "${USERNAME}" = "none" ] || ! id -u ${USERNAME} > /dev/null 2>&1; then ...@@ -61,31 +112,79 @@ elif [ "${USERNAME}" = "none" ] || ! id -u ${USERNAME} > /dev/null 2>&1; then
fi fi
updaterc() { updaterc() {
local _bashrc
local _zshrc
if [ "${UPDATE_RC}" = "true" ]; then if [ "${UPDATE_RC}" = "true" ]; then
echo "Updating /etc/bash.bashrc and /etc/zsh/zshrc..." case $ADJUSTED_ID in
if [[ "$(cat /etc/bash.bashrc)" != *"$1"* ]]; then debian)
echo -e "$1" >> /etc/bash.bashrc _bashrc=/etc/bash.bashrc
_zshrc=/etc/zsh/zshrc
;;
rhel)
_bashrc=/etc/bashrc
_zshrc=/etc/zshrc
;;
esac
echo "Updating ${_bashrc} and ${_zshrc}..."
if [[ "$(cat ${_bashrc})" != *"$1"* ]]; then
echo -e "$1" >> "${_bashrc}"
fi fi
if [ -f "/etc/zsh/zshrc" ] && [[ "$(cat /etc/zsh/zshrc)" != *"$1"* ]]; then if [ -f "${_zshrc}" ] && [[ "$(cat ${_zshrc})" != *"$1"* ]]; then
echo -e "$1" >> /etc/zsh/zshrc echo -e "$1" >> "${_zshrc}"
fi fi
fi fi
} }
apt_get_update()
{ pkg_manager_update() {
case $ADJUSTED_ID in
debian)
if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
echo "Running apt-get update..." echo "Running apt-get update..."
apt-get update -y ${PKG_MGR_CMD} update -y
fi
;;
rhel)
if [ ${PKG_MGR_CMD} = "microdnf" ]; then
if [ "$(ls /var/cache/yum/* 2>/dev/null | wc -l)" = 0 ]; then
echo "Running ${PKG_MGR_CMD} makecache ..."
${PKG_MGR_CMD} makecache
fi
else
if [ "$(ls /var/cache/${PKG_MGR_CMD}/* 2>/dev/null | wc -l)" = 0 ]; then
echo "Running ${PKG_MGR_CMD} check-update ..."
set +e
stderr_messages=$(${PKG_MGR_CMD} -q check-update 2>&1)
rc=$?
# centos 7 sometimes returns a status of 100 when it apears to work.
if [ $rc != 0 ] && [ $rc != 100 ]; then
echo "(Error) ${PKG_MGR_CMD} check-update produced the following error message(s):"
echo "${stderr_messages}"
exit 1
fi fi
set -e
fi
fi
;;
esac
} }
# Checks if packages are installed and installs them if not # Checks if packages are installed and installs them if not
check_packages() { check_packages() {
case ${ADJUSTED_ID} in
debian)
if ! dpkg -s "$@" > /dev/null 2>&1; then if ! dpkg -s "$@" > /dev/null 2>&1; then
apt_get_update pkg_manager_update
apt-get -y install --no-install-recommends "$@" ${INSTALL_CMD} "$@"
fi fi
;;
rhel)
if ! rpm -q "$@" > /dev/null 2>&1; then
pkg_manager_update
${INSTALL_CMD} "$@"
fi
;;
esac
} }
# Use Microsoft JDK for everything but JDK 8 and 18 (unless specified differently with jdkDistro option) # Use Microsoft JDK for everything but JDK 8 and 18 (unless specified differently with jdkDistro option)
...@@ -142,8 +241,19 @@ if [ "${architecture}" != "amd64" ] && [ "${architecture}" != "x86_64" ] && [ "$ ...@@ -142,8 +241,19 @@ if [ "${architecture}" != "amd64" ] && [ "${architecture}" != "x86_64" ] && [ "$
exit 1 exit 1
fi fi
# Install dependencies # Install dependencies,
check_packages curl ca-certificates zip unzip sed check_packages ca-certificates zip unzip sed findutils util-linux tar
# Make sure passwd (Debian) and shadow-utils RHEL family is installed
if [ ${ADJUSTED_ID} = "debian" ]; then
check_packages passwd
elif [ ${ADJUSTED_ID} = "rhel" ]; then
check_packages shadow-utils
fi
# minimal RHEL installs may not include curl, or includes curl-minimal instead.
# Install curl if the "curl" command is not present.
if ! type curl > /dev/null 2>&1; then
check_packages curl
fi
# Install sdkman if not installed # Install sdkman if not installed
if [ ! -d "${SDKMAN_DIR}" ]; then if [ ! -d "${SDKMAN_DIR}" ]; then
...@@ -178,26 +288,26 @@ if [ ! -z "${ADDITIONAL_VERSIONS}" ]; then ...@@ -178,26 +288,26 @@ if [ ! -z "${ADDITIONAL_VERSIONS}" ]; then
fi fi
# Install Ant # Install Ant
if [[ "${INSTALL_ANT}" = "true" ]] && ! ant -version > /dev/null; then if [[ "${INSTALL_ANT}" = "true" ]] && ! ant -version > /dev/null 2>&1; then
sdk_install ant ${ANT_VERSION} sdk_install ant ${ANT_VERSION}
fi fi
# Install Gradle # Install Gradle
if [[ "${INSTALL_GRADLE}" = "true" ]] && ! gradle --version > /dev/null; then if [[ "${INSTALL_GRADLE}" = "true" ]] && ! gradle --version > /dev/null 2>&1; then
sdk_install gradle ${GRADLE_VERSION} sdk_install gradle ${GRADLE_VERSION}
fi fi
# Install Maven # Install Maven
if [[ "${INSTALL_MAVEN}" = "true" ]] && ! mvn --version > /dev/null; then if [[ "${INSTALL_MAVEN}" = "true" ]] && ! mvn --version > /dev/null 2>&1; then
sdk_install maven ${MAVEN_VERSION} sdk_install maven ${MAVEN_VERSION}
fi fi
# Install Groovy # Install Groovy
if [[ "${INSTALL_GROOVY}" = "true" ]] && ! groovy --version > /dev/null; then if [[ "${INSTALL_GROOVY}" = "true" ]] && ! groovy --version > /dev/null 2>&1; then
sdk_install groovy "${GROOVY_VERSION}" sdk_install groovy "${GROOVY_VERSION}"
fi fi
# Clean up # Clean up
rm -rf /var/lib/apt/lists/* clean_up
echo "Done!" echo "Done!"
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
check "version" java --version
# Check env
check "JAVA_HOME is set correctly" echo $JAVA_HOME | grep "/usr/local/sdkman/candidates/java/current"
# Report result
reportResults
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
check "version" java --version
# Check env
check "JAVA_HOME is set correctly" echo $JAVA_HOME | grep "/usr/local/sdkman/candidates/java/current"
# Report result
reportResults
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
check "version" java --version
# Check env
check "JAVA_HOME is set correctly" echo $JAVA_HOME | grep "/usr/local/sdkman/candidates/java/current"
# Report result
reportResults
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
check "version" java --version
# Check env
check "JAVA_HOME is set correctly" echo $JAVA_HOME | grep "/usr/local/sdkman/candidates/java/current"
# Report result
reportResults
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
check "version" java --version
# Check env
check "JAVA_HOME is set correctly" echo $JAVA_HOME | grep "/usr/local/sdkman/candidates/java/current"
# Report result
reportResults
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
check "version" java --version
# Check env
check "JAVA_HOME is set correctly" echo $JAVA_HOME | grep "/usr/local/sdkman/candidates/java/current"
# Report result
reportResults
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
check "java version 11 installed as default" grep "11\." <(java --version)
check "java version 17 installed" grep "^17\." <(ls /usr/local/sdkman/candidates/java)
check "java version 8 installed" grep "^8\." <(ls /usr/local/sdkman/candidates/java)
# Report result
reportResults
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
check "user is vscode" grep vscode <(whoami)
check "java" java --version
check "ant" ant -version
cat << EOF > /tmp/build.xml
<project><target name="init"><mkdir dir="ant-src"/></target></project>
EOF
cd /tmp && ant init
check "ant-src exists" grep "ant-src" <(ls -la /tmp)
check "gradle" gradle --version
cd /tmp && gradle init --type basic --dsl groovy --incubating --project-name test
check "GRADLE_USER_HOME exists" grep ".gradle" <(ls -la /home/vscode)
check "maven" mvn --version
cd /tmp && mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false
check "m2 exists" grep ".m2" <(ls -la /home/vscode)
check "groovy" groovy --version
cat << EOF > /tmp/test.groovy
println("verify")
EOF
check "groovy works" test "$(groovy /tmp/test.groovy)" = "verify"
# Report result
reportResults
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
check "user is root" grep root <(whoami)
check "java" java --version
check "ant" ant -version
cat << EOF > /tmp/build.xml
<project><target name="init"><mkdir dir="ant-src"/></target></project>
EOF
cd /tmp && ant init
check "ant-src exists" grep "ant-src" <(ls -la /tmp)
check "gradle" gradle --version
cd /tmp && gradle init --type basic --dsl groovy --incubating --project-name test
check "GRADLE_USER_HOME exists" grep ".gradle" <(ls -la /root)
check "maven" mvn --version
cd /tmp && mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false
check "m2 exists" grep ".m2" <(ls -la /root)
check "groovy" groovy --version
cat << EOF > /tmp/test.groovy
println("verify")
EOF
check "groovy works" test "$(groovy /tmp/test.groovy)" = "verify"
# Report result
reportResults
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
check "user is root" grep root <(whoami)
check "java" java --version
check "ant version" grep "Ant(TM) version 1.10.12" <(ant -version)
cat << EOF > /tmp/build.xml
<project><target name="init"><mkdir dir="ant-src"/></target></project>
EOF
cd /tmp && ant init
check "ant-src exists" grep "ant-src" <(ls -la /tmp)
check "gradle version" grep "Gradle 6.8.3" <(gradle --version)
cd /tmp && gradle init --type basic --dsl groovy --project-name test
check "GRADLE_USER_HOME exists" grep ".gradle" <(ls -la /root)
check "maven version" grep "Apache Maven 3.6.3" <(mvn --version)
cd /tmp && mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false
check "m2 exists" grep ".m2" <(ls -la /root)
check "groovy version" grep "Groovy Version: 2.5.22" <(groovy --version)
# Report result
reportResults
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
check "java version openjdk 21 installed" grep "openjdk 21." <(java --version)
# Report result
reportResults
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
check "java version openjdk 21 installed" grep "openjdk 21." <(java --version)
# Report result
reportResults
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
check "version" java --version
# Check env
check "JAVA_HOME is set correctly" echo $JAVA_HOME | grep "/usr/local/sdkman/candidates/java/current"
# Report result
reportResults
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
check "version" java --version
# Check env
check "JAVA_HOME is set correctly" echo $JAVA_HOME | grep "/usr/local/sdkman/candidates/java/current"
# Report result
reportResults
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
check "version" java --version
# Check env
check "JAVA_HOME is set correctly" echo $JAVA_HOME | grep "/usr/local/sdkman/candidates/java/current"
# Report result
reportResults
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
check "version" java --version
# Check env
check "JAVA_HOME is set correctly" echo $JAVA_HOME | grep "/usr/local/sdkman/candidates/java/current"
# Report result
reportResults
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
check "version" java --version
# Check env
check "JAVA_HOME is set correctly" echo $JAVA_HOME | grep "/usr/local/sdkman/candidates/java/current"
# Report result
reportResults
...@@ -69,5 +69,142 @@ ...@@ -69,5 +69,142 @@
"jdkDistro": "graalce" "jdkDistro": "graalce"
} }
} }
},
"install_from_non_default_distro_rhel_family": {
"image": "almalinux:8",
"features": {
"java": {
"version": "21",
"jdkDistro": "open"
}
}
},
"install_additional_java_rhel_family": {
"image": "almalinux:8",
"features": {
"java": {
"version": "11",
"additionalVersions": "17,8"
}
}
},
"install_ant_and_gradle_and_maven_and_groovy_for_user_rhel_family": {
"image": "almalinux:8",
"remoteUser": "vscode",
"features": {
"common-utils": {
"username": "vscode"
},
"java": {
"version": "latest",
"installAnt": true,
"installGradle": true,
"installMaven": true,
"installGroovy": true
}
}
},
"install_ant_and_gradle_and_maven_and_groovy_rhel_family": {
"image": "almalinux:8",
"features": {
"java": {
"version": "latest",
"installAnt": true,
"installGradle": true,
"installMaven": true,
"installGroovy": true
}
}
},
"install_ant_and_gradle_and_maven_and_groovy_with_specific_version_rhel_family": {
"image": "almalinux:8",
"features": {
"java": {
"version": "latest",
"installAnt": "true",
"antVersion": "1.10.12",
"installGradle": "true",
"gradleVersion": "6.8.3",
"installMaven": "true",
"mavenVersion": "3.6.3",
"installGroovy": "true",
"groovyVersion": "2.5.22"
}
}
},
"install_non_conventional_version_rhel_family": {
"image": "almalinux:8",
"features": {
"java": {
"version": "21",
"jdkDistro": "graalce"
}
}
},
"centos-7": {
"image": "centos:centos7",
"features": {
"java": {}
}
},
"alma-8": {
"image": "almalinux:8",
"features": {
"java": {}
}
},
"alma-8-minimal": {
"image": "almalinux:8-minimal",
"features": {
"java": {}
}
},
"alma-9": {
"image": "almalinux:9",
"features": {
"java": {}
}
},
"alma-9-minimal": {
"image": "almalinux:9-minimal",
"features": {
"java": {}
}
},
"rocky-8": {
"image": "rockylinux:8",
"features": {
"java": {}
}
},
"rocky-8-minimal": {
"image": "rockylinux:8-minimal",
"features": {
"java": {}
}
},
"rocky-9": {
"image": "rockylinux:9",
"features": {
"java": {}
}
},
"rocky-9-minimal": {
"image": "rockylinux:9-minimal",
"features": {
"java": {}
}
},
"mariner": {
"image": "mcr.microsoft.com/cbl-mariner/base/core:2.0",
"features": {
"java": {}
}
},
"fedora": {
"image": "fedora",
"features": {
"java": {}
}
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment