Skip to content

Commit

Permalink
Fix running IDE in a UBI8-based user's container
Browse files Browse the repository at this point in the history
Signed-off-by: Artem Zatsarynnyi <[email protected]>
  • Loading branch information
azatsarynnyy committed Oct 8, 2024
1 parent d6489e7 commit f62b3e3
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 7 deletions.
6 changes: 6 additions & 0 deletions build/dockerfiles/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
# Contributors:
# Red Hat, Inc. - initial API and implementation

# https://registry.access.redhat.com/ubi8/nodejs-20
FROM registry.access.redhat.com/ubi8/nodejs-20:1-58.1724661482 as ubi8

# Base image tag updater line.
# See https://github.com/eclipse-che/che-release/pull/90
# https://registry.access.redhat.com/ubi9/nodejs-20
Expand Down Expand Up @@ -35,6 +38,9 @@ RUN for f in "${HOME}" "/etc/passwd" "/etc/group" "/status-app" "/idea-server";
WORKDIR /status-app/
RUN npm install

# to provide to a UBI8-based user's container
COPY --from=ubi8 /usr/bin/node /node-ubi8

# Switch to unprivileged user.
USER 10001

Expand Down
7 changes: 5 additions & 2 deletions build/scripts/entrypoint-init-container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ fi

cp -r /status-app/ "$ide_server_path"
cp /entrypoint-volume.sh "$ide_server_path"
# copy Node.js to the editor volume, in case there is no one in the user's container
cp /usr/bin/node "$ide_server_path"

# Copy Node.js to the editor volume,
# in case there is no one in the user's container.
cp /usr/bin/node "$ide_server_path"/node-ubi9
cp /node-ubi8 "$ide_server_path"/node-ubi8

echo "Volume content:"
ls -la "$ide_server_path"
74 changes: 69 additions & 5 deletions build/scripts/entrypoint-volume.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,80 @@ ide_server_path="/idea-server"
echo "Volume content:"
ls -la "$ide_server_path"


libssl_version=""
get_libssl_version() {
libssl=$(find / -type f \( -name "libssl.so*" \) 2>/dev/null)
if [ -z "$libssl" ]; then
for dir in /lib64 /usr/lib64 /lib /usr/lib /usr/local/lib64 /usr/local/lib; do
for file in "$dir"/libssl.so*; do
if [ -e "$file" ]; then
libssl="$file"
break 2
fi
done
done
fi

echo "[INFO] libssl: $libssl"

case "${libssl}" in
*libssl.so.1*)
echo "[INFO] libssl version is: 1"
libssl_version="1"
;;
*libssl.so.3*)
echo "[INFO] libssl version is: 3"
libssl_version="3"
;;
*)
libssl_version=""
echo "[WARNING] unknown libssl version: $libssl"
;;
esac
}

openssl_version=""
get_openssl_version() {
if command -v openssl >/dev/null 2>&1; then
echo "[INFO] openssl command is available, OpenSSL version is: $(openssl version -v)"
openssl_version=$(openssl version -v | cut -d' ' -f2 | cut -d'.' -f1)
elif command -v rpm >/dev/null 2>&1; then
echo "[INFO] rpm command is available"
openssl_version=$(rpm -qa | grep openssl-libs | cut -d'-' -f3 | cut -d'.' -f1)
else
echo "[INFO] openssl and rpm commands are not available, trying to detect OpenSSL version..."
get_libssl_version
openssl_version=$libssl_version
fi
}


# Start the app that checks the IDE server status.
# This will be workspace's 'main' endpoint.
cd "$ide_server_path"/status-app
if command -v npm &> /dev/null
then
# User's container with Node.js
if command -v npm &> /dev/null; then
# Node.js installed in a user's container
nohup npm start &
else
# User's container without Node.js
# Use Node.js copied from the editor-injector container (UBI9).
# no Node.js installed,
# use the one that editor-injector provides
get_openssl_version
echo "[INFO] OpenSSL major version is: $openssl_version."

case "${openssl_version}" in
*"1"*)
mv "$ide_server_path"/node-ubi8 "$ide_server_path"/node
;;
*"3"*)
mv "$ide_server_path"/node-ubi9 "$ide_server_path"/node
;;
*)
echo "[WARNING] Unsupported OpenSSL major version. Node.js from UBI9 will be used."
mv "$ide_server_path"/node-ubi9 "$ide_server_path"/node
;;
esac

nohup "$ide_server_path"/node index.js &
fi

Expand Down

0 comments on commit f62b3e3

Please sign in to comment.