Skip to content

Commit 38d6747

Browse files
authored
Merge pull request #113 from forefireAPI/dev
dev to master Docker files with python
2 parents bbd758a + 29c1c0b commit 38d6747

6 files changed

Lines changed: 110 additions & 6 deletions

File tree

Dockerfile

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
11
FROM ubuntu:22.04
22

3+
# Install build tools, ForeFire dependencies, AND Python environment
34
RUN apt-get update && \
45
apt-get install -y --no-install-recommends \
56
build-essential \
67
libnetcdf-c++4-dev \
7-
cmake
8+
cmake \
9+
python3 \
10+
python3-pip \
11+
python3-dev \
12+
git && \
13+
rm -rf /var/lib/apt/lists/*
814

915
WORKDIR /forefire
1016
ENV FOREFIREHOME=/forefire
1117

1218
# we could only copy src, cmakelists.txt and cmake-build.sh
1319
COPY . .
1420

15-
# install forefire
21+
# Build and install the ForeFire C++ library
1622
RUN sh cmake-build.sh
1723

18-
# add executable to PATH
19-
RUN cp /forefire/bin/forefire /bin
24+
# Add the main forefire executable to the PATH
25+
RUN cp /forefire/bin/forefire /usr/local/bin/
26+
27+
# Use pip to install the Python dependencies defined in pyproject.toml
28+
RUN pip3 install ./bindings/python
29+
30+
# Set the entrypoint to bash for interactive sessions
31+
CMD ["bash"]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ The easiest way to get started is often using Docker and the interactive console
5858
3. Run the container interactively
5959

6060
```bash
61-
docker run -it --rm -p 8000:8000 --name ff_interactive forefire bash
61+
docker run -it --rm -p 8000:8000 --name ff_interactive forefire
6262
```
6363
4. Inside the container navigate to test directory and launch the forefire console:
6464
```bash

docs/source/getting_started/quickstart.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Steps
3434

3535
.. code-block:: bash
3636
37-
docker run -it --rm -p 8000:8000 --name ff_interactive forefire bash
37+
docker run -it --rm -p 8000:8000 --name ff_interactive forefire
3838
3939
4. **Inside the container, navigate to the test directory:**
4040

tools/docker/Dockerfile.base

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM ubuntu:22.04
2+
3+
RUN apt-get update && \
4+
apt-get install -y --no-install-recommends \
5+
build-essential \
6+
libnetcdf-c++4-dev \
7+
cmake
8+
9+
WORKDIR /forefire
10+
ENV FOREFIREHOME=/forefire
11+
12+
# we could only copy src, cmakelists.txt and cmake-build.sh
13+
COPY . .
14+
15+
# install forefire
16+
RUN sh cmake-build.sh
17+
18+
# add executable to PATH
19+
RUN cp /forefire/bin/forefire /usr/local/bin/
20+
21+
# Set the entrypoint to bash for interactive sessions
22+
CMD ["bash"]

tools/docker/Dockerfile.multistage

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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"]

tools/docker/readme.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
## Alternative Dockerfiles
2+
3+
WIP
4+
5+
- Dockerfile without python to make the image smaller
6+
- Multistage build to make the also smaller (490 vs 620 mb)
7+
8+
```
9+
docker build -f tools/docker/Dockerfile.multistage -t forefire:multistage .
10+
```

0 commit comments

Comments
 (0)