Skip to content

Commit

Permalink
Implement dynamic Docker build strategy
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dvershinin committed Jul 6, 2024
1 parent 6b01561 commit 338aa05
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 28 deletions.
44 changes: 16 additions & 28 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)"
17 changes: 17 additions & 0 deletions docker-matrix.json
Original file line number Diff line number Diff line change
@@ -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"
}
]

0 comments on commit 338aa05

Please sign in to comment.