From a904df0f875856e5179798685ced0fe8d5b06707 Mon Sep 17 00:00:00 2001 From: "Jason N." <33561705+JasonN3@users.noreply.github.com> Date: Thu, 7 Mar 2024 12:49:51 -0500 Subject: [PATCH] copy cache before it's deleted --- Makefile | 5 ++++- action.yml | 4 +++- lorax_templates/copy_dnf_cache.tmpl.in | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 lorax_templates/copy_dnf_cache.tmpl.in diff --git a/Makefile b/Makefile index c09e88f..a0d568a 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ EXTRA_BOOT_PARAMS = ROOTFS_SIZE = 4 DNF_CACHE = -# Generated vars +# Generated/internal vars ## Formatting = _UPPERCASE _BASE_DIR = $(shell pwd) _IMAGE_REPO_ESCAPED = $(subst /,\/,$(IMAGE_REPO)) @@ -23,6 +23,8 @@ _IMAGE_REPO_DOUBLE_ESCAPED = $(subst \,\\\,$(_IMAGE_REPO_ESCAPED)) _VOLID = $(firstword $(subst -, ,$(IMAGE_NAME)))-$(ARCH)-$(IMAGE_TAG) _REPO_FILES = $(subst /etc/yum.repos.d,repos,$(REPOS)) _LORAX_TEMPLATES = $(subst .in,,$(shell ls lorax_templates/*.tmpl.in)) $(foreach file,$(shell ls lorax_templates/scripts/post),lorax_templates/post_$(file).tmpl) +_EXCLUDED_TEMPLATES = lorax_templates/copy_dnf_cache.tpml.in +_LORAX_TEMPLATES = $(filter-out $(_EXCLUDED_TEMPLATES),$(_LORAX_TEMPLATES)) _TEMPLATE_VARS = ARCH VERSION IMAGE_REPO IMAGE_NAME IMAGE_TAG VARIANT WEB_UI REPOS _IMAGE_REPO_ESCAPED _IMAGE_REPO_DOUBLE_ESCAPED ENROLLMENT_PASSWORD _LORAX_ARGS = @@ -40,6 +42,7 @@ endif ifneq ($(DNF_CACHE),) _LORAX_ARGS += --cachedir $(DNF_CACHE) +_LORAX_TEMPLATES += lorax_templates/copy_dnf_cache.tpml.in endif # Step 7: Buid end ISO diff --git a/action.yml b/action.yml index 59e9c44..babe803 100644 --- a/action.yml +++ b/action.yml @@ -91,6 +91,7 @@ runs: shell: bash run: | mkdir /cache/dnf || true + mkdir /cache/dnf_new || true mkdir /cache/skopeo || true - name: Run docker image @@ -101,6 +102,7 @@ runs: if [[ -z "${tag}" ]]; then tag=${{ github.action_ref }}; fi if [[ "${{ inputs.enable_cache_dnf }}" == "true" ]]; then cache="${cache} -v /cache/dnf:/cache/dnf"; fi if [[ "${{ inputs.enable_cache_skopeo }}" == "true" ]]; then cache="${cache} -v /cache/skopeo:/cache/skopeo"; fi + if [[ "${{ steps.load_dnf_cache.outputs.cache-hit}}" == "false" ]]; then cache="${cache} -v /cache/dnf_new:/cache/dnf_new"; fi docker run --privileged --volume ${{ github.workspace }}:/github/workspace/ ${cache} ghcr.io/jasonn3/build-container-installer:${tag} \ ARCH=${{ inputs.arch }} \ IMAGE_NAME=${{ inputs.image_name }} \ @@ -120,7 +122,7 @@ runs: if: inputs.enable_cache_dnf == 'true' && steps.load_dnf_cache.outputs.cache-hit == 'false' uses: actions/cache/save@v4 with: - path: /cache/dnf + path: /cache/dnf_new key: ${{ inputs.dnf_cache_key || env.dnf_cache_key }} - name: Save skopeo cache diff --git a/lorax_templates/copy_dnf_cache.tmpl.in b/lorax_templates/copy_dnf_cache.tmpl.in new file mode 100644 index 0000000..a601d2d --- /dev/null +++ b/lorax_templates/copy_dnf_cache.tmpl.in @@ -0,0 +1 @@ +runcmd "bash -c 'if [[ -d /cache/dnf_new ]]; then cp -R /cache/dnf /cache/dnf_new; fi'" \ No newline at end of file