Files

133 lines
4.2 KiB
Docker

ARG UBUNTU_VERSION=24.04
ARG NVIDIA_CUDA_VERSION=12.9.1
#
# Docker builder stage.
#
FROM nvidia/cuda:${NVIDIA_CUDA_VERSION}-devel-ubuntu${UBUNTU_VERSION} AS builder
ARG COLMAP_GIT_COMMIT=main
ARG CUDA_ARCHITECTURES=86
ENV QT_XCB_GL_INTEGRATION=xcb_egl
# Prevent stop building ubuntu at time zone selection.
ENV DEBIAN_FRONTEND=noninteractive
# Prepare and empty machine for building.
RUN apt-get update && \
apt-get install -y \
git \
cmake \
ninja-build \
build-essential \
libboost-program-options-dev \
libboost-graph-dev \
libboost-system-dev \
libeigen3-dev \
libopenimageio-dev \
openimageio-tools \
libmetis-dev \
libgoogle-glog-dev \
libgtest-dev \
libgmock-dev \
libsqlite3-dev \
libglew-dev \
qt6-base-dev \
libqt6opengl6-dev \
libqt6openglwidgets6 \
libcgal-dev \
libcurl4-openssl-dev \
libssl-dev \
libmkl-full-dev \
libsuitesparse-dev \
libcudss0-dev-cuda-12 \
libcudss0-static-cuda-12
# Install Ceres Solver with CUDA support. Disable testing and examples since
# the GPU isn't available to us at build time
RUN git clone --recursive https://github.com/ceres-solver/ceres-solver
RUN mkdir ceres-bin && \
cd ceres-bin && \
cmake ../ceres-solver \
-DUSE_CUDA=ON \
-DCMAKE_CUDA_ARCHITECTURES=${CUDA_ARCHITECTURES} \
-DBUILD_TESTING=OFF \
-DBUILD_EXAMPLES=OFF \
-DCMAKE_BUILD_TYPE=Release \
-Dcudss_DIR=/usr/lib/x86_64-linux-gnu/libcudss/12/cmake/cudss \
-Dcudss_INCLUDE_DIR=/usr/include/libcudss/12 && \
make -j8 && \
make test && \
make install
# Fix issue in Ubuntu's openimageio CMake config.
# We don't depend on any of openimageio's OpenCV functionality,
# but it still requires the OpenCV include directory to exist.
RUN mkdir -p /usr/include/opencv4
# Build and install COLMAP.
RUN git clone --recursive https://github.com/colmap/colmap.git
RUN cd colmap && \
git fetch https://github.com/colmap/colmap.git ${COLMAP_GIT_COMMIT} && \
git checkout FETCH_HEAD && \
mkdir build && \
cd build && \
cmake .. \
-GNinja \
-DCMAKE_CUDA_ARCHITECTURES=${CUDA_ARCHITECTURES} \
-DCMAKE_INSTALL_PREFIX=/colmap-install \
-DBLA_VENDOR=Intel10_64lp \
-Dcudss_DIR=/usr/lib/x86_64-linux-gnu/libcudss/12/cmake/cudss \
-Dcudss_INCLUDE_DIR=/usr/include/libcudss/12 && \
ninja install
#
# Docker runtime stage.
#
FROM nvidia/cuda:${NVIDIA_CUDA_VERSION}-runtime-ubuntu${UBUNTU_VERSION} AS runtime
# Minimal dependencies to run COLMAP binary compiled in the builder stage.
# Note: this reduces the size of the final image considerably, since all the
# build dependencies are not needed.
RUN apt-get update && \
apt-get install -y --no-install-recommends --no-install-suggests \
libboost-program-options1.83.0 \
libspqr4 \
libcholmod5 \
libc6 \
libomp5 \
libopengl0 \
libmetis5 \
libopenimageio2.4t64 \
libgcc-s1 \
libgl1 \
libglew2.2 \
libgoogle-glog0v6t64 \
libqt6core6 \
libqt6gui6 \
libqt6widgets6 \
libqt6openglwidgets6 \
libcurl4 \
libssl3t64 \
libmkl-locale \
libmkl-intel-lp64 \
libmkl-intel-thread \
libmkl-core \
libcudss0-cuda-12 && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Copy all files from /colmap-install/ in the builder stage to /usr/local/ in
# the runtime stage. This simulates installing COLMAP in the default location
# (/usr/local/), which simplifies environment variables. It also allows the user
# of this Docker image to use it as a base image for compiling against COLMAP as
# a library. For instance, CMake will be able to find COLMAP easily with the
# command: find_package(COLMAP REQUIRED).
COPY --from=builder /colmap-install/ /usr/local/
COPY --from=builder /usr/local/include/ /usr/local/include/
COPY --from=builder /usr/local/lib/ /usr/local/lib/
COPY --from=builder /usr/lib/x86_64-linux-gnu/libcudss /usr/lib/x86_64-linux-gnu/libcudss
ENV LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/libcudss/12:$LD_LIBRARY_PATH
WORKDIR /workspace