Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduced the number of docker images by one pybamm:latest #3992

Merged
merged 12 commits into from
Apr 14, 2024
25 changes: 5 additions & 20 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@ jobs:
build_docker_images:
santacodes marked this conversation as resolved.
Show resolved Hide resolved
# This workflow is only of value to PyBaMM and would always be skipped in forks
if: github.repository_owner == 'pybamm-team'
name: Image (${{ matrix.build-args }})
name: Image
santacodes marked this conversation as resolved.
Show resolved Hide resolved
runs-on: ubuntu-latest
strategy:
matrix:
build-args: ["No solvers", "JAX", "IDAKLU", "ALL"]
fail-fast: true
arjxn-py marked this conversation as resolved.
Show resolved Hide resolved

steps:
- name: Checkout
Expand All @@ -33,22 +29,11 @@ jobs:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Create tags for Docker images based on build-time arguments
- name: Create latest tag for Docker image
id: tags
run: |
if [ "${{ matrix.build-args }}" = "No solvers" ]; then
echo "tag=latest" >> "$GITHUB_OUTPUT"
elif [ "${{ matrix.build-args }}" = "JAX" ]; then
echo "tag=jax" >> "$GITHUB_OUTPUT"
elif [ "${{ matrix.build-args }}" = "ODES" ]; then
echo "tag=odes" >> "$GITHUB_OUTPUT"
elif [ "${{ matrix.build-args }}" = "IDAKLU" ]; then
echo "tag=idaklu" >> "$GITHUB_OUTPUT"
elif [ "${{ matrix.build-args }}" = "ALL" ]; then
echo "tag=all" >> "$GITHUB_OUTPUT"
fi

- name: Build and push Docker image to Docker Hub (${{ matrix.build-args }})
run: echo "tag=latest" >> "$GITHUB_OUTPUT"

- name: Build and push Docker image to Docker Hub
santacodes marked this conversation as resolved.
Show resolved Hide resolved
uses: docker/build-push-action@v5
with:
santacodes marked this conversation as resolved.
Show resolved Hide resolved
context: .
Expand Down
97 changes: 6 additions & 91 deletions docs/source/user_guide/installation/install-from-docker.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,11 @@ Pulling the Docker image

Use the following command to pull the PyBaMM Docker image from Docker Hub:

.. tab:: No optional solver

.. code:: bash

docker pull pybamm/pybamm:latest

.. tab:: JAX solver

.. code:: bash

docker pull pybamm/pybamm:jax

.. tab:: IDAKLU solver

.. code:: bash

docker pull pybamm/pybamm:idaklu

.. tab:: All solvers
.. code:: bash

.. code:: bash
docker pull pybamm/pybamm:latest
arjxn-py marked this conversation as resolved.
Show resolved Hide resolved

docker pull pybamm/pybamm:all

Running the Docker container
----------------------------
Expand All @@ -51,35 +33,11 @@ Once you have pulled the Docker image, you can run a Docker container with the P

1. In your terminal, use the following command to start a Docker container from the pulled image:

.. tab:: Basic

.. code:: bash

docker run -it pybamm/pybamm:latest

.. tab:: ODES Solver

.. code:: bash

docker run -it pybamm/pybamm:odes

.. tab:: JAX Solver

.. code:: bash

docker run -it pybamm/pybamm:jax

.. tab:: IDAKLU Solver

.. code:: bash

docker run -it pybamm/pybamm:idaklu

.. tab:: All Solver
.. code:: bash

.. code:: bash
docker run -it pybamm/pybamm:latest
arjxn-py marked this conversation as resolved.
Show resolved Hide resolved

docker run -it pybamm/pybamm:all

2. You will now be inside the Docker container's shell. You can use PyBaMM and its dependencies as if you were in a virtual environment.

Expand Down Expand Up @@ -138,52 +96,9 @@ If you want to build the PyBaMM Docker image locally from the PyBaMM source code

conda activate pybamm

Building Docker images with optional arguments
----------------------------------------------

When building the PyBaMM Docker images locally, you have the option to include specific solvers by using optional arguments. These solvers include:

- ``IDAKLU``: For IDA solver provided by the SUNDIALS plus KLU.
- ``JAX``: For Jax solver.
- ``ALL``: For all the above solvers.

To build the Docker images with optional arguments, you can follow these steps for each solver:

.. tab:: JAX solver

.. code-block:: bash

docker build -t pybamm:jax -f scripts/Dockerfile --build-arg JAX=true .

.. tab:: IDAKLU solver

.. code-block:: bash

docker build -t pybamm:idaklu -f scripts/Dockerfile --build-arg IDAKLU=true .

.. tab:: All solvers

.. code-block:: bash

docker build -t pybamm:all -f scripts/Dockerfile --build-arg ALL=true .

After building the Docker images with the desired solvers, use the ``docker run`` command followed by the desired image name. For example, to run a container from the image built with all optional solvers:

.. code-block:: bash

docker run -it pybamm:all

Activate PyBaMM development environment inside docker container using:

.. code-block:: bash

conda activate pybamm

If you want to exit the Docker container's shell, you can simply type:

.. code-block:: bash
agriyakhetarpal marked this conversation as resolved.
Show resolved Hide resolved
.. note::

exit
PyBaMM Docker image comes with all the solvers by default. These solvers include ``IDAKLU`` IDA solver provided by the SUNDIALS plus KLU and ``JAX`` solver.
santacodes marked this conversation as resolved.
Show resolved Hide resolved


Using Git inside a running Docker container
Expand Down
27 changes: 2 additions & 25 deletions scripts/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,12 @@ RUN conda init --all
SHELL ["conda", "run", "-n", "pybamm", "/bin/bash", "-c"]
RUN conda install -y pip

ARG IDAKLU
ARG JAX
ARG ALL

RUN pip install --upgrade --user pip setuptools wheel wget
RUN pip install cmake

RUN if [ "$IDAKLU" = "true" ]; then \
python scripts/install_KLU_Sundials.py && \
rm -rf pybind11 && \
git clone https://github.com/pybind/pybind11.git && \
pip install --user -e ".[all,dev,docs]"; \
fi

RUN if [ "$JAX" = "true" ]; then \
pip install --user -e ".[all,dev,docs,jax]"; \
fi

RUN if [ "$ALL" = "true" ]; then \
python scripts/install_KLU_Sundials.py && \
RUN python scripts/install_KLU_Sundials.py && \
rm -rf pybind11 && \
git clone https://github.com/pybind/pybind11.git && \
pip install --user -e ".[all,dev,docs,jax]"; \
fi

RUN if [ -z "$IDAKLU" ] \
&& [ -z "$JAX" ] \
&& [ -z "$ALL" ]; then \
pip install --user -e ".[all,dev,docs]"; \
fi
pip install --user -e ".[all,dev,docs,jax]";

ENTRYPOINT ["/bin/bash"]
arjxn-py marked this conversation as resolved.
Show resolved Hide resolved
Loading