Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split Dockerfile in two stages: builder and runtime. #31

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 37 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -32,10 +31,44 @@ 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/

# Build 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"
pablospe marked this conversation as resolved.
Show resolved Hide resolved
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand All @@ -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

Expand Down
Loading