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

Multi-architecture Docker images and parallel builds #3430

Merged
merged 11 commits into from
Oct 20, 2023
79 changes: 45 additions & 34 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build & Push Docker Images
name: Build and push Docker images to Docker Hub

on:
workflow_dispatch:
Expand All @@ -7,69 +7,80 @@ on:
- develop

jobs:
pre_job:
build_docker_images:
# 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 }})
agriyakhetarpal marked this conversation as resolved.
Show resolved Hide resolved
runs-on: ubuntu-latest
strategy:
matrix:
build-args: ["No solvers", "JAX", "ODES", "IDAKLU", "ALL"]
fail-fast: true

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to DockerHub
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: List built images
run: docker images

- name: Build and Push Docker Image (Without Solvers)
uses: docker/build-push-action@v5
with:
context: .
file: scripts/Dockerfile
tags: pybamm/pybamm:latest
push: true
- 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 (With JAX Solver)
- name: Build and push Docker image to Docker Hub (no solvers)
if: matrix.build-args == 'No solvers'
uses: docker/build-push-action@v5
with:
context: .
file: scripts/Dockerfile
tags: pybamm/pybamm:jax
tags: pybamm/pybamm:${{ steps.tags.outputs.tag }}
push: true
build-args: |
JAX=true
platforms: linux/amd64, linux/arm64

- name: Build and Push Docker Image (With ODES & DAE Solver)
- name: Build and push Docker image to Docker Hub (with ODES and IDAKLU solvers)
if: matrix.build-args == 'ODES' || matrix.build-args == 'IDAKLU'
uses: docker/build-push-action@v5
with:
context: .
file: scripts/Dockerfile
tags: pybamm/pybamm:odes
tags: pybamm/pybamm:${{ steps.tags.outputs.tag }}
push: true
build-args: |
ODES=true
build-args: ${{ matrix.build-args }}=true
platforms: linux/amd64, linux/arm64

- name: Build and Push Docker Image (With IDAKLU Solver)
- name: Build and push Docker image to Docker Hub (with ALL and JAX solvers)
if: matrix.build-args == 'ALL' || matrix.build-args == 'JAX'
uses: docker/build-push-action@v5
with:
context: .
file: scripts/Dockerfile
tags: pybamm/pybamm:idaklu
tags: pybamm/pybamm:${{ steps.tags.outputs.tag }}
push: true
build-args: |
IDAKLU=true
build-args: ${{ matrix.build-args }}=true
# exclude arm64 for JAX and ALL builds for now, see
# https://github.com/google/jax/issues/13608
platforms: linux/amd64

- name: Build and Push Docker Image (With All Solvers)
uses: docker/build-push-action@v5
with:
context: .
file: scripts/Dockerfile
tags: pybamm/pybamm:latest
push: true
build-args: |
ALL=true
- name: List built image(s)
run: docker images
Loading