From 0284a71d02b1f795061933f36aacb202eae72b27 Mon Sep 17 00:00:00 2001 From: Paul Santus Date: Fri, 27 Feb 2026 10:26:26 +0100 Subject: [PATCH 1/2] Add GitHub Actions cache support for Docker builds - Add Docker Buildx setup to workflow - Use GHA cache for docker builds to speed up CI - Cache is shared across all layers and PHP versions for maximum reuse - Conditional cache flags only apply in GitHub Actions, works locally without cache --- .github/workflows/deploy-docker.yml | 3 +++ Makefile | 11 +++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-docker.yml b/.github/workflows/deploy-docker.yml index 24458966..0d3aaf0c 100644 --- a/.github/workflows/deploy-docker.yml +++ b/.github/workflows/deploy-docker.yml @@ -63,6 +63,9 @@ jobs: php-version: 8.2 coverage: none + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Docker login run: echo '${{ secrets.DOCKER_PASSWORD }}' | docker login --username ${{ secrets.DOCKER_USERNAME }} --password-stdin diff --git a/Makefile b/Makefile index bbe2a7ee..6a9abf6a 100644 --- a/Makefile +++ b/Makefile @@ -3,9 +3,16 @@ layer ?= * resolve_php_versions = $(or $(php_versions),`jq -r '.php | join(" ")' ${1}/config.json`) resolve_tags = `./new-docker-tags.php $(DOCKER_TAG)` BREF_VERSION = 3 +COMMA := , +CACHE_FLAGS = $(if $(GITHUB_ACTIONS),--cache-from type=gha --cache-to type=gha$(COMMA)mode=max,) define build_docker_image - docker build -t bref/${1}-php-${2} --build-arg PHP_VERSION=${2} --build-arg BREF_VERSION=${BREF_VERSION} ${DOCKER_BUILD_FLAGS} ${1} + docker buildx build -t bref/${1}-php-${2} \ + --build-arg PHP_VERSION=${2} \ + --build-arg BREF_VERSION=${BREF_VERSION} \ + $(CACHE_FLAGS) \ + --load \ + ${DOCKER_BUILD_FLAGS} ${1} endef docker-images: @@ -31,7 +38,7 @@ test: docker-images echo "###############################################"; \ echo "### Testing $${dir} PHP$${php_version}"; \ echo "###"; \ - docker build --build-arg PHP_VERSION=$${php_version} --build-arg TARGET_IMAGE=$${dir}-php-$${php_version} -t bref/test-$${dir}-$${php_version} tests ; \ + docker buildx build --build-arg PHP_VERSION=$${php_version} --build-arg TARGET_IMAGE=$${dir}-php-$${php_version} -t bref/test-$${dir}-$${php_version} $(CACHE_FLAGS) --load tests ; \ docker run --entrypoint= --rm -v $$(pwd)/$${dir}:/var/task bref/test-$${dir}-$${php_version} /opt/bin/php /var/task/test.php ; \ if docker run --entrypoint= --rm -v $$(pwd)/$${dir}:/var/task bref/test-$${dir}-$${php_version} /opt/bin/php -v 2>&1 >/dev/null | grep -q 'Unable\|Warning'; then exit 1; fi ; \ echo ""; \ From 093075491df56f4df60d2e66b7f038f7b5dcee43 Mon Sep 17 00:00:00 2001 From: Paul Santus Date: Tue, 3 Mar 2026 12:16:49 +0100 Subject: [PATCH 2/2] Fix image naming for docker buildx compatibility The notdir function strips the 'layers/' prefix from the directory path, ensuring the image is tagged as 'bref/sqlsrv-php-82' instead of 'bref/layers/sqlsrv-php-82', which matches what the test Dockerfile expects. --- Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 6a9abf6a..8a44ffe5 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ COMMA := , CACHE_FLAGS = $(if $(GITHUB_ACTIONS),--cache-from type=gha --cache-to type=gha$(COMMA)mode=max,) define build_docker_image - docker buildx build -t bref/${1}-php-${2} \ + docker buildx build -t bref/$(notdir ${1})-php-${2} \ --build-arg PHP_VERSION=${2} \ --build-arg BREF_VERSION=${BREF_VERSION} \ $(CACHE_FLAGS) \ @@ -38,9 +38,9 @@ test: docker-images echo "###############################################"; \ echo "### Testing $${dir} PHP$${php_version}"; \ echo "###"; \ - docker buildx build --build-arg PHP_VERSION=$${php_version} --build-arg TARGET_IMAGE=$${dir}-php-$${php_version} -t bref/test-$${dir}-$${php_version} $(CACHE_FLAGS) --load tests ; \ - docker run --entrypoint= --rm -v $$(pwd)/$${dir}:/var/task bref/test-$${dir}-$${php_version} /opt/bin/php /var/task/test.php ; \ - if docker run --entrypoint= --rm -v $$(pwd)/$${dir}:/var/task bref/test-$${dir}-$${php_version} /opt/bin/php -v 2>&1 >/dev/null | grep -q 'Unable\|Warning'; then exit 1; fi ; \ + docker buildx build --build-arg PHP_VERSION=$${php_version} --build-arg TARGET_IMAGE=$$(basename $${dir})-php-$${php_version} -t bref/test-$$(basename $${dir})-$${php_version} $(CACHE_FLAGS) --load tests ; \ + docker run --entrypoint= --rm -v $$(pwd)/$${dir}:/var/task bref/test-$$(basename $${dir})-$${php_version} /opt/bin/php /var/task/test.php ; \ + if docker run --entrypoint= --rm -v $$(pwd)/$${dir}:/var/task bref/test-$$(basename $${dir})-$${php_version} /opt/bin/php -v 2>&1 >/dev/null | grep -q 'Unable\|Warning'; then exit 1; fi ; \ echo ""; \ echo " - Test passed"; \ echo ""; \