|
| 1 | +#################### |
| 2 | +# base # |
| 3 | +#################### |
| 4 | +FROM registry.access.redhat.com/ubi9/python-312:latest AS base |
| 5 | + |
| 6 | +WORKDIR /opt/app-root/bin |
| 7 | + |
| 8 | +# OS Packages needs to be installed as root |
| 9 | +USER 0 |
| 10 | + |
| 11 | +# Install useful OS packages |
| 12 | +RUN dnf install -y mesa-libGL skopeo && dnf clean all && rm -rf /var/cache/yum |
| 13 | + |
| 14 | +# Other apps and tools installed as default user |
| 15 | +USER 1001 |
| 16 | + |
| 17 | +# Install micropipenv to deploy packages from Pipfile.lock |
| 18 | +RUN pip install --no-cache-dir -U "micropipenv[toml]" |
| 19 | + |
| 20 | +# Install the oc client |
| 21 | +RUN curl -L https://mirror.openshift.com/pub/openshift-v4/$(uname -m)/clients/ocp/stable/openshift-client-linux.tar.gz \ |
| 22 | + -o /tmp/openshift-client-linux.tar.gz && \ |
| 23 | + tar -xzvf /tmp/openshift-client-linux.tar.gz oc && \ |
| 24 | + rm -f /tmp/openshift-client-linux.tar.gz |
| 25 | + |
| 26 | + |
| 27 | +#################### |
| 28 | +# codeserver # |
| 29 | +#################### |
| 30 | +FROM base AS codeserver |
| 31 | + |
| 32 | +ARG CODESERVER_SOURCE_CODE=codeserver/ubi9-python-3.12 |
| 33 | +ARG CODESERVER_VERSION=v4.98.0 |
| 34 | + |
| 35 | +LABEL name="odh-notebook-code-server-ubi9-python-3.12" \ |
| 36 | + summary="code-server image with python 3.12 based on UBI 9" \ |
| 37 | + description="code-server image with python 3.12 based on UBI9" \ |
| 38 | + io.k8s.display-name="code-server image with python 3.12 based on UBI9" \ |
| 39 | + io.k8s.description="code-server image with python 3.12 based on UBI9" \ |
| 40 | + authoritative-source-url="https://github.com/opendatahub-io/notebooks" \ |
| 41 | + io.openshift.build.commit.ref="main" \ |
| 42 | + io.openshift.build.source-location="https://github.com/opendatahub-io/notebooks/tree/main/codeserver/ubi9-python-3.12" \ |
| 43 | + io.openshift.build.image="quay.io/opendatahub/workbench-images:codeserver-ubi9-python-3.12" |
| 44 | + |
| 45 | +USER 0 |
| 46 | + |
| 47 | +WORKDIR /opt/app-root/bin |
| 48 | + |
| 49 | +# Install usefull OS packages |
| 50 | +RUN dnf install -y jq git-lfs libsndfile && dnf clean all && rm -rf /var/cache/yum |
| 51 | + |
| 52 | +# Install code-server |
| 53 | +RUN yum install -y "https://github.com/coder/code-server/releases/download/${CODESERVER_VERSION}/code-server-${CODESERVER_VERSION/v/}-amd64.rpm" && \ |
| 54 | + yum -y clean all --enablerepo='*' |
| 55 | + |
| 56 | +COPY --chown=1001:0 ${CODESERVER_SOURCE_CODE}/utils utils/ |
| 57 | + |
| 58 | +# Create and intall the extensions though build-time on a temporary directory. Later this directory will copied on the `/opt/app-root/src/.local/share/code-server/extensions` via run-code-server.sh file when it starts up. |
| 59 | +RUN mkdir -p /opt/app-root/extensions-temp && \ |
| 60 | + code-server --install-extension /opt/app-root/bin/utils/ms-python.python-2025.2.0.vsix --extensions-dir /opt/app-root/extensions-temp && \ |
| 61 | + code-server --install-extension /opt/app-root/bin/utils/ms-toolsai.jupyter-2025.2.0.vsix --extensions-dir /opt/app-root/extensions-temp |
| 62 | + |
| 63 | +# Install NGINX to proxy code-server and pass probes check |
| 64 | +ENV NGINX_VERSION=1.24 \ |
| 65 | + NGINX_SHORT_VER=124 \ |
| 66 | + NGINX_CONFIGURATION_PATH=${APP_ROOT}/etc/nginx.d \ |
| 67 | + NGINX_CONF_PATH=/etc/nginx/nginx.conf \ |
| 68 | + NGINX_DEFAULT_CONF_PATH=${APP_ROOT}/etc/nginx.default.d \ |
| 69 | + NGINX_CONTAINER_SCRIPTS_PATH=/usr/share/container-scripts/nginx \ |
| 70 | + NGINX_APP_ROOT=${APP_ROOT} \ |
| 71 | + NGINX_LOG_PATH=/var/log/nginx \ |
| 72 | + NGINX_PERL_MODULE_PATH=${APP_ROOT}/etc/perl |
| 73 | + |
| 74 | +# Modules does not exist |
| 75 | +RUN yum install -y https://download.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm && \ |
| 76 | + INSTALL_PKGS="bind-utils nginx nginx-mod-stream nginx-mod-http-perl fcgiwrap initscripts chkconfig supervisor" && \ |
| 77 | + yum install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \ |
| 78 | + rpm -V $INSTALL_PKGS && \ |
| 79 | + yum -y clean all --enablerepo='*' |
| 80 | + |
| 81 | +COPY --chown=1001:0 ${CODESERVER_SOURCE_CODE}/supervisord/supervisord.conf /etc/supervisor/conf.d/supervisord.conf |
| 82 | + |
| 83 | +# Copy extra files to the image. |
| 84 | +COPY --chown=1001:0 ${CODESERVER_SOURCE_CODE}/nginx/root/ / |
| 85 | + |
| 86 | +# Changing ownership and user rights to support following use-cases: |
| 87 | +# 1) running container on OpenShift, whose default security model |
| 88 | +# is to run the container under random UID, but GID=0 |
| 89 | +# 2) for working root-less container with UID=1001, which does not have |
| 90 | +# to have GID=0 |
| 91 | +# 3) for default use-case, that is running container directly on operating system, |
| 92 | +# with default UID and GID (1001:0) |
| 93 | +# Supported combinations of UID:GID are thus following: |
| 94 | +# UID=1001 && GID=0 |
| 95 | +# UID=<any>&& GID=0 |
| 96 | +# UID=1001 && GID=<any> |
| 97 | +RUN sed -i -f ${NGINX_APP_ROOT}/nginxconf.sed ${NGINX_CONF_PATH} && \ |
| 98 | + mkdir -p ${NGINX_APP_ROOT}/etc/nginx.d/ && \ |
| 99 | + mkdir -p ${NGINX_APP_ROOT}/etc/nginx.default.d/ && \ |
| 100 | + mkdir -p ${NGINX_APP_ROOT}/api/ && \ |
| 101 | + mkdir -p ${NGINX_CONTAINER_SCRIPTS_PATH}/nginx-start && \ |
| 102 | + mkdir -p ${NGINX_LOG_PATH} && \ |
| 103 | + mkdir -p ${NGINX_PERL_MODULE_PATH} && \ |
| 104 | + chown -R 1001:0 ${NGINX_CONF_PATH} && \ |
| 105 | + chown -R 1001:0 ${NGINX_APP_ROOT}/etc && \ |
| 106 | + chown -R 1001:0 ${NGINX_CONTAINER_SCRIPTS_PATH}/nginx-start && \ |
| 107 | + chown -R 1001:0 /var/lib/nginx /var/log/nginx /run && \ |
| 108 | + chmod ug+rw ${NGINX_CONF_PATH} && \ |
| 109 | + chmod -R ug+rwX ${NGINX_APP_ROOT}/etc && \ |
| 110 | + chmod -R ug+rwX ${NGINX_CONTAINER_SCRIPTS_PATH}/nginx-start && \ |
| 111 | + chmod -R ug+rwX /var/lib/nginx /var/log/nginx /run && \ |
| 112 | + rpm-file-permissions && \ |
| 113 | + # Ensure the temporary directory and target directory have the correct permissions |
| 114 | + mkdir -p /opt/app-root/src/.local/share/code-server/extensions && \ |
| 115 | + mkdir -p /opt/app-root/src/.local/share/code-server/coder-logs && \ |
| 116 | + chown -R 1001:0 /opt/app-root/src/.local/share/code-server && \ |
| 117 | + chown -R 1001:0 /opt/app-root/extensions-temp && \ |
| 118 | + chown -R 1001:0 /opt/app-root/src/.config/code-server |
| 119 | + |
| 120 | +## Configure nginx |
| 121 | +COPY ${CODESERVER_SOURCE_CODE}/nginx/serverconf/ /opt/app-root/etc/nginx.default.d/ |
| 122 | +COPY ${CODESERVER_SOURCE_CODE}/nginx/httpconf/ /opt/app-root/etc/nginx.d/ |
| 123 | +COPY ${CODESERVER_SOURCE_CODE}/nginx/api/ /opt/app-root/api/ |
| 124 | + |
| 125 | +# Launcher |
| 126 | +COPY --chown=1001:0 ${CODESERVER_SOURCE_CODE}/run-code-server.sh ${CODESERVER_SOURCE_CODE}/run-nginx.sh ./ |
| 127 | + |
| 128 | +ENV SHELL=/bin/bash |
| 129 | + |
| 130 | +ENV PYTHONPATH=/opt/app-root/bin/python3 |
| 131 | + |
| 132 | +USER 1001 |
| 133 | + |
| 134 | +# Install usefull packages from Pipfile.lock |
| 135 | +COPY ${CODESERVER_SOURCE_CODE}/Pipfile.lock ./ |
| 136 | + |
| 137 | +# Install packages and cleanup |
| 138 | +RUN echo "Installing softwares and packages" && \ |
| 139 | + micropipenv install && \ |
| 140 | + rm -f ./Pipfile.lock && \ |
| 141 | + # Fix permissions to support pip in Openshift environments \ |
| 142 | + chmod -R g+w /opt/app-root/lib/python3.12/site-packages && \ |
| 143 | + fix-permissions /opt/app-root -P |
| 144 | + |
| 145 | +WORKDIR /opt/app-root/src |
| 146 | + |
| 147 | +CMD ["/opt/app-root/bin/run-code-server.sh"] |
0 commit comments