Skip to content

Commit 0fd0b23

Browse files
authored
Allow disabling portions of caching (#42)
1 parent 25092e9 commit 0fd0b23

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ jobs:
5050
| `build-secrets` | List of [secrets](https://docs.docker.com/engine/reference/commandline/buildx_build/#secret) to expose to the build. | No | <pre><code>GIT_AUTH_TOKEN=mytoken</code></pre> |
5151
| `from-scratch` | Do not read from the cache when building the image. Writes to caches will still occur. Defaults to `false`. | No | `false` |
5252
| `cache-mount-ids` | List of build [cache mount IDs or targets](https://docs.docker.com/reference/dockerfile/#run---mounttypecache) to preserve across builds. By default the IDs are determined from the Dockerfile as specified in `dockerfile`. | No | <pre><code>/var/cache/apt&#10;/var/lib/apt</code></pre> |
53+
| `use-layer-caching` | Store Docker layer cache data in the `image-repository` to accelerate image building. These cache images are stored using the "cache-*" tag. Typically, should be enabled but it can be useful to disable for debugging purposes. | No | `false` |
54+
| `use-mount-caching` | Store data contained within `--mount=type=cache` in GitHub Actions cache entries such that it can be used between image builds in CI workflows. Typically, should be enabled but it can be useful to disable for debugging purposes. | No | `false` |
5355

5456
## Outputs
5557

action.yaml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ inputs:
3232
List of build cache mount IDs or targets to preserve across builds. By default the
3333
IDs are determined from the Dockerfile as specified in `dockerfile`.
3434
default: ""
35+
use-layer-caching:
36+
description: >-
37+
Store Docker layer cache data in the `image-repository` to accelerate image building.
38+
These cache images are stored using the "cache-*" tag. Typically, should be enabled
39+
but it can be useful to disable for debugging purposes.
40+
default: "true"
41+
use-mount-caching:
42+
description: >-
43+
Store data contained within `--mount=type=cache` in GitHub Actions cache entries such
44+
that it can be used between image builds in CI workflows. Typically, should be enabled
45+
but it can be useful to disable for debugging purposes.
46+
default: "true"
3547
outputs:
3648
image:
3749
description: Reference to the build image including the digest.
@@ -111,7 +123,7 @@ runs:
111123
# https://docs.docker.com/build/cache/backends/registry/
112124
- name: Docker cache-from
113125
id: cache-from
114-
if: ${{ inputs.from-scratch != 'true' }}
126+
if: ${{ inputs.use-layer-caching == 'true' && inputs.from-scratch != 'true' }}
115127
uses: docker/metadata-action@c1e51972afc2121e065aed6d45c65596fe445f3f # v5.8.0
116128
with:
117129
images: |
@@ -127,6 +139,7 @@ runs:
127139
DOCKER_METADATA_SET_OUTPUT_ENV: "false"
128140
- name: Docker cache-to
129141
id: cache-to
142+
if: ${{ inputs.use-layer-caching == 'true' }}
130143
uses: docker/metadata-action@c1e51972afc2121e065aed6d45c65596fe445f3f # v5.8.0
131144
with:
132145
images: |
@@ -140,6 +153,7 @@ runs:
140153
DOCKER_METADATA_SET_OUTPUT_ENV: "false"
141154
- name: Docker cache metadata
142155
id: cache
156+
if: ${{ inputs.use-layer-caching == 'true' }}
143157
shell: bash
144158
run: |
145159
# Docker cache metadata
@@ -168,7 +182,7 @@ runs:
168182
bind_root: ${{ github.action_path }}/cache-mount
169183
- name: Process cache mount IDs
170184
id: cache-mount
171-
if: ${{ inputs.cache-mount-ids != '' }}
185+
if: ${{ inputs.use-mount-caching == 'true' && inputs.cache-mount-ids != '' }}
172186
shell: bash
173187
run: |
174188
# Process cache mount IDs
@@ -188,6 +202,7 @@ runs:
188202
cache_mount_ids: ${{ inputs.cache-mount-ids }}
189203
bind_root: ${{ steps.bind-root.outputs.path }}
190204
- name: Retrieve Docker cache mount bundle
205+
if: ${{ inputs.use-mount-caching == 'true' }}
191206
uses: actions/cache@v4
192207
with:
193208
path: ${{ steps.bind-root.outputs.path }}
@@ -196,6 +211,7 @@ runs:
196211
docker-build-cache-mount
197212
# https://docs.docker.com/build/ci/github-actions/cache/#cache-mounts
198213
- name: Restore Docker cache mounts
214+
if: ${{ inputs.use-mount-caching == 'true' }}
199215
uses: reproducible-containers/buildkit-cache-dance@5b81f4d29dc8397a7d341dba3aeecc7ec54d6361 # v3.3.0
200216
with:
201217
cache-map: ${{ steps.cache-mount.outputs.cache-map }}

0 commit comments

Comments
 (0)