From f907bd72c1ec397180e7d9547bad6b74cc805cf4 Mon Sep 17 00:00:00 2001 From: Pablo Speciale Date: Sun, 28 Jan 2024 21:22:57 +0100 Subject: [PATCH 1/4] By dividing the Dockerfile into two stages, we significantly reduce the size of the final image. This is because the build dependencies, which are not required in the final image, are excluded. You can create tags for each stage separately using the `--target` option: ```bash docker build --target builder -t pyceres:builder . docker build --target runtime -t pyceres:runtime . ``` However, if you run the `docker build` command without the `--target` option, it will build up to the last stage defined in the Dockerfile. So, running: ```bash docker build -t pyceres:latest . ``` is equivalent to specifying `--target runtime`, as runtime is the final stage in the Dockerfile. --- Dockerfile | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index d57da3d..d36f171 100644 --- a/Dockerfile +++ b/Dockerfile @@ -44,19 +44,51 @@ RUN apt-get install -y --no-install-recommends --no-install-suggests wget && \ tar zxf ceres-solver-2.1.0.tar.gz && \ mkdir ceres-build && \ cd ceres-build && \ - cmake ../ceres-solver-2.1.0 -GNinja && \ + cmake ../ceres-solver-2.1.0 -GNinja \ + -DCMAKE_INSTALL_PREFIX=/ceres_installed && \ ninja install +RUN cp -r /ceres_installed/* /usr/local/ # Install Colmap. RUN wget "https://github.com/colmap/colmap/archive/refs/tags/${COLMAP_VERSION}.tar.gz" -O colmap-${COLMAP_VERSION}.tar.gz && \ tar zxvf colmap-${COLMAP_VERSION}.tar.gz && \ mkdir colmap-build && \ cd colmap-build && \ - cmake ../colmap-${COLMAP_VERSION} -GNinja -DCMAKE_CUDA_ARCHITECTURES=${CUDA_ARCHITECTURES} && \ + cmake ../colmap-${COLMAP_VERSION} -GNinja \ + -DCMAKE_CUDA_ARCHITECTURES=${CUDA_ARCHITECTURES} \ + -DCMAKE_INSTALL_PREFIX=/colmap_installed && \ ninja install - +RUN cp -r /colmap_installed/* /usr/local/ # Build pyceres. -COPY . /pyceres +RUN git clone --depth 1 --recursive https://github.com/cvg/pyceres WORKDIR /pyceres -RUN pip install . -vv --config-settings=cmake.define.CMAKE_CUDA_ARCHITECTURES=${CUDA_ARCHITECTURES} +RUN pip wheel --no-deps -w dist-wheel . -vv && \ + whl_path=$(find dist-wheel/ -name "*.whl") && \ + echo $whl_path >dist-wheel/whl_path.txt + + +# +# Runtime stage. +# +FROM nvidia/cuda:${NVIDIA_CUDA_VERSION}-runtime-ubuntu${UBUNTU_VERSION} as runtime + +# Install minimal runtime dependencies. +RUN apt-get update && \ + apt-get install -y --no-install-recommends --no-install-suggests \ + libgoogle-glog0v5 \ + python-is-python3 \ + python3-minimal \ + python3-pip + +# Copy installed libraries in builder stage. +COPY --from=builder /ceres_installed/ /usr/local/ +COPY --from=builder /colmap_installed/ /usr/local/ + +# Install pyceres. +COPY --from=builder /pyceres/dist-wheel /tmp/dist-wheel +RUN cd /tmp && whl_path=$(cat dist-wheel/whl_path.txt) && pip install $whl_path +RUN rm -rfv /tmp/* + +# Verify if pyceres library is accessible from python. +RUN python -c "import pyceres" From 520c19860975f427c37d58a3b056da6f75a69618 Mon Sep 17 00:00:00 2001 From: Pablo Speciale Date: Sun, 28 Jan 2024 22:48:49 +0100 Subject: [PATCH 2/4] fixes --- Dockerfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index d36f171..2d9c2e0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -61,9 +61,10 @@ RUN wget "https://github.com/colmap/colmap/archive/refs/tags/${COLMAP_VERSION}.t RUN cp -r /colmap_installed/* /usr/local/ # Build pyceres. -RUN git clone --depth 1 --recursive https://github.com/cvg/pyceres +ADD . /pyceres WORKDIR /pyceres -RUN pip wheel --no-deps -w dist-wheel . -vv && \ +RUN pip install --upgrade pip +RUN pip wheel . --no-deps -w dist-wheel -vv --config-settings=cmake.define.CMAKE_CUDA_ARCHITECTURES=${CUDA_ARCHITECTURES} && \ whl_path=$(find dist-wheel/ -name "*.whl") && \ echo $whl_path >dist-wheel/whl_path.txt From 1ffab03e174e72f410633aeb956744a58c4e7424 Mon Sep 17 00:00:00 2001 From: Pablo Speciale Date: Tue, 6 Feb 2024 22:35:04 +0100 Subject: [PATCH 3/4] update with main branch modifications --- Dockerfile | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index b9c5469..18c1c9d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,5 @@ ARG UBUNTU_VERSION=22.04 -ARG NVIDIA_CUDA_VERSION=12.3.1 -FROM nvidia/cuda:${NVIDIA_CUDA_VERSION}-devel-ubuntu${UBUNTU_VERSION} as builder +FROM ubuntu:${UBUNTU_VERSION} as builder ENV QT_XCB_GL_INTEGRATION=xcb_egl @@ -36,7 +35,40 @@ RUN apt-get install -y --no-install-recommends --no-install-suggests wget && \ -DCMAKE_INSTALL_PREFIX=/ceres_installed && \ ninja install RUN cp -r /ceres_installed/* /usr/local/ + # Build pyceres. -ADD . /pyceres +COPY . /pyceres WORKDIR /pyceres -RUN pip install . -vv +RUN pip install --upgrade pip +RUN pip wheel . --no-deps -w dist-wheel -vv && \ + whl_path=$(find dist-wheel/ -name "*.whl") && \ + echo $whl_path >dist-wheel/whl_path.txt + + +# +# Runtime stage. +# +FROM ubuntu:${UBUNTU_VERSION} as runtime + +# Install minimal runtime dependencies. +RUN apt-get update && \ + apt-get install -y --no-install-recommends --no-install-suggests \ + libgoogle-glog0v5 \ + libspqr2 \ + libcxsparse3 \ + libatlas3-base \ + python-is-python3 \ + python3-minimal \ + python3-pip + +# Copy installed library in the builder stage. +COPY --from=builder /ceres_installed/ /usr/local/ + +# Install pyceres. +COPY --from=builder /pyceres/dist-wheel /tmp/dist-wheel +RUN pip install --upgrade pip +RUN cd /tmp && whl_path=$(cat dist-wheel/whl_path.txt) && pip install $whl_path +RUN rm -rfv /tmp/* + +# # Verify if pyceres library is accessible from python. +RUN python -c "import pyceres" From 2f0549a8bd4bfddc2e9be62f738052c4f020f3c9 Mon Sep 17 00:00:00 2001 From: Pablo Speciale Date: Thu, 8 Feb 2024 11:51:34 +0100 Subject: [PATCH 4/4] README improvements --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b9a7f1f..a826171 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ This repository provides minimal Python bindings for the [Ceres Solver](http://c ## Installation Wheels for Python 8/9/10 on Linux, macOS 10+ (both Intel and Apple Silicon), and Windows can be installed using pip: -```bash +```sh pip install pyceres ``` @@ -22,8 +22,13 @@ python -m pip install . Alternatively, you can build the Docker image: ```sh -docker build -t pyceres -f Dockerfile . +docker build --target builder -t pyceres:builder . +docker build --target runtime -t pyceres:runtime . ``` +Note: The builder image can be used for development and testing, as it contains +all the necessary dependencies for building the project. On the other hand, the +runtime version is streamlined for running pyceres, containing only the minimal +dependencies required for execution, making it lightweight. ## Factor graph optimization