Skip to content

Commit dc76f55

Browse files
Switches to registry-based build caching (#12)
1 parent d8277d4 commit dc76f55

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

.github/workflows/build.yml

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
workflow_dispatch:
88

99
env:
10+
BUILD_SUFFIX: -build-${{ github.run_id }}_${{ github.run_attempt }}
1011
DOCKER_METADATA_SET_OUTPUT_ENV: 'true'
1112

1213
jobs:
@@ -35,38 +36,42 @@ jobs:
3536
username: ${{ github.actor }}
3637
password: ${{ secrets.GITHUB_TOKEN }}
3738

38-
- name: Docker meta
39-
id: meta
39+
- id: build-meta
40+
name: Docker meta
41+
uses: docker/metadata-action@v5
42+
with:
43+
images: ghcr.io/${{ github.repository }}
44+
tags: type=sha,suffix=${{ env.BUILD_SUFFIX }}
45+
46+
# Build cache is shared among all builds of the same architecture
47+
- id: cache-meta
48+
name: Docker meta
4049
uses: docker/metadata-action@v5
4150
with:
4251
images: ghcr.io/${{ github.repository }}
43-
# note Specifies a single tag to ensure the default doesn't add more than one.
44-
# The actual tag is not used, this is just used to sanitize the registry name
45-
# and produce labels.
46-
tags: type=sha
52+
tags: type=raw,value=buildcache-${{ runner.arch }}
4753

48-
- name: Sanitize registry repository name
49-
id: get-reg
54+
- id: get-registry
55+
name: Get the sanitized registry name
5056
run: |
51-
echo "registry=$(echo '${{ steps.meta.outputs.tags }}' | cut -f1 -d:)" | tee -a "$GITHUB_OUTPUT"
57+
echo "registry=$(echo '${{ steps.build-meta.outputs.tags }}' | cut -f1 -d:)" | tee -a "$GITHUB_OUTPUT"
5258
53-
- name: Build/push the arch-specific image
54-
id: build
59+
- id: build
60+
name: Build/push the arch-specific image
5561
uses: docker/build-push-action@v6
5662
with:
57-
# @todo GHA caching needs tuning, these tend not to hit. Perhaps switch to type=registry?
58-
cache-from: type=gha
59-
cache-to: type=gha,mode=max
60-
labels: ${{ steps.meta.outputs.labels }}
63+
cache-from: type=registry,ref=${{ steps.cache-meta.outputs.tags }}
64+
cache-to: type=registry,ref=${{ steps.cache-meta.outputs.tags }},mode=max
65+
labels: ${{ steps.build-meta.outputs.labels }}
6166
provenance: mode=max
6267
sbom: true
63-
tags: ${{ steps.get-reg.outputs.registry }}
68+
tags: ${{ steps.get-registry.outputs.registry }}
6469
outputs: type=image,push-by-digest=true,push=true
6570

66-
- name: Write arch-specific image digest to outputs
67-
id: gen-output
71+
- id: gen-output
72+
name: Write arch-specific image digest to outputs
6873
run: |
69-
echo "image-${RUNNER_ARCH,,}=${{ steps.get-reg.outputs.registry }}@${{ steps.build.outputs.digest }}" | tee -a "$GITHUB_OUTPUT"
74+
echo "image-${RUNNER_ARCH,,}=${{ steps.get-registry.outputs.registry }}@${{ steps.build.outputs.digest }}" | tee -a "$GITHUB_OUTPUT"
7075
7176
merge:
7277
runs-on: ubuntu-24.04

0 commit comments

Comments
 (0)