Skip to content

Commit 27e2dba

Browse files
committed
Upgrade to trixie, use slim in image
1 parent 104c2ba commit 27e2dba

1 file changed

Lines changed: 62 additions & 74 deletions

File tree

Dockerfile

Lines changed: 62 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
FROM debian:bullseye as dependencies
1+
# Default build produces the "runtime" stage (slim). Use --target gtsam for a dev image with build tools and shell.
2+
FROM debian:trixie-20260112 AS dependencies
23
ARG PYTHON_VERSION=3.11.2
34

45
# Disable GUI prompts
5-
ENV DEBIAN_FRONTEND noninteractive
6+
ENV DEBIAN_FRONTEND=noninteractive
67

7-
8-
RUN rm /var/lib/dpkg/info/libc-bin.*
9-
RUN apt-get clean && apt-get update
10-
RUN apt-get -y install libc-bin
11-
12-
# Install required build dependencies
13-
RUN apt-get update && apt-get install -y \
8+
# Install required build dependencies (single update for better layer caching)
9+
RUN apt-get update && apt-get install -y --no-install-recommends \
10+
ca-certificates \
1411
build-essential \
1512
wget \
1613
libssl-dev \
@@ -33,56 +30,9 @@ RUN apt-get update && apt-get install -y \
3330
libmpc-dev \
3431
libmpfr-dev \
3532
libgmp-dev \
33+
make \
3634
&& rm -rf /var/lib/apt/lists/*
3735

38-
39-
# Download and build GCC 13.4
40-
RUN wget https://ftp.gnu.org/gnu/gcc/gcc-13.4.0/gcc-13.4.0.tar.gz && \
41-
tar -xzf gcc-13.4.0.tar.gz && \
42-
cd gcc-13.4.0 && \
43-
./contrib/download_prerequisites && \
44-
mkdir build && \
45-
cd build && \
46-
../configure --prefix=/usr/local/gcc-13.4.0 \
47-
--enable-languages=c,c++ \
48-
--disable-multilib \
49-
--disable-bootstrap \
50-
--enable-checking=release && \
51-
make -j$(nproc) && \
52-
make install && \
53-
cd ../.. && \
54-
rm -rf gcc-13.4.0 gcc-13.4.0.tar.gz
55-
56-
# Set up GCC 13.4 as the default compiler
57-
ENV PATH="/usr/local/gcc-13.4.0/bin:${PATH}"
58-
ENV LD_LIBRARY_PATH="/usr/local/gcc-13.4.0/lib64:${LD_LIBRARY_PATH}"
59-
ENV CC="/usr/local/gcc-13.4.0/bin/gcc"
60-
ENV CXX="/usr/local/gcc-13.4.0/bin/g++"
61-
62-
# Create symlinks for easier access
63-
RUN ln -sf /usr/local/gcc-13.4.0/bin/gcc /usr/local/bin/gcc && \
64-
ln -sf /usr/local/gcc-13.4.0/bin/g++ /usr/local/bin/g++
65-
66-
# Install Make 4.4.1
67-
RUN wget https://ftp.gnu.org/gnu/make/make-4.4.1.tar.gz && \
68-
tar -xzf make-4.4.1.tar.gz && \
69-
cd make-4.4.1 && \
70-
./configure --prefix=/usr/local && \
71-
make -j$(nproc) && \
72-
make install && \
73-
cd .. && \
74-
rm -rf make-4.4.1 make-4.4.1.tar.gz
75-
76-
# Install CMake 4.0.3
77-
RUN wget https://github.com/Kitware/CMake/releases/download/v4.0.3/cmake-4.0.3.tar.gz && \
78-
tar -xzf cmake-4.0.3.tar.gz && \
79-
cd cmake-4.0.3 && \
80-
./bootstrap --prefix=/usr/local && \
81-
make -j$(nproc) && \
82-
make install && \
83-
cd .. && \
84-
rm -rf cmake-4.0.3 cmake-4.0.3.tar.gz
85-
8636
# Set working directory
8737
WORKDIR /usr/src
8838

@@ -100,33 +50,32 @@ RUN wget https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VER
10050
# Ensure /usr/local/bin is in the PATH
10151
ENV PATH="/usr/local/bin:${PATH}"
10252

103-
RUN python3 -m pip install --upgrade pip
53+
RUN python3 -m pip install --no-cache-dir --upgrade pip
10454

10555
# Use git to clone gtsam and specific GTSAM version
106-
FROM alpine/git:2.52.0 as gtsam-clone
56+
FROM alpine/git:2.52.0 AS gtsam-clone
10757

10858
ARG GTSAM_VERSION=4.2.0
10959
WORKDIR /usr/src/
11060

111-
# Clone GTSAM and checkout to given GTSAM_VERSION tag
112-
RUN git clone --no-checkout https://github.com/borglab/gtsam.git && \
113-
cd gtsam && \
114-
git fetch origin tag ${GTSAM_VERSION} && \
115-
git checkout ${GTSAM_VERSION}
61+
# Shallow clone specific tag for smaller, faster fetch
62+
RUN git clone --depth 1 --branch ${GTSAM_VERSION} https://github.com/borglab/gtsam.git
11663

11764
# Create new stage called gtsam for GTSAM building
118-
FROM dependencies as gtsam
65+
FROM dependencies AS gtsam
66+
67+
ARG PYTHON_VERSION=3.11.2
68+
69+
# Needed to link with GTSAM (ENV works in non-interactive shells; .bashrc does not)
70+
ENV LD_LIBRARY_PATH=/usr/local/lib
11971

12072
# Move gtsam data
12173
COPY --from=gtsam-clone /usr/src/gtsam /usr/src/gtsam
12274

12375
WORKDIR /usr/src/gtsam/build
12476

125-
# Needed to link with GTSAM
126-
RUN echo "export LD_LIBRARY_PATH=/usr/local/lib:\$LD_LIBRARY_PATH" >> /root/.bashrc
127-
12877
# Install python wrapper requirements
129-
RUN python3 -m pip install -U -r /usr/src/gtsam/python/requirements.txt
78+
RUN python3 -m pip install --no-cache-dir -U -r /usr/src/gtsam/python/requirements.txt
13079

13180
# Run cmake
13281
RUN cmake \
@@ -141,14 +90,53 @@ RUN cmake \
14190
-DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
14291
..
14392

144-
# Make install and clean up
93+
# Build, install, strip binaries, and clean in one layer to reduce image size
14594
RUN make -j$(nproc) install && \
14695
make python-install && \
147-
make clean
96+
find /usr/local -type f \( -name "*.so" -o -name "*.so.*" \) -exec strip --strip-unneeded {} \; 2>/dev/null || true && \
97+
find /usr/local/bin /usr/local/lib -executable -type f -exec strip --strip-unneeded {} \; 2>/dev/null || true && \
98+
make clean && \
99+
ldconfig
100+
101+
# Final cleanup (dependencies stage already cleared apt lists)
102+
RUN rm -rf /tmp/* /var/tmp/*
103+
104+
# -----------------------------------------------------------------------------
105+
# Slim runtime stage: copy only installed artifacts, no build tools or source
106+
# -----------------------------------------------------------------------------
107+
FROM debian:trixie-slim AS runtime
108+
109+
ENV DEBIAN_FRONTEND=noninteractive
110+
ENV PATH="/usr/local/bin:${PATH}"
111+
ENV LD_LIBRARY_PATH=/usr/local/lib
112+
113+
# Runtime libs only (no -dev, no build-essential). Match what Python + GTSAM link to.
114+
# Verify with: ldd /usr/local/lib/libgtsam.so /usr/local/bin/python3.11 (in build image)
115+
RUN apt-get update && apt-get install -y --no-install-recommends \
116+
ca-certificates \
117+
libssl3t64 \
118+
libbz2-1.0 \
119+
libreadline8t64 \
120+
libsqlite3-0 \
121+
libffi8 \
122+
zlib1g \
123+
libncursesw6 \
124+
libtbb12 \
125+
libgmp10 \
126+
libmpfr6 \
127+
libmpc3 \
128+
libboost-serialization1.83.0 \
129+
libboost-system1.83.0 \
130+
libboost-thread1.83.0 \
131+
libboost-date-time1.83.0 \
132+
libboost-filesystem1.83.0 \
133+
libboost-chrono1.83.0 \
134+
libboost-atomic1.83.0 \
135+
libboost-timer1.83.0 \
136+
&& rm -rf /var/lib/apt/lists/*
148137

149-
RUN apt-get clean && \
150-
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
138+
COPY --from=gtsam /usr/local /usr/local
151139

152140
RUN ldconfig
153141

154-
CMD ["bash"]
142+
CMD ["python3"]

0 commit comments

Comments
 (0)