-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
103 lines (82 loc) · 3.51 KB
/
Dockerfile
File metadata and controls
103 lines (82 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# Default build produces the "runtime" stage (slim). Use --target gtsam for a dev image with build tools and shell.
# Pre-built Python base image (build once with Dockerfile.python-base, push to registry)
# To build locally without registry: docker build -f Dockerfile.python-base -t python-optimized:3.11.2-trixie .
ARG PYTHON_BASE_IMAGE=python-optimized:3.11.2-trixie
FROM ${PYTHON_BASE_IMAGE} AS dependencies
# Disable GUI prompts
ENV DEBIAN_FRONTEND=noninteractive
# Install GTSAM build dependencies (Python already installed in base image)
RUN apt-get update && apt-get install -y --no-install-recommends \
apt-utils \
build-essential \
libboost-all-dev \
cmake \
libtbb-dev \
flex \
bison \
dejagnu \
libmpc-dev \
libmpfr-dev \
libgmp-dev \
make \
&& rm -rf /var/lib/apt/lists/*
# Set working directory
WORKDIR /usr/src
# Use git to clone gtsam and specific GTSAM version
FROM alpine/git:2.52.0 AS gtsam-clone
ARG GTSAM_VERSION=4.2.0
WORKDIR /usr/src/
# Shallow clone specific tag for smaller, faster fetch
RUN git clone --depth 1 --branch ${GTSAM_VERSION} https://github.com/borglab/gtsam.git
# Create new stage called gtsam for GTSAM building
FROM dependencies AS gtsam
ARG PYTHON_VERSION=3.11.2
# Needed to link with GTSAM (ENV works in non-interactive shells; .bashrc does not)
ENV LD_LIBRARY_PATH=/usr/local/lib
# Move gtsam data
COPY --from=gtsam-clone /usr/src/gtsam /usr/src/gtsam
WORKDIR /usr/src/gtsam/build
# Install python wrapper requirements, then pin numpy for GTSAM ABI compatibility
RUN python3 -m pip install --no-cache-dir -U -r /usr/src/gtsam/python/requirements.txt && \
python3 -m pip install --no-cache-dir "numpy==1.26.4"
# Run cmake
RUN cmake \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DGTSAM_WITH_EIGEN_MKL=OFF \
-DGTSAM_BUILD_EXAMPLES_ALWAYS=OFF \
-DGTSAM_BUILD_TIMING_ALWAYS=OFF \
-DGTSAM_BUILD_TESTS=OFF \
-DGTSAM_BUILD_PYTHON=ON \
-DGTSAM_BUILD_CONVENIENCE_LIBRARIES=OFF \
-DGTSAM_PYTHON_VERSION=${PYTHON_VERSION} \
-DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
..
# Build, install, strip binaries, and clean in one layer to reduce image size
RUN make -j$(nproc) install && \
make python-install && \
#find /usr/local -type f \( -name "*.so" -o -name "*.so.*" \) -exec strip --strip-unneeded {} \; 2>/dev/null || true && \
#find /usr/local/bin /usr/local/lib -executable -type f -exec strip --strip-unneeded {} \; 2>/dev/null || true && \
make clean && \
ldconfig
# Final cleanup (dependencies stage already cleared apt lists)
RUN rm -rf /tmp/* /var/tmp/*
# -----------------------------------------------------------------------------
# Slim runtime stage: copy only installed artifacts, no build tools or source
# -----------------------------------------------------------------------------
FROM debian:trixie-slim AS runtime
ENV DEBIAN_FRONTEND=noninteractive
ENV PATH="/usr/local/bin:${PATH}"
ENV LD_LIBRARY_PATH=/usr/local/lib
# Runtime libs only. Python binary (ldd python3.11) needs only libc/libm/libpython; GTSAM needs Boost + TBB (see scripts/audit-runtime-deps.sh).
# Add back libssl3t64 libbz2-1.0 libreadline8t64 libsqlite3-0 libffi8 zlib1g libncursesw6 if you import ssl/sqlite3/readline/etc.
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
libtbb12 \
libtbbmalloc2 \
libboost-serialization1.83.0 \
libboost-filesystem1.83.0 \
libboost-timer1.83.0 \
&& rm -rf /var/lib/apt/lists/*
COPY --from=gtsam /usr/local /usr/local
RUN ldconfig
CMD ["python3"]