|
7 | 7 | workflow_dispatch: |
8 | 8 |
|
9 | 9 | env: |
| 10 | + BUILD_SUFFIX: -build-${{ github.run_id }}_${{ github.run_attempt }} |
10 | 11 | DOCKER_METADATA_SET_OUTPUT_ENV: 'true' |
11 | 12 |
|
12 | 13 | jobs: |
@@ -35,38 +36,42 @@ jobs: |
35 | 36 | username: ${{ github.actor }} |
36 | 37 | password: ${{ secrets.GITHUB_TOKEN }} |
37 | 38 |
|
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 |
40 | 49 | uses: docker/metadata-action@v5 |
41 | 50 | with: |
42 | 51 | 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 }} |
47 | 53 |
|
48 | | - - name: Sanitize registry repository name |
49 | | - id: get-reg |
| 54 | + - id: get-registry |
| 55 | + name: Get the sanitized registry name |
50 | 56 | 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" |
52 | 58 |
|
53 | | - - name: Build/push the arch-specific image |
54 | | - id: build |
| 59 | + - id: build |
| 60 | + name: Build/push the arch-specific image |
55 | 61 | uses: docker/build-push-action@v6 |
56 | 62 | 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 }} |
61 | 66 | provenance: mode=max |
62 | 67 | sbom: true |
63 | | - tags: ${{ steps.get-reg.outputs.registry }} |
| 68 | + tags: ${{ steps.get-registry.outputs.registry }} |
64 | 69 | outputs: type=image,push-by-digest=true,push=true |
65 | 70 |
|
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 |
68 | 73 | 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" |
70 | 75 |
|
71 | 76 | merge: |
72 | 77 | runs-on: ubuntu-24.04 |
|
0 commit comments