Skip to content

Commit ab94b50

Browse files
authored
Merge pull request #2541 from norio-nomura/use-no_timer_check-kernel-parameter
test.yml: use `inject-cmdline-to-template.sh` to append `no_timer_check` kernel command line option
2 parents c200d17 + 9fbd193 commit ab94b50

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed

.github/workflows/test.yml

+6
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ jobs:
184184
time brew install qemu bash coreutils curl jq
185185
- name: "Show cache"
186186
run: ./hack/debug-cache.sh
187+
- name: "Inject `no_timer_check` to kernel cmdline"
188+
# workaround to https://github.com/lima-vm/lima/issues/84
189+
run: ./hack/inject-cmdline-to-template.sh templates/default.yaml no_timer_check
187190
- name: "Test default.yaml"
188191
uses: nick-invision/retry@v3
189192
with:
@@ -356,6 +359,9 @@ jobs:
356359
- name: Unit test (pkg/networks) with socket_vmnet
357360
# Set -count=1 to disable cache
358361
run: go test -v -count=1 ./pkg/networks/...
362+
- name: "Inject `no_timer_check` to kernel cmdline"
363+
# workaround to https://github.com/lima-vm/lima/issues/84
364+
run: ./hack/inject-cmdline-to-template.sh templates/vmnet.yaml no_timer_check
359365
- name: Test socket_vmnet
360366
uses: nick-invision/retry@v3
361367
with:

hack/inject-cmdline-to-template.sh

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#!/usr/bin/env bash
2+
#
3+
# This script does
4+
# 1. detect arch from template if not provided
5+
# 2. extract location by parsing template using arch
6+
# 3. get the image location
7+
# 4. check the image location is supported
8+
# 5. build the kernel and initrd location, digest, and cmdline
9+
# 6. inject the kernel and initrd location, digest, and cmdline to the template
10+
# 7. output kernel_location, kernel_digest, cmdline, initrd_location, initrd_digest
11+
12+
set -eu -o pipefail
13+
14+
template="$1"
15+
appending_options="$2"
16+
# 1. detect arch from template if not provided
17+
arch="${3:-$(yq '.arch // ""' "${template}")}"
18+
arch="${arch:-$(uname -m)}"
19+
20+
# normalize arch. amd64 -> x86_64, arm64 -> aarch64
21+
case "${arch}" in
22+
amd64 | x86_64) arch=x86_64 ;;
23+
aarch64 | arm64) arch=aarch64 ;;
24+
*)
25+
echo "Unsupported arch: ${arch}" >&2
26+
exit 1
27+
;;
28+
esac
29+
30+
# 2. extract location by parsing template using arch
31+
readonly yq_filter="
32+
[
33+
.images | map(select(.arch == \"${arch}\")) | [.[].location]
34+
]|flatten|.[]
35+
"
36+
parsed=$(yq eval "${yq_filter}" "${template}")
37+
38+
# 3. get the image location
39+
while IFS= read -r line; do arr+=("${line}"); done <<<"${parsed}"
40+
readonly locations=("${arr[@]}")
41+
for ((i = 0; i < ${#locations[@]}; i++)); do
42+
[[ ${locations[i]} != "null" ]] || continue
43+
http_code=$(curl -sIL -w "%{http_code}" "${locations[i]}" -o /dev/null)
44+
if [[ ${http_code} -eq 200 ]]; then
45+
location=${locations[i]}
46+
index=${i}
47+
break
48+
fi
49+
done
50+
51+
# 4. check the image location is supported
52+
if [[ -z ${location} ]]; then
53+
echo "Failed to get the image location for ${template}" >&2
54+
exit 1
55+
elif [[ ${location} == https://cloud-images.ubuntu.com/* ]]; then
56+
readonly default_cmdline="root=LABEL=cloudimg-rootfs ro console=tty1 console=ttyAMA0"
57+
else
58+
echo "Unsupported image location: ${location}" >&2
59+
exit 1
60+
fi
61+
62+
# 5. build the kernel and initrd location, digest, and cmdline
63+
location_dirname=$(dirname "${location}")/unpacked
64+
sha256sums=$(curl -sSLf "${location_dirname}/SHA256SUMS")
65+
location_basename=$(basename "${location}")
66+
67+
# cmdline
68+
cmdline="${default_cmdline} ${appending_options}"
69+
70+
# kernel
71+
kernel_basename="${location_basename/.img/-vmlinuz-generic}"
72+
kernel_digest=$(awk "/${kernel_basename}/{print \"sha256:\"\$1}" <<<"${sha256sums}")
73+
kernel_location="${location_dirname}/${kernel_basename}"
74+
75+
# initrd
76+
initrd_basename="${location_basename/.img/-initrd-generic}"
77+
initrd_digest=$(awk "/${initrd_basename}/{print \"sha256:\"\$1}" <<<"${sha256sums}")
78+
initrd_location="${location_dirname}/${initrd_basename}"
79+
80+
# 6. inject the kernel and initrd location, digest, and cmdline to the template
81+
yq -i eval "
82+
[(.images.[] | select(.arch == \"${arch}\") | path)].[${index}] + \"kernel\" as \$path|
83+
setpath(\$path; { \"location\": \"${kernel_location}\", \"digest\": \"${kernel_digest}\", \"cmdline\": \"${cmdline}\" })
84+
" "${template}"
85+
yq -i eval "
86+
[(.images.[] | select(.arch == \"${arch}\") | path)].[${index}] + \"initrd\" as \$path|
87+
setpath(\$path ; { \"location\": \"${initrd_location}\", \"digest\": \"${initrd_digest}\" })
88+
" "${template}"
89+
90+
# 7. output kernel_location, kernel_digest, cmdline, initrd_location, initrd_digest
91+
readonly outputs=(kernel_location kernel_digest cmdline initrd_location initrd_digest)
92+
for output in "${outputs[@]}"; do
93+
echo "${output}=${!output}"
94+
done

0 commit comments

Comments
 (0)