Skip to content

Commit 6df9f43

Browse files
perf(ci): scope the Docker layer cache per image and platform
setup-docker-builder@v1 keys the sticky disk on the repository name alone, so all five images across amd64 and arm64 shared one disk. Parallel matrix jobs clone the same parent snapshot and only one commit per wave survives, which is why app.Dockerfile's deps stage rebuilt every run. Co-authored-by: Codesmith <codesmith-bot@users.noreply.github.com>
1 parent ccdb03d commit 6df9f43

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

.github/actions/docker-build/action.yml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,31 @@ inputs:
2525
runs:
2626
using: composite
2727
steps:
28+
# One sticky disk per Dockerfile per platform. setup-docker-builder@v1 keyed
29+
# the disk on the repository name alone, so all five images (x amd64/arm64)
30+
# shared a single disk. Every job in a matrix clones the same parent
31+
# snapshot and only one commit per wave becomes the next parent (in
32+
# practice the first job to finish, never the app build). Its `deps`
33+
# layer was written to the disk every run and discarded every run, so the
34+
# stage rebuilt from scratch (~300-465s) despite being provably cacheable.
35+
#
36+
# Platform is part of the key because build-amd64 and build-ghcr-arm64 build
37+
# the same Dockerfiles concurrently on main; a shared key would reproduce the
38+
# same clobbering between them, and the two share no layers anyway.
39+
- name: Resolve Docker layer cache key
40+
id: cache-key
41+
if: inputs.provider == '' || inputs.provider == 'blacksmith'
42+
shell: bash
43+
env:
44+
FILE: ${{ inputs.file }}
45+
PLATFORMS: ${{ inputs.platforms }}
46+
run: echo "value=${GITHUB_REPOSITORY##*/}/${FILE#./}/${PLATFORMS//\//-}" >> "$GITHUB_OUTPUT"
47+
2848
- name: Set up Blacksmith builder
2949
if: inputs.provider == '' || inputs.provider == 'blacksmith'
30-
uses: useblacksmith/setup-docker-builder@ab5c1da94f53f5cd75c1038092aa276dddfccbba # v1
50+
uses: useblacksmith/setup-docker-builder@a5256a73e30f09e37e3eceb8ca36043d17621d24 # v2
51+
with:
52+
cache-key: ${{ steps.cache-key.outputs.value }}
3153

3254
- name: Build and push (Blacksmith)
3355
if: inputs.provider == '' || inputs.provider == 'blacksmith'

0 commit comments

Comments
 (0)