Skip to content

Commit 389c822

Browse files
authored
Merge pull request #628 from psantus/add-gha-cache
Add GitHub Actions cache support for Docker builds
2 parents a528782 + e3b7379 commit 389c822

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

.github/workflows/deploy-docker.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ jobs:
6363
php-version: 8.2
6464
coverage: none
6565

66+
- name: Set up Docker Buildx
67+
uses: docker/setup-buildx-action@v3
68+
6669
- name: Docker login
6770
run: echo '${{ secrets.DOCKER_PASSWORD }}' | docker login --username ${{ secrets.DOCKER_USERNAME }} --password-stdin
6871

Makefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,16 @@ layer ?= *
33
resolve_php_versions = $(or $(php_versions),`jq -r '.php | join(" ")' ${1}/config.json`)
44
resolve_tags = `./new-docker-tags.php $(DOCKER_TAG)`
55
BREF_VERSION = 3
6+
COMMA := ,
7+
CACHE_FLAGS = $(if $(GITHUB_ACTIONS),--cache-from type=gha --cache-to type=gha$(COMMA)mode=max,)
68
79
define build_docker_image
8-
docker build -t bref/${1}-php-${2} --build-arg PHP_VERSION=${2} --build-arg BREF_VERSION=${BREF_VERSION} ${DOCKER_BUILD_FLAGS} ${1}
10+
docker buildx build -t bref/${1}-php-${2} \
11+
--build-arg PHP_VERSION=${2} \
12+
--build-arg BREF_VERSION=${BREF_VERSION} \
13+
$(CACHE_FLAGS) \
14+
--load \
15+
${DOCKER_BUILD_FLAGS} ${1}
916
endef
1017
1118
docker-images:
@@ -31,7 +38,7 @@ test: docker-images
3138
echo "###############################################"; \
3239
echo "### Testing $${dir} PHP$${php_version}"; \
3340
echo "###"; \
34-
docker build --build-arg PHP_VERSION=$${php_version} --build-arg TARGET_IMAGE=$${dir}-php-$${php_version} -t bref/test-$${dir}-$${php_version} tests ; \
41+
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 ; \
3542
docker run --entrypoint= --rm -v $$(pwd)/$${dir}:/var/task bref/test-$${dir}-$${php_version} /opt/bin/php /var/task/test.php ; \
3643
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 ; \
3744
echo ""; \

0 commit comments

Comments
 (0)