From 338aa05c5f599961ccd5a6e9b29d81c99b7ae679 Mon Sep 17 00:00:00 2001 From: Danila Vershinin Date: Sat, 6 Jul 2024 11:46:59 +0500 Subject: [PATCH] Implement dynamic Docker build strategy A new strategy has been implemented for the Docker build using a matrix from a JSON file. This approach allows flexibility in defining the Docker image builds and pushes, as it moves their configuration into the separate JSON file. The configuration is read, set as an output for a new "config" job, and then used in the original build-and-push job. --- .github/workflows/docker-build.yml | 44 +++++++++++------------------- docker-matrix.json | 17 ++++++++++++ 2 files changed, 33 insertions(+), 28 deletions(-) create mode 100644 docker-matrix.json diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 0fd0278..7ec8a06 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -12,6 +12,10 @@ jobs: build-and-push: runs-on: ubuntu-latest + strategy: + matrix: + include: ${{ fromJson(needs.config.outputs.matrix) }} + steps: - name: Checkout code uses: actions/checkout@v2 @@ -25,39 +29,23 @@ jobs: username: ${{ secrets.DOCKER_HUB_USERNAME }} password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} - - name: Build and push Docker image for CentOS 7 - uses: docker/build-push-action@v4 - with: - context: . - platforms: linux/amd64,linux/arm64 - push: true - tags: | - getpagespeed/rhel:centos7-lts - getpagespeed/rhel:el7-lts - getpagespeed/rhel:latest # Adjust this if you want the latest to point to a specific version - file: ./Dockerfile.el7 - - - name: Build and push Docker image for CentOS 8 - uses: docker/build-push-action@v4 - with: - context: . - platforms: linux/amd64,linux/arm64 - push: true - tags: | - getpagespeed/rhel:centos8-lts - getpagespeed/rhel:el8-lts - file: ./Dockerfile.centos8 - - - name: Build and push Docker image for CentOS 9 + - name: Build and push Docker image uses: docker/build-push-action@v4 with: context: . platforms: linux/amd64,linux/arm64 push: true - tags: | - getpagespeed/rhel:centos9-lts - getpagespeed/rhel:el9-lts - file: ./Dockerfile.centos9 + tags: ${{ matrix.tags }} + file: ${{ matrix.file }} - name: Logout from Docker Hub run: docker logout + + config: + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.config.outputs.matrix }} + steps: + - name: Read configuration + id: config + run: echo "::set-output name=matrix::$(cat docker-matrix.json)" diff --git a/docker-matrix.json b/docker-matrix.json new file mode 100644 index 0000000..3d84dbc --- /dev/null +++ b/docker-matrix.json @@ -0,0 +1,17 @@ +[ + { + "name": "centos7-lts", + "file": "Dockerfile.centos7", + "tags": "getpagespeed/rhel:centos7-lts,getpagespeed/rhel:el7-lts" + }, + { + "name": "centos8-lts", + "file": "Dockerfile.centos8", + "tags": "getpagespeed/rhel:centos8-lts,getpagespeed/rhel:el8-lts" + }, + { + "name": "centos9-lts", + "file": "Dockerfile.centos9", + "tags": "getpagespeed/rhel:centos9-lts,getpagespeed/rhel:el9-lts" + } +]