Skip to content

Commit 18a20d7

Browse files
authored
Improve build and optional dependency handing in Dockerfiles (#3476)
* As we no longer install dependencies in container, we need them. * Use build-requirements.txt file * Improve comments in Dockerfile.
1 parent d7e57a0 commit 18a20d7

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

docker/Dockerfile.end-user

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,14 @@ ONBUILD ADD dolfinx/ /src/dolfinx/
6767
ONBUILD ADD dolfinx/docker/dolfinx_jit_options.json /root/.config/dolfinx/dolfinx_jit_options.json
6868
ONBUILD ADD dolfinx/docker/ffcx_options.json /root/.config/ffcx/ffcx_options.json
6969

70-
# The following ARGS are used in the DOLFINx layer.
71-
# They are safe defaults.
7270
# CMake build type for DOLFINx C++ build. See CMake documentation.
7371
ONBUILD ARG DOLFINX_CMAKE_BUILD_TYPE="Release"
7472

75-
ONBUILD RUN pip install --no-cache-dir nanobind scikit-build-core[pyproject]
73+
# Using pip install `.[test]` with --no-dependencies and --no-build-isolation
74+
# does not install necessary packages, hence install build and optional
75+
# dependencies manually here.
76+
ONBUILD RUN pip install --no-cache-dir -r dolfinx/python/build-requirements.txt && \
77+
pip install --no-cache-dir pyamg pytest scipy matplotlib numba # test + optional set
7678

7779
# The dolfinx-onbuild container expects to have folders basix/ ufl/
7880
# ffcx/ and dolfinx/ mounted/shared at /src.
@@ -84,6 +86,8 @@ ONBUILD RUN cd basix && cmake -G Ninja -DCMAKE_BUILD_TYPE=${DOLFINX_CMAKE_BUILD_
8486
cd ../ffcx && pip install --no-cache-dir . && \
8587
cd ../ && pip install --no-cache-dir ipython
8688

89+
# --no-dependencies necessary as --target does not contain any dependencies e.g.
90+
# mpi4py - leading to unwanted rebuild.
8791
ONBUILD RUN cd dolfinx && \
8892
mkdir -p build-real && \
8993
cd build-real && \
@@ -92,7 +96,7 @@ ONBUILD RUN cd dolfinx && \
9296
cd ../python && \
9397
PETSC_ARCH=linux-gnu-real64-32 pip -v install \
9498
--config-settings=cmake.build-type="${DOLFINX_CMAKE_BUILD_TYPE}" --config-settings=install.strip=false --no-build-isolation --check-build-dependencies \
95-
--target /usr/local/dolfinx-real/lib/python${PYTHON_VERSION}/dist-packages --no-dependencies --no-cache-dir '.[test]' && \
99+
--target /usr/local/dolfinx-real/lib/python${PYTHON_VERSION}/dist-packages --no-dependencies --no-cache-dir '.' && \
96100
git clean -fdx && \
97101
cd ../ && \
98102
mkdir -p build-complex && \
@@ -103,7 +107,7 @@ ONBUILD RUN cd dolfinx && \
103107
cd ../python && \
104108
PETSC_ARCH=linux-gnu-complex128-32 pip -v install \
105109
--config-settings=cmake.build-type="${DOLFINX_CMAKE_BUILD_TYPE}" --config-settings=install.strip=false --no-build-isolation --check-build-dependencies \
106-
--target /usr/local/dolfinx-complex/lib/python${PYTHON_VERSION}/dist-packages --no-dependencies --no-cache-dir '.[test]'
110+
--target /usr/local/dolfinx-complex/lib/python${PYTHON_VERSION}/dist-packages --no-dependencies --no-cache-dir '.'
107111

108112
# Real by default.
109113
ONBUILD ENV PKG_CONFIG_PATH=/usr/local/dolfinx-real/lib/pkgconfig:$PKG_CONFIG_PATH \

docker/Dockerfile.test-env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ RUN python3 -m venv ${VIRTUAL_ENV}
150150
# Install Python packages (via pip)
151151
RUN pip install --no-cache-dir --upgrade pip setuptools wheel && \
152152
pip install --no-cache-dir cython numpy==${NUMPY_VERSION} && \
153-
pip install --no-cache-dir --no-build-isolation mpi4py
153+
pip install --no-cache-dir mpi4py
154154

155155
# Install KaHIP
156156
RUN wget -nc --quiet https://github.com/kahip/kahip/archive/v${KAHIP_VERSION}.tar.gz && \

0 commit comments

Comments
 (0)