Skip to content

Commit f2b4cd4

Browse files
committed
RHOAIENG-35917: create Dockerfile.konflux.* files for RStudio (#1699)
(cherry picked from commit 5cdd104)
1 parent 2fdc9e2 commit f2b4cd4

File tree

2 files changed

+594
-0
lines changed

2 files changed

+594
-0
lines changed
Lines changed: 290 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,290 @@
1+
ARG TARGETARCH
2+
3+
#########################
4+
# configuration args #
5+
#########################
6+
ARG BASE_IMAGE
7+
8+
# External image alias for UBI repository configuration
9+
FROM registry.access.redhat.com/ubi9/ubi AS ubi-repos
10+
11+
####################
12+
# cpu-base #
13+
####################
14+
FROM ${BASE_IMAGE} AS cpu-base
15+
16+
WORKDIR /opt/app-root/bin
17+
18+
# OS Packages needs to be installed as root
19+
USER root
20+
21+
# Inject the official UBI 9 repository configuration into the AIPCC base image.
22+
# The Quay-based AIPCC image is "repo-less" by default (https://gitlab.com/redhat/rhel-ai/core/base-images/app#repositories), so dnf cannot upgrade or install packages.
23+
# By copying ubi.repo from the public UBI 9 image, we enable package management for upgrades and installations.
24+
COPY --from=ubi-repos /etc/yum.repos.d/ubi.repo /etc/yum.repos.d/ubi.repo
25+
COPY --from=ubi-repos /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
26+
27+
RUN /bin/bash <<'EOF'
28+
set -Eeuxo pipefail
29+
if command -v subscription-manager &> /dev/null; then
30+
subscription-manager identity &>/dev/null && subscription-manager refresh || echo "Not registered, skipping refresh."
31+
fi
32+
EOF
33+
34+
# upgrade first to avoid fixable vulnerabilities begin
35+
# Problem: The operation would result in removing the following protected packages: systemd
36+
# (try to add '--allowerasing' to command line to replace conflicting packages or '--skip-broken' to skip uninstallable packages)
37+
# Solution: --best --skip-broken does not work either, so use --nobest
38+
RUN /bin/bash <<'EOF'
39+
set -Eeuxo pipefail
40+
dnf -y upgrade --refresh --nobest --skip-broken --nodocs --noplugins --setopt=install_weak_deps=0 --setopt=keepcache=0
41+
dnf clean all -y
42+
EOF
43+
44+
# upgrade first to avoid fixable vulnerabilities end
45+
46+
# Install useful OS packages
47+
# remove skopeo, CVE-2025-4674
48+
RUN dnf install -y perl mesa-libGL && dnf clean all && rm -rf /var/cache/yum
49+
50+
# Other apps and tools installed as default user
51+
USER 1001
52+
53+
# Install micropipenv and uv to deploy packages from requirements.txt begin
54+
RUN pip install --no-cache-dir --extra-index-url https://pypi.org/simple -U "micropipenv[toml]==1.9.0" "uv==0.8.12"
55+
# Install micropipenv and uv to deploy packages from requirements.txt end
56+
57+
WORKDIR /opt/app-root/src
58+
59+
#####################
60+
# cpu-rstudio #
61+
#####################
62+
FROM cpu-base AS cpu-rstudio
63+
64+
ARG RSTUDIO_SOURCE_CODE=rstudio/rhel9-python-3.12
65+
ARG TARGETARCH
66+
67+
WORKDIR /opt/app-root/bin
68+
69+
# TODO THIS SHOULD BE REMOVED
70+
# Access the client's secret for the subscription manager from the environment variable
71+
ARG SECRET_DIR=/opt/app-root/src/.sec
72+
ARG SERVERURL_DEFAULT=""
73+
ARG BASEURL_DEFAULT=""
74+
# TILL HERE
75+
76+
LABEL name="rhoai/odh-workbench-rstudio-minimal-cpu-py312-rhel9" \
77+
com.redhat.component="odh-workbench-rstudio-minimal-cpu-py312-rhel9" \
78+
summary="RStudio Server CPU image with python 3.12 based on Red Hat Enterprise Linux 9" \
79+
description="RStudio Server CPU image with python 3.12 based on Red Hat Enterprise Linux 9" \
80+
maintainer="Red Hat AI Notebooks Team" \
81+
io.k8s.display-name="RStudio Server CPU image with python 3.12 based on Red Hat Enterprise Linux 9" \
82+
io.k8s.description="RStudio Server CPU image with python 3.12 based on Red Hat Enterprise Linux 9" \
83+
authoritative-source-url="https://github.com/opendatahub-io/notebooks" \
84+
io.openshift.build.commit.ref="main" \
85+
io.openshift.build.source-location="https://github.com/opendatahub-io/notebooks/tree/main/rstudio/rhel9-python-3.12" \
86+
io.openshift.build.image="quay.io/opendatahub/workbench-images:rstudio-rhel9-python-3.12"
87+
88+
USER 0
89+
90+
# TODO THIS SHOULD BE REMOVED in favor of: https://issues.redhat.com/browse/RHOAIENG-32541
91+
# uncomment the below line if you fall on this error: subscription-manager is disabled when running inside a container. Please refer to your host system for subscription management.
92+
#RUN sed -i 's/\(def in_container():\)/\1\n return False/g' /usr/lib64/python*/*-packages/rhsm/config.py
93+
94+
# If necessary, run the subscription manager command using the provided credentials. Only include --serverurl and --baseurl if they are provided
95+
RUN /bin/bash <<'EOF'
96+
set -Eeuxo pipefail
97+
if [ -d "${SECRET_DIR}" ]; then
98+
SERVERURL=$(cat ${SECRET_DIR}/SERVERURL 2>/dev/null || echo ${SERVERURL_DEFAULT})
99+
BASEURL=$(cat ${SECRET_DIR}/BASEURL 2>/dev/null || echo ${BASEURL_DEFAULT})
100+
USERNAME=$(cat ${SECRET_DIR}/USERNAME)
101+
PASSWORD=$(cat ${SECRET_DIR}/PASSWORD)
102+
subscription-manager register \
103+
${SERVERURL:+--serverurl=$SERVERURL} \
104+
${BASEURL:+--baseurl=$BASEURL} \
105+
--username=$USERNAME \
106+
--password=$PASSWORD \
107+
--force \
108+
--auto-attach
109+
fi
110+
EOF
111+
112+
# TILL HERE
113+
114+
ENV R_VERSION=4.5.1
115+
116+
# Install R
117+
RUN /bin/bash <<'EOF'
118+
set -Eeuxo pipefail
119+
dnf install -y dnf-plugins-core
120+
if command -v subscription-manager &> /dev/null; then
121+
subscription-manager repos --enable codeready-builder-for-rhel-9-x86_64-rpms
122+
else
123+
dnf config-manager --set-enabled crb
124+
fi
125+
dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm
126+
INSTALL_PKGS="R-core R-core-devel R-java R-Rcpp R-highlight \
127+
R-littler R-littler-examples openssl-libs compat-openssl11"
128+
dnf install -y --setopt=tsflags=nodocs $INSTALL_PKGS
129+
echo 'options(repos = c(CRAN = "https://cran.rstudio.com/"), download.file.method = "libcurl")' >> /usr/lib64/R/etc/Rprofile.site
130+
(umask 002;touch /usr/lib64/R/etc/Renviron.site)
131+
dnf -y clean all --enablerepo='*'
132+
EOF
133+
134+
# set R library to default (used in install.r from littler)
135+
ENV LIBLOC=/usr/lib64/R/library
136+
ENV R_LIBS_USER=/opt/app-root/bin/Rpackages/4.5
137+
138+
RUN /bin/bash <<'EOF'
139+
set -Eeuxo pipefail
140+
chmod -R a+w ${LIBLOC}
141+
# create User R Library path
142+
mkdir -p ${R_LIBS_USER}
143+
chmod -R a+w ${R_LIBS_USER}
144+
EOF
145+
146+
WORKDIR /tmp/
147+
COPY /rstudio/utils /tmp/utils
148+
149+
# Install RStudio
150+
ARG RSTUDIO_RPM=rstudio-server-rhel-2025.09.0-387-x86_64.rpm
151+
RUN /bin/bash <<'EOF'
152+
set -Eeuxo pipefail
153+
wget --progress=dot:giga https://download2.rstudio.org/server/rhel9/x86_64/${RSTUDIO_RPM}
154+
dnf install -y ${RSTUDIO_RPM}
155+
rm ${RSTUDIO_RPM}
156+
dnf -y clean all --enablerepo='*'
157+
# Specific RStudio config and fixes
158+
chmod 1777 /var/run/rstudio-server
159+
mkdir -p /usr/share/doc/R
160+
# package installation
161+
# install necessary texlive-framed package to make Knit R markup to PDF rendering possible
162+
dnf install -y libgit2-devel.x86_64 libcurl-devel harfbuzz-devel.x86_64 fribidi-devel.x86_64 cmake "flexiblas-*" texlive-framed
163+
# install npm to run cve_remediation script
164+
dnf install -y npm
165+
dnf clean all
166+
rm -rf /var/cache/yum
167+
(cd /tmp/utils && ./cve_remediation.sh)
168+
EOF
169+
170+
COPY ${RSTUDIO_SOURCE_CODE}/rsession.conf /etc/rstudio/rsession.conf
171+
172+
# # Install R packages
173+
# # https://cran.r-project.org/web/packages
174+
# COPY ${RSTUDIO_SOURCE_CODE}/install_packages.R ./
175+
# RUN /bin/bash <<'EOF'
176+
# set -Eeuxo pipefail
177+
# R -f ./install_packages.R
178+
# rm ./install_packages.R
179+
# EOF
180+
181+
ENV APP_ROOT=/opt/app-root
182+
183+
# Install NGINX to proxy RStudio and pass probes check
184+
ENV NGINX_VERSION=1.24 \
185+
NGINX_SHORT_VER=124 \
186+
NGINX_CONFIGURATION_PATH=${APP_ROOT}/etc/nginx.d \
187+
NGINX_CONF_PATH=/etc/nginx/nginx.conf \
188+
NGINX_DEFAULT_CONF_PATH=${APP_ROOT}/etc/nginx.default.d \
189+
NGINX_CONTAINER_SCRIPTS_PATH=/usr/share/container-scripts/nginx \
190+
NGINX_APP_ROOT=${APP_ROOT} \
191+
NGINX_LOG_PATH=/var/log/nginx \
192+
NGINX_PERL_MODULE_PATH=${APP_ROOT}/etc/perl
193+
194+
# Modules does not exist
195+
RUN /bin/bash <<'EOF'
196+
set -Eeuxo pipefail
197+
dnf -y module enable nginx:$NGINX_VERSION
198+
INSTALL_PKGS="nss_wrapper bind-utils gettext hostname nginx nginx-mod-stream nginx-mod-http-perl httpd"
199+
dnf install -y --setopt=tsflags=nodocs $INSTALL_PKGS
200+
rpm -V $INSTALL_PKGS
201+
nginx -v 2>&1 | grep -qe "nginx/$NGINX_VERSION\." && echo "Found VERSION $NGINX_VERSION"
202+
dnf -y clean all --enablerepo='*'
203+
EOF
204+
205+
# Configure httpd for CGI processing
206+
COPY --chown=1001:0 ${RSTUDIO_SOURCE_CODE}/httpd/httpd.conf /etc/httpd/conf/httpd.conf
207+
COPY --chown=1001:0 ${RSTUDIO_SOURCE_CODE}/httpd/rstudio-cgi.conf /etc/httpd/conf.d/rstudio-cgi.conf
208+
209+
# Copy extra files to the image.
210+
COPY --chown=1001:0 ${RSTUDIO_SOURCE_CODE}/nginx/root/ /
211+
212+
# Configure nginx
213+
COPY ${RSTUDIO_SOURCE_CODE}/nginx/serverconf/ /opt/app-root/etc/nginx.default.d/
214+
COPY ${RSTUDIO_SOURCE_CODE}/nginx/httpconf/ /opt/app-root/etc/nginx.d/
215+
COPY ${RSTUDIO_SOURCE_CODE}/nginx/api/ /opt/app-root/api/
216+
217+
# Changing ownership and user rights to support following use-cases:
218+
# 1) running container on OpenShift, whose default security model
219+
# is to run the container under random UID, but GID=0
220+
# 2) for working root-less container with UID=1001, which does not have
221+
# to have GID=0
222+
# 3) for default use-case, that is running container directly on operating system,
223+
# with default UID and GID (1001:0)
224+
# Supported combinations of UID:GID are thus following:
225+
# UID=1001 && GID=0
226+
# UID=<any>&& GID=0
227+
# UID=1001 && GID=<any>
228+
RUN /bin/bash <<'EOF'
229+
set -Eeuxo pipefail
230+
sed -i -f ${NGINX_APP_ROOT}/nginxconf.sed ${NGINX_CONF_PATH}
231+
mkdir -p ${NGINX_APP_ROOT}/etc/nginx.d/
232+
mkdir -p ${NGINX_APP_ROOT}/etc/nginx.default.d/
233+
mkdir -p ${NGINX_APP_ROOT}/api/
234+
mkdir -p ${NGINX_CONTAINER_SCRIPTS_PATH}/nginx-start
235+
mkdir -p ${NGINX_LOG_PATH}
236+
mkdir -p ${NGINX_PERL_MODULE_PATH}
237+
# Create httpd directories and set permissions
238+
mkdir -p /var/log/httpd /var/run/httpd /etc/httpd/logs
239+
chown -R 1001:0 ${NGINX_CONF_PATH}
240+
chown -R 1001:0 ${NGINX_APP_ROOT}/etc
241+
chown -R 1001:0 ${NGINX_CONTAINER_SCRIPTS_PATH}/nginx-start
242+
chown -R 1001:0 /var/lib/nginx /var/log/nginx /run
243+
chown -R 1001:0 /var/log/httpd /var/run/httpd /etc/httpd/logs
244+
chmod ug+rw ${NGINX_CONF_PATH}
245+
chmod -R ug+rwX ${NGINX_APP_ROOT}/etc
246+
chmod -R ug+rwX ${NGINX_CONTAINER_SCRIPTS_PATH}/nginx-start
247+
chmod -R ug+rwX /var/lib/nginx /var/log/nginx /run
248+
chmod -R ug+rwX /var/log/httpd /var/run/httpd /etc/httpd/logs
249+
# Make CGI scripts executable and set proper ownership
250+
chmod +x /opt/app-root/api/kernels/access.cgi
251+
chmod +x /opt/app-root/api/probe.cgi
252+
chown -R 1001:0 /opt/app-root/api
253+
rpm-file-permissions
254+
EOF
255+
256+
# Launcher
257+
WORKDIR /opt/app-root/bin
258+
259+
COPY ${RSTUDIO_SOURCE_CODE}/utils utils/
260+
COPY ${RSTUDIO_SOURCE_CODE}/run-rstudio.sh ${RSTUDIO_SOURCE_CODE}/setup_rstudio.py ${RSTUDIO_SOURCE_CODE}/rsession.sh ${RSTUDIO_SOURCE_CODE}/run-nginx.sh ./
261+
262+
# TODO THIS SHOULD BE REMOVED in favor of: https://issues.redhat.com/browse/RHOAIENG-32541
263+
# Unregister the system
264+
RUN /bin/bash <<'EOF'
265+
set -Eeuxo pipefail
266+
if [ -d "${SECRET_DIR}" ]; then
267+
subscription-manager remove --all && subscription-manager unregister && subscription-manager clean
268+
fi
269+
EOF
270+
271+
# TILL HERE
272+
273+
USER 1001
274+
275+
COPY ${RSTUDIO_SOURCE_CODE}/pylock.toml ./
276+
277+
RUN /bin/bash <<'EOF'
278+
set -Eeuxo pipefail
279+
echo "Installing softwares and packages"
280+
# This may have to download and compile some dependencies, and as we don't lock requirements from `build-system.requires`,
281+
# we often don't know the correct hashes and `--require-hashes` would therefore fail on non amd64, where building is common.
282+
uv pip install --strict --no-deps --no-cache --no-config --no-progress --verify-hashes --compile-bytecode --index-strategy=unsafe-best-match --requirements=./pylock.toml
283+
# Fix permissions to support pip in Openshift environments
284+
chmod -R g+w /opt/app-root/lib/python3.12/site-packages
285+
fix-permissions /opt/app-root -P
286+
EOF
287+
288+
WORKDIR /opt/app-root/src
289+
290+
CMD ["/opt/app-root/bin/run-rstudio.sh"]

0 commit comments

Comments
 (0)