From 6f9ce65ddb19f1e478675ade300c4b3d4f01031f Mon Sep 17 00:00:00 2001 From: "arjxn.py" Date: Sun, 24 Dec 2023 23:03:10 +0530 Subject: [PATCH 1/6] Build & Push Docker Images on release --- .github/workflows/docker.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index f92ee76c9e..23bc69fcf6 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -5,6 +5,8 @@ on: push: branches: - develop + release: + types: [published] jobs: build_docker_images: From 3cd65731626389e8aff83770322afde490ab7e31 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Thu, 28 Dec 2023 20:10:53 +0530 Subject: [PATCH 2/6] #3312 initial setup, configure release tags via name --- .github/workflows/docker.yml | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 23bc69fcf6..20b111dae7 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -36,6 +36,7 @@ jobs: password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Create tags for Docker images based on build-time arguments + if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' && github.event_name != 'release' id: tags run: | if [ "${{ matrix.build-args }}" = "No solvers" ]; then @@ -50,7 +51,24 @@ jobs: echo "tag=all" >> "$GITHUB_OUTPUT" fi + - name: Create tags for Docker images based on build-time arguments (release) + if: github.event_name == 'release' && github.event.action == 'published' + id: tags-release + run: | + if [ "${{ matrix.build-args }}" = "No solvers" ]; then + echo "tag=${{ github.event.release.name }}-latest" >> "$GITHUB_OUTPUT" + elif [ "${{ matrix.build-args }}" = "JAX" ]; then + echo "tag=${{ github.event.release.name }}-jax" >> "$GITHUB_OUTPUT" + elif [ "${{ matrix.build-args }}" = "ODES" ]; then + echo "tag=${{ github.event.release.name }}-odes" >> "$GITHUB_OUTPUT" + elif [ "${{ matrix.build-args }}" = "IDAKLU" ]; then + echo "tag=${{ github.event.release.name }}-idaklu" >> "$GITHUB_OUTPUT" + elif [ "${{ matrix.build-args }}" = "ALL" ]; then + echo "tag=${{ github.event.release.name }}-all" >> "$GITHUB_OUTPUT" + fi + - name: Build and push Docker image to Docker Hub (${{ matrix.build-args }}) + if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' && github.event_name != 'release' uses: docker/build-push-action@v5 with: context: . @@ -59,5 +77,12 @@ jobs: push: true platforms: linux/amd64, linux/arm64 - - name: List built image(s) - run: docker images + - name: Build and push Docker image to Docker Hub (${{ matrix.build-args}}) (Release) + if: github.event_name == 'release' && github.event.action == 'published' + uses: docker/build-push-action@v5 + with: + context: . + file: scripts/Dockerfile + tags: pybamm/pybamm:${{ steps.tags-release.outputs.tag }} + push: true + platforms: linux/amd64, linux/arm64 From 83fda1995b0463d6196056eb90c6430c0ee21c06 Mon Sep 17 00:00:00 2001 From: "arjxn.py" Date: Fri, 29 Dec 2023 00:14:39 +0530 Subject: [PATCH 3/6] Temporary changes to test tag generation --- .github/workflows/docker.yml | 176 +++++++++++++++++------------------ 1 file changed, 88 insertions(+), 88 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 20b111dae7..416728cf55 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -1,88 +1,88 @@ -name: Build and push Docker images to Docker Hub - -on: - workflow_dispatch: - push: - branches: - - develop - release: - types: [published] - -jobs: - 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 }}) - 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 Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Create tags for Docker images based on build-time arguments - if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' && github.event_name != 'release' - 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: Create tags for Docker images based on build-time arguments (release) - if: github.event_name == 'release' && github.event.action == 'published' - id: tags-release - run: | - if [ "${{ matrix.build-args }}" = "No solvers" ]; then - echo "tag=${{ github.event.release.name }}-latest" >> "$GITHUB_OUTPUT" - elif [ "${{ matrix.build-args }}" = "JAX" ]; then - echo "tag=${{ github.event.release.name }}-jax" >> "$GITHUB_OUTPUT" - elif [ "${{ matrix.build-args }}" = "ODES" ]; then - echo "tag=${{ github.event.release.name }}-odes" >> "$GITHUB_OUTPUT" - elif [ "${{ matrix.build-args }}" = "IDAKLU" ]; then - echo "tag=${{ github.event.release.name }}-idaklu" >> "$GITHUB_OUTPUT" - elif [ "${{ matrix.build-args }}" = "ALL" ]; then - echo "tag=${{ github.event.release.name }}-all" >> "$GITHUB_OUTPUT" - fi - - - name: Build and push Docker image to Docker Hub (${{ matrix.build-args }}) - if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' && github.event_name != 'release' - uses: docker/build-push-action@v5 - with: - context: . - file: scripts/Dockerfile - tags: pybamm/pybamm:${{ steps.tags.outputs.tag }} - push: true - platforms: linux/amd64, linux/arm64 - - - name: Build and push Docker image to Docker Hub (${{ matrix.build-args}}) (Release) - if: github.event_name == 'release' && github.event.action == 'published' - uses: docker/build-push-action@v5 - with: - context: . - file: scripts/Dockerfile - tags: pybamm/pybamm:${{ steps.tags-release.outputs.tag }} - push: true - platforms: linux/amd64, linux/arm64 +name: Build and push Docker images to Docker Hub + +on: + workflow_dispatch: + push: + branches: + - develop + release: + types: [published] + +jobs: + 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 }}) + 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 Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Create tags for Docker images based on build-time arguments + if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' && github.event_name != 'release' + 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: Create tags for Docker images based on build-time arguments (release) + if: github.event_name == 'release' && github.event.action == 'published' + id: tags-release + run: | + if [ "${{ matrix.build-args }}" = "No solvers" ]; then + echo "tag=${{ github.event.release.name }}-latest" >> "$GITHUB_OUTPUT" + elif [ "${{ matrix.build-args }}" = "JAX" ]; then + echo "tag=${{ github.event.release.name }}-jax" >> "$GITHUB_OUTPUT" + elif [ "${{ matrix.build-args }}" = "ODES" ]; then + echo "tag=${{ github.event.release.name }}-odes" >> "$GITHUB_OUTPUT" + elif [ "${{ matrix.build-args }}" = "IDAKLU" ]; then + echo "tag=${{ github.event.release.name }}-idaklu" >> "$GITHUB_OUTPUT" + elif [ "${{ matrix.build-args }}" = "ALL" ]; then + echo "tag=${{ github.event.release.name }}-all" >> "$GITHUB_OUTPUT" + fi + + - name: Build and push Docker image to Docker Hub (${{ matrix.build-args }}) + if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' && github.event_name != 'release' + uses: docker/build-push-action@v5 + with: + context: . + file: scripts/Dockerfile + tags: pybamm/pybamm:${{ steps.tags.outputs.tag }} + push: true + platforms: linux/amd64, linux/arm64 + + - name: Build and push Docker image to Docker Hub (${{ matrix.build-args}}) (Release) + if: github.event_name == 'release' && github.event.action == 'published' + uses: docker/build-push-action@v5 + with: + context: . + file: scripts/Dockerfile + tags: pybamm/pybamm:${{ steps.tags-release.outputs.tag }} + push: false + platforms: linux/amd64, linux/arm64 From a269e9b897d17d15ff12fc76eec7f214f6687844 Mon Sep 17 00:00:00 2001 From: "arjxn.py" Date: Fri, 29 Dec 2023 00:28:52 +0530 Subject: [PATCH 4/6] Skip login step temporarily --- .github/workflows/docker.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 416728cf55..6e43e17168 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -29,11 +29,11 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - name: Login to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} + # - name: Login to Docker Hub + # uses: docker/login-action@v3 + # with: + # username: ${{ secrets.DOCKERHUB_USERNAME }} + # password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Create tags for Docker images based on build-time arguments if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' && github.event_name != 'release' From 5b8b83df354203de69973e2f488ffeb4103efe64 Mon Sep 17 00:00:00 2001 From: "arjxn.py" Date: Fri, 29 Dec 2023 00:55:36 +0530 Subject: [PATCH 5/6] Try using `github.ref_name` instead --- .github/workflows/docker.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 6e43e17168..175673bd9c 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -56,15 +56,15 @@ jobs: id: tags-release run: | if [ "${{ matrix.build-args }}" = "No solvers" ]; then - echo "tag=${{ github.event.release.name }}-latest" >> "$GITHUB_OUTPUT" + echo "tag=${{ github.ref_name }}-latest" >> "$GITHUB_OUTPUT" elif [ "${{ matrix.build-args }}" = "JAX" ]; then - echo "tag=${{ github.event.release.name }}-jax" >> "$GITHUB_OUTPUT" + echo "tag=${{ github.ref_name }}-jax" >> "$GITHUB_OUTPUT" elif [ "${{ matrix.build-args }}" = "ODES" ]; then - echo "tag=${{ github.event.release.name }}-odes" >> "$GITHUB_OUTPUT" + echo "tag=${{ github.ref_name }}-odes" >> "$GITHUB_OUTPUT" elif [ "${{ matrix.build-args }}" = "IDAKLU" ]; then - echo "tag=${{ github.event.release.name }}-idaklu" >> "$GITHUB_OUTPUT" + echo "tag=${{ github.ref_name }}-idaklu" >> "$GITHUB_OUTPUT" elif [ "${{ matrix.build-args }}" = "ALL" ]; then - echo "tag=${{ github.event.release.name }}-all" >> "$GITHUB_OUTPUT" + echo "tag=${{ github.ref_name }}-all" >> "$GITHUB_OUTPUT" fi - name: Build and push Docker image to Docker Hub (${{ matrix.build-args }}) From bc0fa0bb1adf4071e3dcf0e9bf753e72b4e091fe Mon Sep 17 00:00:00 2001 From: "arjxn.py" Date: Fri, 29 Dec 2023 19:36:39 +0530 Subject: [PATCH 6/6] Revert temporary changes --- .github/workflows/docker.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 175673bd9c..d90dcddd62 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -11,7 +11,7 @@ on: jobs: build_docker_images: # This workflow is only of value to PyBaMM and would always be skipped in forks - # if: github.repository_owner == 'pybamm-team' + if: github.repository_owner == 'pybamm-team' name: Image (${{ matrix.build-args }}) runs-on: ubuntu-latest strategy: @@ -29,11 +29,11 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - # - name: Login to Docker Hub - # uses: docker/login-action@v3 - # with: - # username: ${{ secrets.DOCKERHUB_USERNAME }} - # password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Create tags for Docker images based on build-time arguments if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' && github.event_name != 'release' @@ -84,5 +84,5 @@ jobs: context: . file: scripts/Dockerfile tags: pybamm/pybamm:${{ steps.tags-release.outputs.tag }} - push: false + push: true platforms: linux/amd64, linux/arm64