diff --git a/Dockerfile b/Dockerfile index 91ce315..d7bbed9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,16 @@ FROM ubuntu:22.04 +# Install build tools, ForeFire dependencies, AND Python environment RUN apt-get update && \ apt-get install -y --no-install-recommends \ build-essential \ libnetcdf-c++4-dev \ - cmake + cmake \ + python3 \ + python3-pip \ + python3-dev \ + git && \ + rm -rf /var/lib/apt/lists/* WORKDIR /forefire ENV FOREFIREHOME=/forefire @@ -12,8 +18,14 @@ ENV FOREFIREHOME=/forefire # we could only copy src, cmakelists.txt and cmake-build.sh COPY . . -# install forefire +# Build and install the ForeFire C++ library RUN sh cmake-build.sh -# add executable to PATH -RUN cp /forefire/bin/forefire /bin +# Add the main forefire executable to the PATH +RUN cp /forefire/bin/forefire /usr/local/bin/ + +# Use pip to install the Python dependencies defined in pyproject.toml +RUN pip3 install ./bindings/python + +# Set the entrypoint to bash for interactive sessions +CMD ["bash"] \ No newline at end of file diff --git a/README.md b/README.md index 609d8ba..4b816ea 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ The easiest way to get started is often using Docker and the interactive console 3. Run the container interactively ```bash - docker run -it --rm -p 8000:8000 --name ff_interactive forefire bash + docker run -it --rm -p 8000:8000 --name ff_interactive forefire ``` 4. Inside the container navigate to test directory and launch the forefire console: ```bash diff --git a/docs/source/getting_started/quickstart.rst b/docs/source/getting_started/quickstart.rst index ac5d2f3..6c57a13 100644 --- a/docs/source/getting_started/quickstart.rst +++ b/docs/source/getting_started/quickstart.rst @@ -34,7 +34,7 @@ Steps .. code-block:: bash - docker run -it --rm -p 8000:8000 --name ff_interactive forefire bash + docker run -it --rm -p 8000:8000 --name ff_interactive forefire 4. **Inside the container, navigate to the test directory:** diff --git a/tools/docker/Dockerfile.base b/tools/docker/Dockerfile.base new file mode 100644 index 0000000..6ca310c --- /dev/null +++ b/tools/docker/Dockerfile.base @@ -0,0 +1,22 @@ +FROM ubuntu:22.04 + +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + build-essential \ + libnetcdf-c++4-dev \ + cmake + +WORKDIR /forefire +ENV FOREFIREHOME=/forefire + +# we could only copy src, cmakelists.txt and cmake-build.sh +COPY . . + +# install forefire +RUN sh cmake-build.sh + +# add executable to PATH +RUN cp /forefire/bin/forefire /usr/local/bin/ + +# Set the entrypoint to bash for interactive sessions +CMD ["bash"] \ No newline at end of file diff --git a/tools/docker/Dockerfile.multistage b/tools/docker/Dockerfile.multistage new file mode 100644 index 0000000..8bfcc21 --- /dev/null +++ b/tools/docker/Dockerfile.multistage @@ -0,0 +1,60 @@ +# File: tools/Dockerfile.multistage +# Target: Creates an optimized, smaller final image using a multi-stage build. +# Contains full Python support. + +# --- STAGE 1: The "Builder" --- +# This stage is a temporary environment used to compile the C++ code. +# It contains all the heavy build tools, which will NOT be in the final image. +FROM ubuntu:22.04 AS builder + +# Install build tools and C++ dependencies +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + build-essential \ + libnetcdf-c++4-dev \ + cmake \ + git && \ + rm -rf /var/lib/apt/lists/* + +WORKDIR /src + +# Copy all source code into the builder stage +COPY . . + +# Build the C++ library and executable +RUN sh cmake-build.sh + + +# --- STAGE 2: The "Final Image" --- +# This is the final, clean image that will be distributed. +# It starts from a fresh Ubuntu base and only pulls in what's necessary. +FROM ubuntu:22.04 + +# Install only the RUNTIME dependencies needed for ForeFire and the Python bindings. +# As requested, we use libnetcdf-c++4-dev here for consistency with the build stage. +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + libnetcdf-c++4-dev \ + libgomp1 \ + python3 \ + g++ \ + python3-pip \ + python3-dev && \ + rm -rf /var/lib/apt/lists/* + +WORKDIR /forefire +ENV FOREFIREHOME=/forefire + +# The magic step: Copy the ENTIRE built project from the 'builder' stage. +# This brings over the compiled libs, binaries, and the source code needed for the bindings. +COPY --from=builder /src/ . + +# Add the forefire executable to the system's PATH +RUN cp /forefire/bin/forefire /usr/local/bin/ + +# Install the Python bindings and their dependencies (numpy, etc.) +# This compiles the C++ extension using the headers we just copied. +RUN pip3 install ./bindings/python + +# Set the default command to start a bash shell +CMD ["bash"] \ No newline at end of file diff --git a/tools/docker/readme.md b/tools/docker/readme.md new file mode 100644 index 0000000..8726ea1 --- /dev/null +++ b/tools/docker/readme.md @@ -0,0 +1,10 @@ +## Alternative Dockerfiles + +WIP + +- Dockerfile without python to make the image smaller +- Multistage build to make the also smaller (490 vs 620 mb) + +``` +docker build -f tools/docker/Dockerfile.multistage -t forefire:multistage . +``` \ No newline at end of file