From a9bd5aeb169c079b69354bbfbc0287512d2a2d1b Mon Sep 17 00:00:00 2001 From: "Jason N." <33561705+JasonN3@users.noreply.github.com> Date: Wed, 6 Mar 2024 10:56:10 -0600 Subject: [PATCH] use cache in action --- action.yml | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 22914f1..76b5c45 100644 --- a/action.yml +++ b/action.yml @@ -40,6 +40,20 @@ inputs: description: Version of the action container to run deprecationMessage: No longer used. github.action_ref replaces the need for this. Will be removed in a future version. required: false + enable_cache_dnf: + description: Whether to enable caching for dnf + required: false + default: "true" + enable_cache_skopeo: + description: Whether to enable caching for skopeo + required: false + default: "true" + dnf_cache_key: + description: Overrides the dnf cache key + required: false + skopeo_cache_key: + description: Overrides the skopeo cache key + required: false additional_templates: description: Space delimetered list of additional Lorax templates to include required: false @@ -47,12 +61,32 @@ inputs: runs: using: composite steps: + - name: Load dnf cache + env: + dnf_cache_key: dnf-${{ inputs.version }} + if: inputs.enable_cache_dnf == 'true' + uses: action/cache/restore@v4 + with: + path: /cache/dnf + key: ${{ inputs.dnf_cache_key || env.dnf_cache_key }} + + - name: Load skopeo cache + env: + skopeo_cache_key: skopeo-${{ inputs.image_name }}-${{ inputs.image_tag }} + if: inputs.enable_cache_skopeo == 'true' + uses: action/cache/restore@v4 + with: + path: /cache/skopeo + key: ${{ inputs.skopeo_cache_key || env.skopeo_cache_key }} + - name: Run docker image shell: bash run: | # Check if running inside of the action repo if [[ -z "${{ github.action_ref }}" ]]; then if [[ "${{ github.ref_name }}" =~ (.*)/merge ]]; then tag=pr-${BASH_REMATCH[1]}; else tag=${{ github.ref_name }}; fi; fi 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 docker run --privileged --volume ${{ github.workspace }}:/github/workspace/ ghcr.io/jasonn3/build-container-installer:${tag} \ ARCH=${{ inputs.arch }} \ IMAGE_NAME=${{ inputs.image_name }} \ @@ -63,5 +97,24 @@ runs: WEB_UI=${{ inputs.web_ui }} \ ENROLLMENT_PASSWORD=${{ inputs.enrollment_password }} \ SECURE_BOOT_KEY_URL=${{ inputs.secure_boot_key_url }} \ - "ADDITIONAL_TEMPLATES=${{ inputs.additional_templates }}" + "ADDITIONAL_TEMPLATES=${{ inputs.additional_templates }}" \ + DNF_CACHE=/cache/dnf + + - name: Save dnf cache + env: + dnf_cache_key: dnf-${{ inputs.version }} + if: inputs.enable_cache_dnf == 'true' + uses: action/cache/save@v4 + with: + path: /cache/dnf + key: ${{ inputs.dnf_cache_key || env.dnf_cache_key }} + + - name: Save skopeo cache + env: + skopeo_cache_key: skopeo-${{ inputs.image_name }}-${{ inputs.image_tag }} + if: inputs.enable_cache_skopeo == 'true' + uses: action/cache/save@v4 + with: + path: /cache/skopeo + key: ${{ inputs.skopeo_cache_key || env.skopeo_cache_key }}