7
7
template :
8
8
description : template yaml file
9
9
required : true
10
+ detect-containerd :
11
+ description : detect containerd usage from template by using limactl validate
12
+ required : false
13
+ default : ' true'
10
14
runs :
11
15
using : " composite"
12
16
steps :
@@ -27,10 +31,15 @@ runs:
27
31
set -eux
28
32
arch="${{ inputs.arch }}"
29
33
template="${{ inputs.template }}"
34
+ detect_containerd="${{ inputs.detect-containerd }}"
35
+ if [[ $detect_containerd == "true" ]] && ! command -v limactl &>/dev/null; then
36
+ echo "containerd detection is disabled because limactl is not found" >&2
37
+ detect_containerd="false"
38
+ fi
30
39
case "$template" in
31
40
https://*)
32
41
tmp_yaml=$(mktemp -d)/template.yaml
33
- curl -sSLf "$template" > $tmp_yaml || exit 1
42
+ curl -sSLf "$template" > " $tmp_yaml" || exit 1
34
43
template=$tmp_yaml
35
44
;;
36
45
*)
@@ -47,27 +56,82 @@ runs:
47
56
arm64) arch=aarch64 ;;
48
57
esac
49
58
50
- # extract digest and location from template using arch
51
- digest="$(yq ".images | map(select(.arch == \"$arch\")) | .[0].digest // \"\"" "$template") "
52
- location="$(yq ".images | map(select(.arch == \"$arch\")) | .[0].location // \"\"" "$template")"
53
- test -n "$location" || exit 1
54
-
55
- # path to cache
56
- if command -v sha256sum > /dev/null; then
57
- sha256="$(echo -n "$location" | sha256sum | cut -d' ' -f1) "
58
- elif command -v shasum > /dev/null ; then
59
- sha256="$(echo -n "$location" | shasum -a 256 | cut -d' ' -f1)"
59
+ # extract digest, location and size by parsing template using arch
60
+ readonly yq_filter= "
61
+ [
62
+ .images | map(select(.arch == \"${arch}\")) | [.[0,1].location, .[0,1].digest],
63
+ .containerd|[.system or .user],
64
+ .containerd.archives | map(select(.arch == \"${arch}\")) | [.[0].location, .[0].digest]
65
+ ]|flatten|.[]
66
+ "
67
+ if [[ $detect_containerd == "true" ]] ; then
68
+ parsed=$(LIMA_HOME=$(mktemp -d) limactl validate "$template" --fill 2>/dev/null | yq eval "${yq_filter}")
60
69
else
61
- echo "sha256sum or shasum not found" >&2
70
+ parsed=$(yq eval "${yq_filter}" "$template")
71
+ fi
72
+ readarray -t arr <<<"$parsed"
73
+ readonly locations=("${arr[@]:0:2}") digests=("${arr[@]:2:2}")
74
+ readonly containerd="${arr[4]}" containerd_location="${arr[5]}" containerd_digest="${arr[6]}"
75
+ for ((i = 0; i < ${#locations[@]}; i++)); do
76
+ [[ ${locations[i]} != "null" ]] || continue
77
+ http_code=$(curl -sIL -w "%{http_code}" "${locations[i]}" -o /dev/null)
78
+ if [[ ${http_code} -eq 200 ]]; then
79
+ location=${locations[i]}
80
+ digest=${digests[i]}
81
+ break
82
+ fi
83
+ done
84
+ if [[ -z ${location} ]]; then
85
+ echo "Failed to get the image location for ${template}" >&2
62
86
exit 1
63
87
fi
64
- echo "path=.download/by-url-sha256/$sha256" >> "$GITHUB_OUTPUT"
88
+
89
+ function location_to_sha256() {
90
+ local location=$1
91
+ if command -v sha256sum > /dev/null; then
92
+ sha256="$(echo -n "$location" | sha256sum | cut -d' ' -f1)"
93
+ elif command -v shasum > /dev/null; then
94
+ sha256="$(echo -n "$location" | shasum -a 256 | cut -d' ' -f1)"
95
+ else
96
+ echo "sha256sum or shasum not found" >&2
97
+ exit 1
98
+ fi
99
+ echo "$sha256"
100
+ }
101
+
102
+ function location_to_cache_path() {
103
+ sha256=$(location_to_sha256 "$location") && echo ".download/by-url-sha256/$sha256"
104
+ }
105
+
106
+ # path to cache
107
+ image_cache_path=$(location_to_cache_path "$location")
108
+ echo "path=$image_cache_path" >> "$GITHUB_OUTPUT"
65
109
66
110
# key for cache
67
- key="${digest:+image-$digest}"
68
- # fallback to os and hash of template file if digest not found
69
- key="${key:-${{ runner.os }}-${{ hashFiles(inputs.template) }}}"
111
+ image_basename=$(basename "$location")
112
+ if [[ "$digest" != "null" ]]; then
113
+ key="image:$image_basename-$digest"
114
+ else
115
+ # use sha256 of location as key if digest is not available
116
+ key="image:$image_basename-url-sha256:$(sha256 "$location")"
117
+ fi
70
118
echo "key=$key" >> "$GITHUB_OUTPUT"
119
+
120
+ # containerd path and key for cache
121
+ if [[ $containerd == "true" && "$containerd_location" != "null" ]]; then
122
+ containerd_basename=$(basename "$containerd_location")
123
+ if [[ ${containerd_digest} != "null" ]]; then
124
+ containerd_key="containerd:$containerd_basename-$containerd_digest"
125
+ else
126
+ containerd_key="containerd:$containerd_basename-url-sha256:$(sha256 "$containerd_location")"
127
+ fi
128
+ echo "containerd-key=$containerd_key" >> "$GITHUB_OUTPUT"
129
+ containerd_cache_path=$(location_to_cache_path "$containerd_location")
130
+ echo "containerd-path=$containerd_cache_path" >> "$GITHUB_OUTPUT"
131
+ else
132
+ echo "containerd-key=" >> "$GITHUB_OUTPUT"
133
+ echo "containerd-path=" >> "$GITHUB_OUTPUT"
134
+ fi
71
135
shell : bash
72
136
73
137
- name : " Cache ${{ steps.cache-params-from-template.outputs.path }}"
@@ -78,11 +142,19 @@ runs:
78
142
key : ${{ steps.cache-params-from-template.outputs.key }}
79
143
enableCrossOsArchive : true
80
144
145
+ - name : " Cache ${{ steps.cache-params-from-template.outputs.containerd-key }}"
146
+ if : ${{ steps.cache-params-from-template.outputs.containerd-key != '' }}
147
+ uses : actions/cache@v4
148
+ with :
149
+ path : ${{ steps.cache-params-from-template.outputs.containerd-path }}
150
+ key : ${{ steps.cache-params-from-template.outputs.containerd-key }}
151
+ enableCrossOsArchive : true
152
+
81
153
- name : " Create symbolic link named ${{ steps.detect-platform.outputs.download-dir }} pointing to .download"
82
154
run : |
83
155
set -eux
84
156
[ -d .download ] || mkdir -p .download
85
157
path_to_cache=${{ steps.detect-platform.outputs.download-dir }}
86
- mkdir -p $(dirname $path_to_cache)
87
- ln -sfn $PWD/.download $path_to_cache
158
+ mkdir -p " $(dirname " $path_to_cache")"
159
+ ln -sfn " $PWD/.download" " $path_to_cache"
88
160
shell : bash
0 commit comments