Skip to content

Commit 76b2a63

Browse files
committed
Add support for multi-architecture builds in Docker workflow
1 parent 470665e commit 76b2a63

2 files changed

Lines changed: 93 additions & 39 deletions

File tree

Lines changed: 50 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build and Push Docker Images
1+
name: Build and Push Multi-Architecture Docker Images
22

33
on:
44
push:
@@ -19,6 +19,11 @@ jobs:
1919
- name: Checkout code
2020
uses: actions/checkout@v3
2121

22+
- name: Set up QEMU
23+
uses: docker/setup-qemu-action@v2
24+
with:
25+
platforms: arm64,amd64
26+
2227
- name: Set up Docker Buildx
2328
uses: docker/setup-buildx-action@v2
2429

@@ -28,48 +33,52 @@ jobs:
2833
username: ${{ secrets.DOCKERHUB_USERNAME }}
2934
password: ${{ secrets.DOCKERHUB_TOKEN }}
3035

31-
# The PHP 7.x versions are commented out as they are legacy and should just remain as is.
32-
# - name: Build and push PHP 7.0
33-
# uses: docker/build-push-action@v4
34-
# with:
35-
# context: .
36-
# push: true
37-
# build-args: |
38-
# PHP_VERSION=php7.0-apache
39-
# tags: pattonwebz/local-wordpress-with-xdebug:php7.0-apache
40-
#
41-
# - name: Build and push PHP 7.1
42-
# uses: docker/build-push-action@v4
43-
# with:
44-
# context: .
45-
# push: true
46-
# build-args: |
47-
# PHP_VERSION=php7.1-apache
48-
# tags: pattonwebz/local-wordpress-with-xdebug:php7.1-apache
49-
#
50-
# - name: Build and push PHP 7.2
51-
# uses: docker/build-push-action@v4
52-
# with:
53-
# context: .
54-
# push: true
55-
# build-args: |
56-
# PHP_VERSION=php7.2-apache
57-
# tags: pattonwebz/local-wordpress-with-xdebug:php7.2-apache
58-
#
59-
# - name: Build and push PHP 7.4
60-
# uses: docker/build-push-action@v4
61-
# with:
62-
# context: .
63-
# push: true
64-
# build-args: |
65-
# PHP_VERSION=php7.4-apache
66-
# tags: pattonwebz/local-wordpress-with-xdebug:php7.4-apache
36+
- name: Build and push PHP 7.0
37+
uses: docker/build-push-action@v4
38+
with:
39+
context: .
40+
push: true
41+
platforms: linux/amd64,linux/arm64
42+
build-args: |
43+
PHP_VERSION=php7.0-apache
44+
tags: pattonwebz/local-wordpress-with-xdebug:php7.0-apache
45+
46+
- name: Build and push PHP 7.1
47+
uses: docker/build-push-action@v4
48+
with:
49+
context: .
50+
push: true
51+
platforms: linux/amd64,linux/arm64
52+
build-args: |
53+
PHP_VERSION=php7.1-apache
54+
tags: pattonwebz/local-wordpress-with-xdebug:php7.1-apache
55+
56+
- name: Build and push PHP 7.2
57+
uses: docker/build-push-action@v4
58+
with:
59+
context: .
60+
push: true
61+
platforms: linux/amd64,linux/arm64
62+
build-args: |
63+
PHP_VERSION=php7.2-apache
64+
tags: pattonwebz/local-wordpress-with-xdebug:php7.2-apache
65+
66+
- name: Build and push PHP 7.4
67+
uses: docker/build-push-action@v4
68+
with:
69+
context: .
70+
push: true
71+
platforms: linux/amd64,linux/arm64
72+
build-args: |
73+
PHP_VERSION=php7.4-apache
74+
tags: pattonwebz/local-wordpress-with-xdebug:php7.4-apache
6775

