From ff8df08f3d97a48121955bc079a917ab7f32e3aa Mon Sep 17 00:00:00 2001 From: Santhosh <52504160+santacodes@users.noreply.github.com> Date: Sun, 14 Apr 2024 12:12:53 +0530 Subject: [PATCH] Reduced the number of docker images by one `pybamm:latest` (#3992) * reduced the image to one * removed build time args and multiple image builds * removed optional solvers from docker docs * Apply suggestions from code review Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> * code review suggestions * added breaking change to changelog.md * Update CHANGELOG.md * Apply suggestions from code review --------- Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Co-authored-by: Arjun Verma --- .github/workflows/docker.yml | 27 +----- CHANGELOG.md | 1 + .../installation/install-from-docker.rst | 97 ++----------------- scripts/Dockerfile | 27 +----- 4 files changed, 13 insertions(+), 139 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index d51231d972..6e60454586 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -7,15 +7,11 @@ on: - develop jobs: - build_docker_images: + build_docker_image: # 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: Build image runs-on: ubuntu-latest - strategy: - matrix: - build-args: ["No solvers", "JAX", "IDAKLU", "ALL"] - fail-fast: true steps: - name: Checkout @@ -33,27 +29,12 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Create tags for Docker images based on build-time arguments - 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 }}) + - name: Build and push Docker image to Docker Hub uses: docker/build-push-action@v5 with: context: . file: scripts/Dockerfile - tags: pybamm/pybamm:${{ steps.tags.outputs.tag }} + tags: pybamm/pybamm:latest push: true platforms: linux/amd64, linux/arm64 diff --git a/CHANGELOG.md b/CHANGELOG.md index ed35e49ddb..c3ac2a1a78 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ ## Breaking changes +- Removed multiple Docker images. Here on, a single Docker image tagged `pybamm/pybamm:latest` will be provided with both solvers (`IDAKLU` and `JAX`) pre-installed. ([#3992](https://github.com/pybamm-team/PyBaMM/pull/3992)) - Removed support for Python 3.8 ([#3961](https://github.com/pybamm-team/PyBaMM/pull/3961)) - Renamed "ocp_soc_0_dimensional" to "ocp_soc_0" and "ocp_soc_100_dimensional" to "ocp_soc_100" ([#3942](https://github.com/pybamm-team/PyBaMM/pull/3942)) - The ODES solver was removed due to compatibility issues. Users should use IDAKLU, Casadi, or JAX instead. ([#3932](https://github.com/pybamm-team/PyBaMM/pull/3932)) diff --git a/docs/source/user_guide/installation/install-from-docker.rst b/docs/source/user_guide/installation/install-from-docker.rst index 6660fad08c..69b68f942b 100644 --- a/docs/source/user_guide/installation/install-from-docker.rst +++ b/docs/source/user_guide/installation/install-from-docker.rst @@ -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 - docker pull pybamm/pybamm:all Running the Docker container ---------------------------- @@ -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 - 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. @@ -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 +.. note:: - exit + PyBaMM's Docker image comes with all available solvers by default. These solvers include ``IDAKLU`` IDAS solver provided by the SUNDIALS linked with SuiteSparse's KLU and the ``JAX`` solver. Using Git Inside a Running Docker Container diff --git a/scripts/Dockerfile b/scripts/Dockerfile index 152c8f01d9..4f83b20ba1 100644 --- a/scripts/Dockerfile +++ b/scripts/Dockerfile @@ -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"]