From 5bb87efff9196da53cbe14112b4f563ca28e881f Mon Sep 17 00:00:00 2001 From: Carlos Atkinson Date: Mon, 11 Mar 2024 11:42:39 -0300 Subject: [PATCH 1/5] Add cache-id option Signed-off-by: Carlos Atkinson --- .github/workflows/test.yml | 1 + .github/workflows/test/Dockerfile | 2 +- action.yml | 3 +++ main | 6 +++++- post | 6 +++++- 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8616179..5c4e08a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 diff --git a/.github/workflows/test/Dockerfile b/.github/workflows/test/Dockerfile index 728b80b..0889316 100644 --- a/.github/workflows/test/Dockerfile +++ b/.github/workflows/test/Dockerfile @@ -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 diff --git a/action.yml b/action.yml index 23344c0..f441278 100644 --- a/action.yml +++ b/action.yml @@ -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`" diff --git a/main b/main index 98499d9..9c5ec1e 100755 --- a/main +++ b/main @@ -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 <"$(read_action_input scratch-dir)"/Dancefile.extract < Date: Tue, 12 Mar 2024 09:43:46 -0300 Subject: [PATCH 2/5] Add Other cache options --- action.yml | 8 +++++++- main | 8 +++++++- post | 8 +++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index f441278..8ac5b5c 100644 --- a/action.yml +++ b/action.yml @@ -9,7 +9,13 @@ inputs: 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)" + 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)" scratch-dir: default: scratch description: "Where the action is stores some temporary files for its processing. Default: `scratch`" diff --git a/main b/main index 9c5ec1e..0c20071 100755 --- a/main +++ b/main @@ -14,10 +14,16 @@ date --iso=ns | tee "$(read_action_input cache-source)"/buildstamp 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 <"$(read_action_input scratch-dir)"/Dancefile.extract < Date: Tue, 12 Mar 2024 09:46:08 -0300 Subject: [PATCH 3/5] Debug directories --- main | 2 ++ post | 2 ++ 2 files changed, 4 insertions(+) diff --git a/main b/main index 0c20071..b3801f0 100755 --- a/main +++ b/main @@ -30,5 +30,7 @@ EOF cat "$(read_action_input scratch-dir)"/Dancefile.inject : "Inject Data into Docker Cache" 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)" diff --git a/post b/post index 1fd0380..a4d9839 100755 --- a/post +++ b/post @@ -41,3 +41,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)" From d447f21f19da34b8d39cdfb868c5c378366ce71e Mon Sep 17 00:00:00 2001 From: Carlos Atkinson Date: Tue, 12 Mar 2024 11:13:02 -0300 Subject: [PATCH 4/5] Add builder option --- action.yml | 3 +++ main | 7 +++++++ post | 6 ++++++ 3 files changed, 16 insertions(+) diff --git a/action.yml b/action.yml index 8ac5b5c..07ddb88 100644 --- a/action.yml +++ b/action.yml @@ -16,6 +16,9 @@ inputs: 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`" diff --git a/main b/main index b3801f0..20fd1ca 100755 --- a/main +++ b/main @@ -29,6 +29,13 @@ RUN --mount=type=cache,${cache_mount_id_string}${cache_mount_mode_string}${cache 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)" diff --git a/post b/post index a4d9839..757c314 100755 --- a/post +++ b/post @@ -33,6 +33,12 @@ RUN --mount=type=cache,id=${cache_mount_id_string}${cache_mount_mode_string}${ca 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 From 54f5edfc0d6b40c04930d44af0a5d3ee8c652d17 Mon Sep 17 00:00:00 2001 From: Carlos Atkinson Date: Tue, 19 Mar 2024 19:42:16 -0300 Subject: [PATCH 5/5] fixup! Add cache-id option --- post | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/post b/post index 757c314..eca744d 100755 --- a/post +++ b/post @@ -27,7 +27,7 @@ cache_mount_sharing_string=$(test -n "$cache_mount_sharing" && echo "sharing=${c cat >"$(read_action_input scratch-dir)"/Dancefile.extract <