1+ ####################
2+ # rpm-base         #
3+ ####################
4+ FROM registry.access.redhat.com/ubi9/python-312:latest AS rpm-base
5+ 
6+ USER root
7+ WORKDIR /root
8+ 
9+ ENV HOME=/root
10+ 
11+ ARG CODESERVER_SOURCE_CODE=codeserver/ubi9-python-3.12
12+ 
13+ ARG NODE_VERSION=20
14+ 
15+ ARG CODESERVER_VERSION=v4.98.0
16+ 
17+ COPY ${CODESERVER_SOURCE_CODE}/get_code_server_rpm.sh .
18+ 
19+ # create dummy file to ensure this stage is awaited before installing rpm
20+ RUN ./get_code_server_rpm.sh && touch /tmp/control
21+ 
22+ #######################
23+ # wheel caching stage #
24+ #######################
25+ FROM registry.access.redhat.com/ubi9/python-312:latest AS whl-cache
26+ 
27+ USER root
28+ WORKDIR /root
29+ 
30+ ENV HOME=/root
31+ 
32+ ARG CODESERVER_SOURCE_CODE=codeserver/ubi9-python-3.12
33+ 
34+ # copy requirements and scripts
35+ COPY ${CODESERVER_SOURCE_CODE}/pylock.toml ./
36+ COPY ${CODESERVER_SOURCE_CODE}/devel_env_setup.sh ./
37+ 
38+ # This stage installs (builds) all the packages needed and caches it in uv-cache
39+ # Important: Since HOME & USER for the python-312 has been changed,
40+ #            we need to ensure the same cache directory is mounted in
41+ #            the final stage with the necessary permissions to consume from cache
42+ RUN --mount=type=cache,target=/root/.cache/uv \
43+     pip install --no-cache uv && \
44+     # the devel script is ppc64le specific - sets up build-time dependencies
45+     source ./devel_env_setup.sh && \
46+     # This may have to download and compile some dependencies, and as we don't lock requirements from `build-system.requires`,
47+     #  we often don't know the correct hashes and `--require-hashes` would therefore fail on non amd64, where building is common.
48+     uv pip install --strict --no-deps --refresh --no-config --no-progress --verify-hashes --compile-bytecode --index-strategy=unsafe-best-match --requirements=./pylock.toml
49+ 
50+ # dummy file to make image build wait for this stage
51+ RUN touch /tmp/control
52+ 
153####################
254# base             #
355####################
@@ -16,6 +68,15 @@ RUN dnf -y upgrade --refresh --best --nodocs --noplugins --setopt=install_weak_d
1668# Install useful OS packages
1769RUN dnf install -y mesa-libGL skopeo && dnf clean all && rm -rf /var/cache/yum
1870
71+ # (ARCH-ppc64le): since wheels are compiled from source, we need shared libs available at runtime
72+ RUN --mount=type=cache,from=whl-cache,source=/root/OpenBLAS,target=/OpenBlas,rw \
73+     bash -c ' \
74+         if [[ $(uname -m) == "ppc64le" ]]; then \
75+             dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm; \
76+             dnf install -y lcms2 libraqm libimagequant openjpeg2; \
77+             PREFIX=/usr/ make install -C /OpenBlas; \
78+         fi '
79+ 
1980# Other apps and tools installed as default user
2081USER 1001
2182
@@ -58,8 +119,13 @@ WORKDIR /opt/app-root/bin
58119# Install useful OS packages
59120RUN dnf install -y jq git-lfs libsndfile && dnf clean all && rm -rf /var/cache/yum
60121
122+ # wait for rpm-base stage (rpm builds for ppc64le)
123+ COPY --from=rpm-base /tmp/control /dev/null
124+ 
61125# Install code-server
62- RUN dnf install -y "https://github.com/coder/code-server/releases/download/${CODESERVER_VERSION}/code-server-${CODESERVER_VERSION/v/}-${TARGETARCH}.rpm" && \
126+ # Note: Use cache mounts, bind mounts fail on konflux
127+ RUN --mount=type=cache,from=rpm-base,source=/tmp/,target=/code-server-rpm/,rw \
128+     dnf install -y "/code-server-rpm/code-server-${CODESERVER_VERSION/v/}-${TARGETARCH}.rpm" && \
63129    dnf -y clean all --enablerepo='*'
64130
65131COPY --chown=1001:0 ${CODESERVER_SOURCE_CODE}/utils utils/
@@ -138,18 +204,28 @@ ENV SHELL=/bin/bash
138204
139205ENV PYTHONPATH=/opt/app-root/bin/python3
140206
141- USER 1001
142- 
143207# Install useful packages from requirements.txt
144208COPY ${CODESERVER_SOURCE_CODE}/pylock.toml ./
145209
210+ # wait for whl-cache stage (builds uv cache)
211+ COPY --from=whl-cache /tmp/control /dev/null
212+ 
146213# Install packages and cleanup
147- RUN echo "Installing softwares and packages" && \
148-     # This may have to download and compile some dependencies, and as we don't lock requirements from `build-system.requires`,
149-     #  we often don't know the correct hashes and `--require-hashes` would therefore fail on non amd64, where building is common.
150-     uv pip install --strict --no-deps --no-cache --no-config --no-progress --verify-hashes --compile-bytecode --index-strategy=unsafe-best-match --requirements=./pylock.toml && \
151-     # Fix permissions to support pip in Openshift environments \
152-     chmod -R g+w /opt/app-root/lib/python3.12/site-packages && \
214+ # install packages as USER 0 (this will allow us to consume uv cache)
215+ RUN --mount=type=cache,target=/root/.cache/uv \
216+     echo "Installing softwares and packages" && \
217+     # we can ensure wheels are consumed from the cache only by restricting internet access for uv install with '--offline' flag
218+     uv pip install --offline --cache-dir /root/.cache/uv --requirements=./pylock.toml && \
219+     # Note: debugpy wheel availabe on pypi (in uv cache) is none-any but bundles amd64.so files
220+     #       Build debugpy from source instead
221+     uv pip install --no-cache git+https://github.com/microsoft/debugpy.git@v$(grep -A1 '\"debugpy\"' ./pylock.toml | grep -Eo '\b[0-9\.]+\b') && \
222+     # change ownership to default user (all packages were installed as root and has root:root ownership \
223+     chown -R 1001:0 /opt/app-root/lib
224+ 
225+ USER 1001
226+ 
227+ # Fix permissions to support pip in Openshift environments
228+ RUN chmod -R g+w /opt/app-root/lib/python3.12/site-packages && \
153229    fix-permissions /opt/app-root -P
154230
155231WORKDIR /opt/app-root/src
0 commit comments