Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cache-id option #21

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
12 changes: 12 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ 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 option added)"
cache-mode:
default: ''
description: "The mode of the cache mount. Default: '' (No mode option added)"
cache-sharing:
default: ''
description: "The sharing option of the cache mount. Default: '' (No sharing option added)"
builder:
default: ''
description: "The sharing option of the cache mount. Default: '' (Use the current builder)"
scratch-dir:
default: scratch
description: "Where the action is stores some temporary files for its processing. Default: `scratch`"
Expand Down
21 changes: 20 additions & 1 deletion main
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,34 @@ 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 '')

cache_mount_mode="$(read_action_input cache-mode)"
cache_mount_mode_string=$(test -n "$cache_mount_mode" && echo "mode=${cache_mount_mode}," || echo '')

cache_mount_sharing="$(read_action_input cache-sharing)"
cache_mount_sharing_string=$(test -n "$cache_mount_sharing" && echo "sharing=${cache_mount_sharing}," || 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_mount_id_string}${cache_mount_mode_string}${cache_mount_sharing_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
cat "$(read_action_input scratch-dir)"/Dancefile.inject
: "Inject Data into Docker Cache"

builder=$(read_action_input builder)

if [[ -n "$builder" ]]; then
docker buildx use $builder
fi

docker buildx build -f "$(read_action_input scratch-dir)"/Dancefile.inject --tag dance:inject "$(read_action_input cache-source)"
: "Debug Directories"
sudo ls -laR "$(read_action_input cache-source)"
: "Clean Directories"
sudo rm -rf "$(read_action_input cache-source)"
20 changes: 19 additions & 1 deletion post
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,31 @@ fi
: "Prepare Timestamp for Layer Cache Busting"
date --iso=ns | tee "$(read_action_input scratch-dir)"/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 '')

cache_mount_mode="$(read_action_input cache-mode)"
cache_mount_mode_string=$(test -n "$cache_mount_mode" && echo "mode=${cache_mount_mode}," || echo '')

cache_mount_sharing="$(read_action_input cache-sharing)"
cache_mount_sharing_string=$(test -n "$cache_mount_sharing" && echo "sharing=${cache_mount_sharing}," || echo '')

cat >"$(read_action_input scratch-dir)"/Dancefile.extract <<EOF
FROM busybox:1
COPY buildstamp buildstamp
RUN --mount=type=cache,target="$(read_action_input cache-target)" \
RUN --mount=type=cache,${cache_mount_id_string}${cache_mount_mode_string}${cache_mount_sharing_string}target="$(read_action_input cache-target)" \
mkdir -p /var/dance-cache/ \
&& cp -p -R "$(read_action_input cache-target)"/. /var/dance-cache/ || true
EOF
cat "$(read_action_input scratch-dir)"/Dancefile.extract
: "Extract Data into Docker Image"
builder=$(read_action_input builder)

if [[ -n "$builder" ]]; then
docker buildx use $builder
fi

docker buildx build -f "$(read_action_input scratch-dir)"/Dancefile.extract --tag dance:extract --load "$(read_action_input scratch-dir)"
: "Create Extraction Image"
docker rm -f cache-container && docker create -ti --name cache-container dance:extract
Expand All @@ -31,3 +47,5 @@ docker cp -L cache-container:/var/dance-cache - | tar -H posix -x -C "$(read_act
: "Move Cache into Its Place"
sudo rm -rf "$(read_action_input cache-source)"
mv "$(read_action_input scratch-dir)"/dance-cache "$(read_action_input cache-source)"
: "Debug Directories"
sudo ls -laR "$(read_action_input cache-source)"
Loading