Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add jetbrains-ide container #560

Open
wants to merge 3 commits into
base: devspaces-3-rhel-8
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ openvsx-server.tar.gz
postgresql13.tar.gz
devspaces-idea/**/bin/
.vscode/
.DS_Store
72 changes: 72 additions & 0 deletions devspaces-jetbrains-ide/build/dockerfiles/brew.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Copyright (c) 2024 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# Red Hat, Inc. - initial API and implementation

# The Dockerfile works only in Brew, as it is customized for Cachito fetching
# project sources and npm dependencies, and performing an offline build with them

# The image to get the Node.js binary to support running an IDE in a UBI8-based user container.
# https://registry.access.redhat.com/ubi8/nodejs-20
FROM ubi8/nodejs-20:1-58.1724661482 as ubi8

# https://registry.access.redhat.com/rhel9-2-els/rhel
FROM registry.redhat.io/rhel9-2-els/rhel:9.2-1362

USER 0

WORKDIR $REMOTE_SOURCES_DIR/devspaces-images-jetbrains-ide/app/devspaces-jetbrains-ide/

# cachito:yarn step 1: copy cachito sources where we can use them; source env vars; set working dir
COPY $REMOTE_SOURCES $REMOTE_SOURCES_DIR

# hadolint ignore=SC2086
RUN source $REMOTE_SOURCES_DIR/devspaces-images-jetbrains-ide/cachito.env

RUN dnf module install -y nodejs:18/development

