Skip to content

Commit f6a20ba

Browse files
authored
fix(docker): input cache map (#1653)
1 parent 73f7c60 commit f6a20ba

5 files changed

Lines changed: 56 additions & 11 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"build-push-docker": patch
3+
---
4+
5+
Fix cache-map input description: recommend the object form with an explicit id
6+
matching the Dockerfile cache mount id. The simple string form omits id, so
7+
BuildKit keys the cache on the target path and never matches mounts that
8+
define an explicit id.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"reusable-docker-build-publish": minor
3+
---
4+
5+
Add `docker-cache-map` input, passed through to build-push-docker's `cache-map`.
6+
Set it to restrict buildkit-cache-dance to specific cache mounts (e.g.
7+
`'{"cache-mount/go-build-cache": {"id": "go-build-cache", "target": "/var/cache-target"}}'`)
8+
instead of auto-discovering all cache mounts in the Dockerfile. Omit to keep
9+
auto-discovery.

‎.github/workflows/reusable-docker-build-publish.yml‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,17 @@ on:
150150
required: false
151151
type: string
152152
default: "write-on-trunk"
153+
docker-cache-map:
154+
description: |
155+
JSON string mapping cache mount paths/names for buildkit-cache-dance, passed
156+
through to build-push-docker's cache-map. Use the object form with an explicit
157+
id matching the Dockerfile's cache mount id, e.g.
158+
'{"cache-mount/go-build-cache": {"id": "go-build-cache", "target": "/var/cache-target"}}'.
159+
Restricts cache-dance to only the listed mounts; if omitted, all cache mounts
160+
are discovered from the Dockerfile.
161+
required: false
162+
type: string
163+
default: ""
153164
docker-build-context:
154165
description: "Path to Docker build context."
155166
required: true
@@ -437,7 +448,7 @@ jobs:
437448
docker-build-cache-from: ${{ steps.should-cache.outputs.docker-build-cache-from }}
438449
docker-cache-suffix: ${{ steps.should-cache.outputs.docker-cache-suffix }}
439450
steps:
440-
- uses: actions/checkout@v6
451+
- uses: actions/checkout@v7
441452
with:
442453
persist-credentials: false
443454
fetch-depth: 1
@@ -616,9 +627,9 @@ jobs:
616627
uses: smartcontractkit/.github/actions/free-disk-space@free-disk-space/v1
617628

618629
- name: Enable S3 Cache for Self-Hosted Runners
619-
uses: runs-on/action@4e5f72399b6b17f2e79c511c1b38a315a64d22dc # v2.2.0
630+
uses: runs-on/action@efac073ea2507ec18797de3a81704201ade11d9d # v2.3.1
620631

621-
- uses: actions/checkout@v6
632+
- uses: actions/checkout@v7
622633
id: checkout
623634
with:
624635
persist-credentials: false
@@ -780,6 +791,7 @@ jobs:
780791
docker-save-cache: ${{ needs.init.outputs.docker-save-cache }}
781792
docker-build-cache-to: ${{ needs.init.outputs.docker-build-cache-to }},scope=${{ steps.compute-cache-scope.outputs.scope }}
782793
docker-build-cache-from: ${{ needs.init.outputs.docker-build-cache-from }},scope=${{ steps.compute-cache-scope.outputs.scope }}
794+
cache-map: ${{ inputs.docker-cache-map }}
783795
context: ${{ inputs.docker-build-context }}
784796
docker-build-contexts: ${{ inputs.docker-build-contexts }}
785797
docker-push: ${{ inputs.docker-push }}

‎actions/build-push-docker/action.yml‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,11 @@ inputs:
125125
default: "auto"
126126
cache-map:
127127
description: |
128-
JSON string mapping cache mount paths/names for buildkit-cache-dance (e.g. '{"go-mod-cache": "/go/pkg/mod"}').
128+
JSON string mapping cache mount paths/names for buildkit-cache-dance.
129+
Use the object form with an explicit id matching the Dockerfile's cache mount id
130+
(e.g. '{"cache-mount/go-build-cache": {"id": "go-build-cache", "target": "/var/cache-target"}}').
131+
The simple string form omits id; BuildKit then keys the cache on the target path,
132+
which will not match mounts that define an explicit id.
129133
If omitted, buildkit-cache-dance automatically discovers mounts from the Dockerfile.
130134
See: https://github.com/reproducible-containers/buildkit-cache-dance
131135
See: https://docs.docker.com/build/ci/github-actions/cache/#cache-mounts
@@ -223,7 +227,7 @@ runs:
223227
if:
224228
${{ steps.dockerfile-ecr-parse.outputs.needs-ecr-login == 'true' ||
225229
inputs.docker-push == 'true' }}
226-
uses: aws-actions/configure-aws-credentials@e6de054238d6b7531b4efff3b6587d9aade6a06c # v6.2.3
230+
uses: aws-actions/configure-aws-credentials@cbe3b392738ccf3f987d68400dafcf4b0624a56c # v6.2.4
227231
with:
228232
role-to-assume: ${{ inputs.aws-role-arn }}
229233
role-duration-seconds: 900
@@ -232,14 +236,14 @@ runs:
232236

233237
- name: Login to private ECR registries for base images
234238
if: ${{ steps.dockerfile-ecr-parse.outputs.needs-ecr-login == 'true' }}
235-
uses: aws-actions/amazon-ecr-login@d539f0932e70871a027e9d5a9d8fc38589180a64 # v2.1.6
239+
uses: aws-actions/amazon-ecr-login@03f1aad4c6c7ffd436567f42f9384779290529bd # v2.1.7
236240
with:
237241
registries: ${{ steps.dockerfile-ecr-parse.outputs.ecr-registries }}
238242

239243
- name: Login to ECR for publishing
240244
if: ${{ inputs.docker-push == 'true' }}
241245
id: login-ecr
242-
uses: aws-actions/amazon-ecr-login@d539f0932e70871a027e9d5a9d8fc38589180a64 # v2.1.6
246+
uses: aws-actions/amazon-ecr-login@03f1aad4c6c7ffd436567f42f9384779290529bd # v2.1.7
243247
with:
244248
registry-type: >-
245249
${{
@@ -251,7 +255,7 @@ runs:
251255

252256
- name: Set up Docker Buildx
253257
id: setup-buildx
254-
uses: docker/setup-buildx-action@bb05f3f5519dd87d3ba754cc423b652a5edd6d2c # v4.2.0
258+
uses: docker/setup-buildx-action@37fe631027851001ddb9b187196cc803df7f5f0e # v4.3.0
255259
with:
256260
# https://github.com/docker/buildx/tags
257261
version: v0.35.0

‎workflows/reusable-docker-build-publish/reusable-docker-build-publish.yml‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,17 @@ on:
146146
required: false
147147
type: string
148148
default: "write-on-trunk"
149+
docker-cache-map:
150+
description: |
151+
JSON string mapping cache mount paths/names for buildkit-cache-dance, passed
152+
through to build-push-docker's cache-map. Use the object form with an explicit
153+
id matching the Dockerfile's cache mount id, e.g.
154+
'{"cache-mount/go-build-cache": {"id": "go-build-cache", "target": "/var/cache-target"}}'.
155+
Restricts cache-dance to only the listed mounts; if omitted, all cache mounts
156+
are discovered from the Dockerfile.
157+
required: false
158+
type: string
159+
default: ""
149160
docker-build-context:
150161
description: "Path to Docker build context."
151162
required: true
@@ -433,7 +444,7 @@ jobs:
433444
docker-build-cache-from: ${{ steps.should-cache.outputs.docker-build-cache-from }}
434445
docker-cache-suffix: ${{ steps.should-cache.outputs.docker-cache-suffix }}
435446
steps:
436-
- uses: actions/checkout@v6
447+
- uses: actions/checkout@v7
437448
with:
438449
persist-credentials: false
439450
fetch-depth: 1
@@ -612,9 +623,9 @@ jobs:
612623
uses: smartcontractkit/.github/actions/free-disk-space@free-disk-space/v1
613624

614625
- name: Enable S3 Cache for Self-Hosted Runners
615-
uses: runs-on/action@4e5f72399b6b17f2e79c511c1b38a315a64d22dc # v2.2.0
626+
uses: runs-on/action@efac073ea2507ec18797de3a81704201ade11d9d # v2.3.1
616627

617-
- uses: actions/checkout@v6
628+
- uses: actions/checkout@v7
618629
id: checkout
619630
with:
620631
persist-credentials: false
@@ -776,6 +787,7 @@ jobs:
776787
docker-save-cache: ${{ needs.init.outputs.docker-save-cache }}
777788
docker-build-cache-to: ${{ needs.init.outputs.docker-build-cache-to }},scope=${{ steps.compute-cache-scope.outputs.scope }}
778789
docker-build-cache-from: ${{ needs.init.outputs.docker-build-cache-from }},scope=${{ steps.compute-cache-scope.outputs.scope }}
790+
cache-map: ${{ inputs.docker-cache-map }}
779791
context: ${{ inputs.docker-build-context }}
780792
docker-build-contexts: ${{ inputs.docker-build-contexts }}
781793
docker-push: ${{ inputs.docker-push }}

0 commit comments

Comments
 (0)