1+ # File: tools/Dockerfile.multistage
2+ # Target: Creates an optimized, smaller final image using a multi-stage build.
3+ # Contains full Python support.
4+
5+ # --- STAGE 1: The "Builder" ---
6+ # This stage is a temporary environment used to compile the C++ code.
7+ # It contains all the heavy build tools, which will NOT be in the final image.
8+ FROM ubuntu:22.04 AS builder
9+
10+ # Install build tools and C++ dependencies
11+ RUN apt-get update && \
12+ apt-get install -y --no-install-recommends \
13+ build-essential \
14+ libnetcdf-c++4-dev \
15+ cmake \
16+ git && \
17+ rm -rf /var/lib/apt/lists/*
18+
19+ WORKDIR /src
20+
21+ # Copy all source code into the builder stage
22+ COPY . .
23+
24+ # Build the C++ library and executable
25+ RUN sh cmake-build.sh
26+
27+
28+ # --- STAGE 2: The "Final Image" ---
29+ # This is the final, clean image that will be distributed.
30+ # It starts from a fresh Ubuntu base and only pulls in what's necessary.
31+ FROM ubuntu:22.04
32+
33+ # Install only the RUNTIME dependencies needed for ForeFire and the Python bindings.
34+ # As requested, we use libnetcdf-c++4-dev here for consistency with the build stage.
35+ RUN apt-get update && \
36+ apt-get install -y --no-install-recommends \
37+ libnetcdf-c++4-dev \
38+ libgomp1 \
39+ python3 \
40+ g++ \
41+ python3-pip \
42+ python3-dev && \
43+ rm -rf /var/lib/apt/lists/*
44+
45+ WORKDIR /forefire
46+ ENV FOREFIREHOME=/forefire
47+
48+ # The magic step: Copy the ENTIRE built project from the 'builder' stage.
49+ # This brings over the compiled libs, binaries, and the source code needed for the bindings.
50+ COPY --from=builder /src/ .
51+
52+ # Add the forefire executable to the system's PATH
53+ RUN cp /forefire/bin/forefire /usr/local/bin/
54+
55+ # Install the Python bindings and their dependencies (numpy, etc.)
56+ # This compiles the C++ extension using the headers we just copied.
57+ RUN pip3 install ./bindings/python
58+
59+ # Set the default command to start a bash shell
60+ CMD ["bash"]
0 commit comments