6876
- name: Build and push PHP 8.0
6977
uses: docker/build-push-action@v4
7078
with:
7179
context: .
7280
push: true
81+
platforms: linux/amd64,linux/arm64
7382
build-args: |
7483
PHP_VERSION=php8.0-apache
7584
tags: pattonwebz/local-wordpress-with-xdebug:php8.0-apache
@@ -79,6 +88,7 @@ jobs:
7988
with:
8089
context: .
8190
push: true
91+
platforms: linux/amd64,linux/arm64
8292
build-args: |
8393
PHP_VERSION=php8.1-apache
8494
tags: pattonwebz/local-wordpress-with-xdebug:php8.1-apache
@@ -88,6 +98,7 @@ jobs:
8898
with:
8999
context: .
90100
push: true
101+
platforms: linux/amd64,linux/arm64
91102
build-args: |
92103
PHP_VERSION=php8.2-apache
93104
tags: |
@@ -99,6 +110,7 @@ jobs:
99110
with:
100111
context: .
101112
push: true
113+
platforms: linux/amd64,linux/arm64
102114
build-args: |
103115
PHP_VERSION=php8.3-apache
104116
tags: pattonwebz/local-wordpress-with-xdebug:php8.3-apache
@@ -108,6 +120,7 @@ jobs:
108120
with:
109121
context: .
110122
push: true
123+
platforms: linux/amd64,linux/arm64
111124
build-args: |
112125
PHP_VERSION=php8.4-apache
113126
tags: pattonwebz/local-wordpress-with-xdebug:php8.4-apache

build.sh

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,56 @@ PHP_VERSIONS=("7.0" "7.1" "7.2" "7.4" "8.0" "8.1" "8.2" "8.3" "8.4")
66
# Base image name
77
IMAGE_NAME="pattonwebz/local-wordpress-with-xdebug"
88

9+
# Check if --multi-arch flag is passed
10+
MULTI_ARCH=false
11+
PUSH_IMAGES=false
12+
13+
for arg in "$@"; do
14+
if [ "$arg" == "--multi-arch" ]; then
15+
MULTI_ARCH=true
16+
elif [ "$arg" == "--push" ]; then
17+
PUSH_IMAGES=true
18+
fi
19+
done
20+
21+
# Set up buildx if multi-arch is requested
22+
if [ "$MULTI_ARCH" = true ]; then
23+
echo "Setting up Docker Buildx for multi-architecture builds..."
24+
docker buildx create --name multiarch --use 2>/dev/null || docker buildx use multiarch
25+
docker buildx inspect --bootstrap
26+
27+
PLATFORMS="linux/amd64,linux/arm64"
28+
BUILDX_CMD="buildx build --platform $PLATFORMS"
29+
30+
if [ "$PUSH_IMAGES" = true ]; then
31+
BUILDX_CMD="$BUILDX_CMD --push"
32+
else
33+
BUILDX_CMD="$BUILDX_CMD --load"
34+
fi
35+
else
36+
BUILDX_CMD="build"
37+
fi
38+
39+
echo "Build command: docker $BUILDX_CMD"
40+
941
# Build for all versions
1042
for version in "${PHP_VERSIONS[@]}"; do
1143
echo "Building image for PHP $version..."
12-
docker build --build-arg PHP_VERSION="php${version}-apache" -t "${IMAGE_NAME}:php${version}-apache" .
44+
45+
if [ "$MULTI_ARCH" = true ]; then
46+
docker $BUILDX_CMD --build-arg PHP_VERSION="php${version}-apache" -t "${IMAGE_NAME}:php${version}-apache" .
47+
else
48+
docker build --build-arg PHP_VERSION="php${version}-apache" -t "${IMAGE_NAME}:php${version}-apache" .
49+
fi
1350

1451
# Tag latest for the newest stable version (currently 8.2)
15-
if [ "$version" = "8.2" ]; then
52+
if [ "$version" = "8.2" ] && [ "$MULTI_ARCH" = false ]; then
1653
docker tag $IMAGE_NAME:"php${version}-apache" $IMAGE_NAME:latest
1754
echo "Tagged PHP $version as latest"
55+
elif [ "$version" = "8.2" ] && [ "$MULTI_ARCH" = true ] && [ "$PUSH_IMAGES" = true ]; then
56+
# For multi-arch with push, need to create the latest tag with buildx
57+
docker $BUILDX_CMD --build-arg PHP_VERSION="php${version}-apache" -t "${IMAGE_NAME}:latest" .
58+
echo "Tagged PHP $version as latest"
1859
fi
1960
done
2061

0 commit comments

Comments
 (0)