Skip to content

Commit

Permalink
Improve build and optional dependency handing in Dockerfiles (#3476)
Browse files Browse the repository at this point in the history
* As we no longer install dependencies in container, we need them.

* Use build-requirements.txt file

* Improve comments in Dockerfile.
  • Loading branch information
jhale authored Oct 21, 2024
1 parent d7e57a0 commit 18a20d7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions docker/Dockerfile.end-user
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,14 @@ ONBUILD ADD dolfinx/ /src/dolfinx/
ONBUILD ADD dolfinx/docker/dolfinx_jit_options.json /root/.config/dolfinx/dolfinx_jit_options.json
ONBUILD ADD dolfinx/docker/ffcx_options.json /root/.config/ffcx/ffcx_options.json

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

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

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

# --no-dependencies necessary as --target does not contain any dependencies e.g.
# mpi4py - leading to unwanted rebuild.
ONBUILD RUN cd dolfinx && \
mkdir -p build-real && \
cd build-real && \
Expand All @@ -92,7 +96,7 @@ ONBUILD RUN cd dolfinx && \
cd ../python && \
PETSC_ARCH=linux-gnu-real64-32 pip -v install \
--config-settings=cmake.build-type="${DOLFINX_CMAKE_BUILD_TYPE}" --config-settings=install.strip=false --no-build-isolation --check-build-dependencies \
--target /usr/local/dolfinx-real/lib/python${PYTHON_VERSION}/dist-packages --no-dependencies --no-cache-dir '.[test]' && \
--target /usr/local/dolfinx-real/lib/python${PYTHON_VERSION}/dist-packages --no-dependencies --no-cache-dir '.' && \
git clean -fdx && \
cd ../ && \
mkdir -p build-complex && \
Expand All @@ -103,7 +107,7 @@ ONBUILD RUN cd dolfinx && \
cd ../python && \
PETSC_ARCH=linux-gnu-complex128-32 pip -v install \
--config-settings=cmake.build-type="${DOLFINX_CMAKE_BUILD_TYPE}" --config-settings=install.strip=false --no-build-isolation --check-build-dependencies \
--target /usr/local/dolfinx-complex/lib/python${PYTHON_VERSION}/dist-packages --no-dependencies --no-cache-dir '.[test]'
--target /usr/local/dolfinx-complex/lib/python${PYTHON_VERSION}/dist-packages --no-dependencies --no-cache-dir '.'

# Real by default.
ONBUILD ENV PKG_CONFIG_PATH=/usr/local/dolfinx-real/lib/pkgconfig:$PKG_CONFIG_PATH \
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.test-env
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ RUN python3 -m venv ${VIRTUAL_ENV}
# Install Python packages (via pip)
RUN pip install --no-cache-dir --upgrade pip setuptools wheel && \
pip install --no-cache-dir cython numpy==${NUMPY_VERSION} && \
pip install --no-cache-dir --no-build-isolation mpi4py
pip install --no-cache-dir mpi4py

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

0 comments on commit 18a20d7

Please sign in to comment.