RUN cp -r build/scripts/*.sh /
RUN cp -r status-app /status-app/

# Create a folders structure for mounting a shared volume and copy the editor binaries to.
RUN mkdir -p /idea-server/status-app

# Adjust permissions on some items so they're writable by group root.
# hadolint ignore=SC2086
RUN for f in "${HOME}" "/etc/passwd" "/etc/group" "/status-app" "/idea-server"; do\
chgrp -R 0 ${f} && \
chmod -R g+rwX ${f}; \
done

# Build the status app.
RUN cd $REMOTE_SOURCES_DIR/devspaces-images-jetbrains-ide/app/devspaces-jetbrains-ide/status-app/ && npm install

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

# Switch to unprivileged user.
USER 1001

ENTRYPOINT /entrypoint.sh

ENV SUMMARY="Red Hat OpenShift Dev Spaces with JetBrains IDE container" \
DESCRIPTION="Red Hat OpenShift Dev Spaces with JetBrains IDE container" \
PRODNAME="devspaces" \
COMPNAME="jetbrains-ide-rhel9"
LABEL summary="$SUMMARY" \
description="$DESCRIPTION" \
io.k8s.description="$DESCRIPTION" \
io.k8s.display-name="$DESCRIPTION" \
io.openshift.tags="$PRODNAME,$COMPNAME" \
com.redhat.component="$PRODNAME-$COMPNAME-container" \
name="$PRODNAME/$COMPNAME" \
version="3.17" \
license="EPLv2" \
maintainer="Artem Zatsarynnyi <[email protected]>, Samantha Dawley <[email protected]>" \
io.openshift.expose-services="" \
usage=""
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/sh
#
# Copyright (c) 2023-2024 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# Red Hat, Inc. - initial API and implementation
#

# Being called as a pre-start command, the script downloads the requested IDE and
# copies the binaries to the shared volume which should be mounted to a folder in a dev container.

ide_flavour="$1"
# mounted volume path
ide_server_path="/idea-server"

# IDEA, if none is specified
if [ -z "$ide_flavour" ]; then
ide_flavour="idea"
fi

# Download the IDE binaries and install them to the shared volume.
cd "$ide_server_path"
echo "Downloading IDE binaries..."
if [[ "$ide_flavour" == "idea" ]]; then
curl -sL https://download-cdn.jetbrains.com/idea/ideaIU-2024.2.tar.gz | tar xzf - --strip-components=1
elif [[ "$ide_flavour" == "webstorm" ]]; then
curl -sL https://download-cdn.jetbrains.com/webstorm/WebStorm-2024.2.tar.gz | tar xzf - --strip-components=1
elif [[ "$ide_flavour" == "pycharm" ]]; then
curl -sL https://download-cdn.jetbrains.com/python/pycharm-professional-2024.2.tar.gz | tar xzf - --strip-components=1
elif [[ "$ide_flavour" == "goland" ]]; then
curl -sL https://download-cdn.jetbrains.com/go/goland-2024.2.tar.gz | tar xzf - --strip-components=1
elif [[ "$ide_flavour" == "clion" ]]; then
curl -sL https://download-cdn.jetbrains.com/cpp/CLion-2024.2.tar.gz | tar xzf - --strip-components=1
elif [[ "$ide_flavour" == "phpstorm" ]]; then
curl -sL https://download-cdn.jetbrains.com/webide/PhpStorm-2024.2.tar.gz | tar xzf - --strip-components=1
elif [[ "$ide_flavour" == "rubymine" ]]; then
curl -sL https://download-cdn.jetbrains.com/ruby/RubyMine-2024.2.tar.gz | tar xzf - --strip-components=1
elif [[ "$ide_flavour" == "rider" ]]; then
curl -sL https://download-cdn.jetbrains.com/rider/JetBrains.Rider-2024.2.tar.gz | tar xzf - --strip-components=1
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"/node-ubi9
cp /node-ubi8 "$ide_server_path"/node-ubi8

echo "Volume content:"
ls -la "$ide_server_path"
110 changes: 110 additions & 0 deletions devspaces-jetbrains-ide/build/scripts/entrypoint-volume.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/bin/sh
#
# Copyright (c) 2023-2024 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# Red Hat, Inc. - initial API and implementation
#

# Being called as a post-start command, the script runs the IDE
# from the shared volume which should be mounted to a folder in a dev container.

# Register the current (arbitrary) user.
if ! whoami &> /dev/null; then
if [ -w /etc/passwd ]; then
echo "Registering the current (arbitrary) user."
echo "${USER_NAME:-user}:x:$(id -u):0:${USER_NAME:-user} user:${HOME}:/bin/bash" >> /etc/passwd
echo "${USER_NAME:-user}:x:$(id -u):" >> /etc/group
fi
fi

# mounted volume path
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
# Node.js installed in a user's container
nohup npm start &
else
# 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

cd "$ide_server_path"/bin
./remote-dev-server.sh run ${PROJECT_SOURCE}
27 changes: 27 additions & 0 deletions devspaces-jetbrains-ide/build/scripts/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/sh
#
# Copyright (c) 2023 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# Red Hat, Inc. - initial API and implementation
#

# Register the current (arbitrary) user.
if ! whoami &> /dev/null; then
if [ -w /etc/passwd ]; then
echo "Registering the current (arbitrary) user."
echo "${USER_NAME:-user}:x:$(id -u):0:${USER_NAME:-user} user:${HOME}:/bin/bash" >> /etc/passwd
echo "${USER_NAME:-user}:x:$(id -u):" >> /etc/group
fi
fi

# Skip all interactive shell prompts.
export REMOTE_DEV_NON_INTERACTIVE=1

cd /idea-dist/bin
./remote-dev-server.sh run ~
82 changes: 82 additions & 0 deletions devspaces-jetbrains-ide/build/scripts/sync.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/bin/bash
#
# Copyright (c) 2024 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# Red Hat, Inc. - initial API and implementation

set -e

# defaults
CSV_VERSION=3.y.0 # csv 3.y.0
DS_VERSION=${CSV_VERSION%.*} # tag 3.y

UPSTM_NAME="jetbrains-ide-dev-server"
MIDSTM_NAME="jetbrains-ide"

usage () {
echo "
Usage: $0 -v [DS CSV_VERSION] [-s /path/to/${UPSTM_NAME}] [-t /path/to/generated]
Example: $0 -v 3.y.0 -s ${HOME}/projects/${UPSTM_NAME} -t /tmp/devspaces-${MIDSTM_NAME}"
exit
}

if [[ $# -lt 6 ]]; then usage; fi

while [[ "$#" -gt 0 ]]; do
case $1 in
'-v') CSV_VERSION="$2"; DS_VERSION="${CSV_VERSION%.*}"; shift 1;;
# paths to use for input and output
'-s') SOURCEDIR="$2"; SOURCEDIR="${SOURCEDIR%/}"; shift 1;;
'-t') TARGETDIR="$2"; TARGETDIR="${TARGETDIR%/}"; shift 1;;
'--help'|'-h') usage;;
esac
shift 1
done

if [[ ! -d "${SOURCEDIR}" ]]; then usage; fi
if [[ ! -d "${TARGETDIR}" ]]; then usage; fi
if [[ "${CSV_VERSION}" == "3.y.0" ]]; then usage; fi

# ignore changes in these files
echo ".github/
.git/
.gitattributes
README.md
/build/dockerfiles
/build/scripts/sync.sh
/cvp.yml
/container.yaml
/content_sets.*
/cvp.yml
/cvp-owners.yml
/sources
sources.spec
/get-source*.sh
/tests/basic-test.yaml
" > /tmp/rsync-excludes
echo "Rsync ${SOURCEDIR} to ${TARGETDIR}"
rsync -azrlt --checksum --exclude-from /tmp/rsync-excludes --delete "${SOURCEDIR}"/ "${TARGETDIR}"/
rm -f /tmp/rsync-excludes

# ensure shell scripts are executable
find "${TARGETDIR}"/ -name "*.sh" -exec chmod +x {} \;

sed_in_place() {
SHORT_UNAME=$(uname -s)
if [ "$(uname)" == "Darwin" ]; then
sed -i '' "$@"
elif [ "${SHORT_UNAME:0:5}" == "Linux" ]; then
sed -i "$@"
fi
}

sed_in_place -r \
`# Update DevSpaces version for Dockerfile` \
-e "s/version=.*/version=\"$DS_VERSION\" \\\/" \
"${TARGETDIR}"/build/dockerfiles/brew.Dockerfile
26 changes: 26 additions & 0 deletions devspaces-jetbrains-ide/container.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
platforms:
# all these keys are optional - see https://osbs.readthedocs.io/en/latest/users.html#image-configuration for more info

only:
- x86_64
# - s390x
# - ppc64le

compose:
inherit: false
pulp_repos: true
signing_intent: release

# instead of docker_api, use imagebuilder for multistage builds
image_build_method: imagebuilder

remote_sources:
- name: devspaces-images-jetbrains-ide
remote_source:
repo: https://github.com/redhat-developer/devspaces-images.git
ref: 5797bdde686f36207837c367b5f8861e739fd51d
pkg_managers: [npm]
packages:
npm:
- path: devspaces-jetbrains-ide/status-app/
Loading