Skip to content

Commit 2328f73

Browse files
committed
feat: added cache for binary and bundle to speed up action
This commit will add a new parameter to enable cache, default to true. When cache is enabled it will cache the crc binary per arch and the bundle per preset and arch, so on next action invocations there is no need to download anddecompress which could be time consuming actions within the cluster start up Signed-off-by: Adrian Riobo <[email protected]>
1 parent 9b79f84 commit 2328f73

File tree

1 file changed

+43
-6
lines changed

1 file changed

+43
-6
lines changed

action.yml

+43-6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ inputs:
1818
disk:
1919
description: 'disk size consumed by crc instance'
2020
required: false
21+
cache:
22+
description: 'enable cache to speed up cluster starts: true or false (default true). '
23+
default: 'true'
2124
runs:
2225
using: 'composite'
2326
steps:
@@ -27,6 +30,30 @@ runs:
2730
run: |
2831
echo "::error title=⛔ error hint::Support Linux Only"
2932
exit 1
33+
34+
- name: Set CRC versions
35+
if: ${{ inputs.cache == 'true' }}
36+
shell: bash
37+
run: |
38+
curl -LO https://mirror.openshift.com/pub/openshift-v4/clients/crc/latest/release-info.json
39+
echo "crc_version=$(jq -r '.version.crcVersion' release-info.json)" >> "$GITHUB_ENV"
40+
41+
- name: Cache for crc binary
42+
if: ${{ inputs.cache == 'true' }}
43+
uses: actions/cache@v4
44+
with:
45+
with:
46+
path: installer
47+
key: installer-${{ env.crc_version}}-${{ runner.arch }}
48+
49+
- name: Cache for bundle
50+
if: ${{ inputs.cache == 'true' }}
51+
uses: actions/cache@v4
52+
with:
53+
with:
54+
path: ~/.crc/cache
55+
key: bundle-${{ inputs.preset}}-${{ env.crc_version }}-${{ runner.arch }}
56+
3057
- name: Download CRC
3158
shell: bash
3259
run: |
@@ -36,20 +63,26 @@ runs:
3663
CRC_ARCH="amd64"
3764
fi
3865
URL="https://mirror.openshift.com/pub/openshift-v4/clients/crc/latest/crc-linux-${CRC_ARCH}.tar.xz"
39-
echo "Downloading $URL"
40-
curl -H user-agent:crc-github-action -L "$URL" -o crc-linux.tar.xz --max-time 300 --fail
41-
SHA256SUM=$(curl -H user-agent:crc-github-action -L "${URL}".sha256 --fail)
42-
echo "Expected sha256: $SHA256SUM"
43-
echo "Actual sha256: $(sha256sum crc-linux.tar.xz)"
44-
echo "$SHA256SUM crc-linux.tar.xz" | sha256sum -c
66+
mkdir -p installer
67+
pushd installer
68+
if [ ! -f crc-linux.tar.xz ]; then
69+
echo "Downloading $URL"
70+
curl -H user-agent:crc-github-action -L "$URL" -o crc-linux.tar.xz --max-time 300 --fail
71+
SHA256SUM=$(curl -H user-agent:crc-github-action -L "${URL}".sha256 --fail)
72+
echo "Expected sha256: $SHA256SUM"
73+
echo "Actual sha256: $(sha256sum crc-linux.tar.xz)"
74+
echo "$SHA256SUM crc-linux.tar.xz" | sha256sum -c
75+
fi
4576
tar -C /tmp -xvf crc-linux.tar.xz
4677
sudo mv /tmp/crc-linux-*-amd64/crc /usr/bin
78+
4779
- name: Install required virtualization software
4880
shell: bash
4981
run: |
5082
sudo apt-get update
5183
sudo apt install qemu-kvm libvirt-daemon libvirt-daemon-system
5284
sudo usermod -a -G libvirt $USER
85+
5386
- name: Remove unwanted stuff to free up disk image
5487
shell: bash
5588
run: |
@@ -63,6 +96,7 @@ runs:
6396

6497
sudo swapoff -a
6598
sudo rm -f /mnt/swapfile
99+
66100
- name: Set the crc config
67101
shell: bash
68102
env:
@@ -85,15 +119,18 @@ runs:
85119
echo "Using disk: ${{ inputs['disk'] }}"
86120
crc config set disk-size ${{ inputs['disk'] }}
87121
fi
122+
88123
- name: Setup and Start the crc
89124
shell: bash
90125
run: |
91126
sudo -su $USER crc setup
92127
sudo -su $USER crc start
93128
sleep 60
129+
94130
- name: Copy OpenShift client
95131
shell: bash
96132
run: sudo cp /home/$USER/.crc/bin/oc/oc /usr/bin/
133+
97134
- name: Copy the kubeconfig file to required location
98135
shell: bash
99136
run: |

0 commit comments

Comments
 (0)