From f84b67a2679b1ad4d9bca17c19e21abe23ebf2f0 Mon Sep 17 00:00:00 2001 From: Daniel Mohns Date: Tue, 22 Oct 2024 12:10:56 +0200 Subject: [PATCH] Use `matrix` in Github Actions --- .../workflows/release-publish-dockerhub.yaml | 62 +++++++------------ 1 file changed, 21 insertions(+), 41 deletions(-) diff --git a/.github/workflows/release-publish-dockerhub.yaml b/.github/workflows/release-publish-dockerhub.yaml index c34c62634..fe4745052 100644 --- a/.github/workflows/release-publish-dockerhub.yaml +++ b/.github/workflows/release-publish-dockerhub.yaml @@ -6,13 +6,21 @@ on: - published workflow_dispatch: -env: - IMAGE_NAME_FRONTEND: enaccess/micropowermanager-frontend - IMAGE_NAME_BACKEND: enaccess/micropowermanager-backend - jobs: release-publish: runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + image: + - repo: enaccess/micropowermanager-frontend + dockerfile: ./docker/DockerfileUIProd + - repo: enaccess/micropowermanager-backend + dockerfile: ./docker/DockerfileLaravelProd + platform: + - linux/amd64 + - linux/arm64 + permissions: contents: read id-token: write @@ -38,58 +46,30 @@ jobs: VERSION=$(cat version) echo "VERSION=$VERSION" >> $GITHUB_ENV - - name: Check if image tag already exists Frontend - run: | - VERSION="${{ env.VERSION }}" - if docker manifest inspect $IMAGE_NAME_FRONTEND:$VERSION > /dev/null 2>&1; then - echo "Docker image tag $VERSION already exists." - exit 1 - else - echo "Docker image tag $VERSION does not exist. Proceeding with build." - fi - - - name: Check if image tag already exists Backend + - name: Check if image tag already exists run: | VERSION="${{ env.VERSION }}" - if docker manifest inspect $IMAGE_NAME_BACKEND:$VERSION > /dev/null 2>&1; then + if docker manifest inspect ${{ matrix.image.repo }}:$VERSION > /dev/null 2>&1; then echo "Docker image tag $VERSION already exists." exit 1 else echo "Docker image tag $VERSION does not exist. Proceeding with build." fi - - name: Build and push Docker image Frontend + - name: Build and push Docker image uses: docker/build-push-action@v6 with: - file: ./docker/DockerfileUIProd - platforms: linux/amd64,linux/arm64 + file: ${{ matrix.image.dockerfile }} + platforms: ${{ matrix.platform }} push: true tags: | - ${{ env.IMAGE_NAME_FRONTEND }}:latest - ${{ env.IMAGE_NAME_FRONTEND }}:${{ env.VERSION }} - - - name: Build and push Docker image Backend - uses: docker/build-push-action@v5 - with: - file: ./docker/DockerfileLaravelProd - platforms: linux/amd64,linux/arm64 - push: true - tags: | - ${{ env.IMAGE_NAME_BACKEND }}:latest - ${{ env.IMAGE_NAME_BACKEND }}:${{ env.VERSION }} - - - name: Update Docker Hub Description Frontend - uses: peter-evans/dockerhub-description@v4 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - repository: ${{ env.IMAGE_NAME_FRONTEND }} - short-description: Open Source Management Tool for Decentralized Utilities + ${{ matrix.image.repo }}:latest + ${{ matrix.image.repo }}:${{ env.VERSION }} - - name: Update Docker Hub Description Backend + - name: Update Docker Hub Description uses: peter-evans/dockerhub-description@v4 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - repository: ${{ env.IMAGE_NAME_BACKEND }} + repository: ${{ matrix.image.repo }} short-description: Open Source Management Tool for Decentralized Utilities