Skip to content

Commit

Permalink
Add cache-id option
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Atkinson <[email protected]>
  • Loading branch information
catks committed Mar 11, 2024
1 parent e2c919a commit be46452
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
with:
cache-source: var-lib-apt
cache-target: /var/lib/apt
cache-id: cache-var-lib-apt
skip-extraction: ${{ steps.cache-var-lib-apt.outputs.cache-hit }}
- name: Build and push
uses: docker/build-push-action@v5
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ RUN rm -f /etc/apt/apt.conf.d/docker-clean && \
echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache
RUN \
--mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
--mount=type=cache,id=cache-var-lib-apt,target=/var/lib/apt,sharing=locked \
apt update && \
apt-get --no-install-recommends install -y gcc
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ inputs:
cache-target:
default: /root/.cache/go-build
description: "Where the cache is stored in the docker container. Default: `/root/.cache/go-build`"
cache-id:
default: ''
description: "The id of the cache mount. Default: '' (No id)"
scratch-dir:
default: scratch
description: "Where the action is stores some temporary files for its processing. Default: `scratch`"
Expand Down
6 changes: 5 additions & 1 deletion main
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ rm -Rf "$(read_action_input scratch-dir)" && mkdir -p "$(read_action_input scrat
: "Prepare Timestamp for Layer Cache Busting"
date --iso=ns | tee "$(read_action_input cache-source)"/buildstamp
: "Prepare Dancefile to Access Caches"

cache_mount_id="$(read_action_input cache-id)"
cache_mount_id_string=$(test -n "$cache_mount_id" && echo "id=${cache_mount_id}," || echo '')

cat >"$(read_action_input scratch-dir)"/Dancefile.inject <<EOF
FROM busybox:1
COPY buildstamp buildstamp
RUN --mount=type=cache,target="$(read_action_input cache-target)" \
RUN --mount=type=cache,${cache_mound_id_string}target="$(read_action_input cache-target)" \
--mount=type=bind,source=.,target=/var/dance-cache \
cp -p -R /var/dance-cache/. "$(read_action_input cache-target)" || true
EOF
Expand Down

0 comments on commit be46452

Please sign in to comment.