Skip to content

Commit 2adaf1d

Browse files
authored
Merge pull request #3453 from jandubois/image-templates
Refactor images lists and default mounts into base templates
2 parents 95173c1 + 238a141 commit 2adaf1d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+865
-893
lines changed

.github/workflows/test.yml

+8-6
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ jobs:
196196
- name: Validate jsonschema
197197
run: make schema-limayaml.json
198198
- name: Validate templates
199-
run: find -L templates -name '*.yaml' | xargs limactl validate
199+
# Can't validate base templates in `_default` because they have no images
200+
run: find -L templates -name '*.yaml' ! -path '*/_default/*' | xargs limactl validate
200201
- name: Install test dependencies
201202
# QEMU: required by Lima itself
202203
# bash: required by test-templates.sh (OS version of bash is too old)
@@ -208,7 +209,7 @@ jobs:
208209
run: echo "LIMACTL_CREATE_ARGS=${LIMACTL_CREATE_ARGS} --vm-type=qemu" >>$GITHUB_ENV
209210
- name: "Inject `no_timer_check` to kernel cmdline"
210211
# workaround to https://github.com/lima-vm/lima/issues/84
211-
run: ./hack/inject-cmdline-to-template.sh templates/default.yaml no_timer_check
212+
run: ./hack/inject-cmdline-to-template.sh templates/_images/ubuntu.yaml no_timer_check
212213
- name: Cache image used by default.yaml
213214
uses: ./.github/actions/setup_cache_for_template
214215
with:
@@ -353,7 +354,7 @@ jobs:
353354
steps:
354355
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
355356
with:
356-
fetch-depth: 1
357+
fetch-depth: 0
357358
- uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5.4.0
358359
with:
359360
go-version: 1.24.x
@@ -365,7 +366,7 @@ jobs:
365366
run: echo "LIMACTL_CREATE_ARGS=${LIMACTL_CREATE_ARGS} --vm-type=qemu --network=lima:shared" >>$GITHUB_ENV
366367
- name: "Inject `no_timer_check` to kernel cmdline"
367368
# workaround to https://github.com/lima-vm/lima/issues/84
368-
run: ./hack/inject-cmdline-to-template.sh templates/default.yaml no_timer_check
369+
run: ./hack/inject-cmdline-to-template.sh templates/_images/ubuntu.yaml no_timer_check
369370
- name: Cache image used by default .yaml
370371
uses: ./.github/actions/setup_cache_for_template
371372
with:
@@ -408,6 +409,7 @@ jobs:
408409
steps:
409410
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
410411
with:
412+
# To avoid "failed to load YAML file \"templates/experimental/riscv64.yaml\": can't parse builtin Lima version \"3f3a6f6\": 3f3a6f6 is not in dotted-tri format"
411413
fetch-depth: 0
412414
- name: Fetch homebrew-core commit messages
413415
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
@@ -452,7 +454,7 @@ jobs:
452454
steps:
453455
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
454456
with:
455-
fetch-depth: 1
457+
fetch-depth: 0
456458
- uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5.4.0
457459
with:
458460
go-version: 1.24.x
@@ -487,7 +489,7 @@ jobs:
487489
steps:
488490
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
489491
with:
490-
fetch-depth: 1
492+
fetch-depth: 0
491493
- uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5.4.0
492494
with:
493495
go-version: 1.24.x

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
_output/
22
_artifacts/
33
lima.REJECTED.yaml
4+
default-template.yaml
45
schema-limayaml.json
56
.config

.ls-lint.yml

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ ls:
1919
docs:
2020
.md: kebab-case
2121

22+
templates:
23+
# _default and _images have leading underscores
24+
.dir: lowercase
25+
2226
website/content:
2327
.dir: lowercase
2428

Makefile

+9-4
Original file line numberDiff line numberDiff line change
@@ -419,14 +419,19 @@ ifeq ($(native_compiling),true)
419419
endif
420420

421421
################################################################################
422-
schema-limayaml.json: _output/bin/limactl$(exe)
422+
default-template.yaml: _output/bin/limactl$(exe)
423423
ifeq ($(native_compiling),true)
424-
$< generate-jsonschema --schemafile $@ templates/default.yaml
424+
$< tmpl copy --embed-all templates/default.yaml $@
425+
endif
426+
427+
schema-limayaml.json: _output/bin/limactl$(exe) default-template.yaml
428+
ifeq ($(native_compiling),true)
429+
$< generate-jsonschema --schemafile $@ default-template.yaml
425430
endif
426431

427432
.PHONY: check-jsonschema
428-
check-jsonschema: schema-limayaml.json
429-
check-jsonschema --schemafile $< templates/default.yaml
433+
check-jsonschema: schema-limayaml.json default-template.yaml
434+
check-jsonschema --schemafile schema-limayaml.json default-template.yaml
430435

431436
################################################################################
432437
.PHONY: diagrams

cmd/limactl/start.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,10 @@ func createStartActionCommon(cmd *cobra.Command, _ []string) (exit bool, err err
374374
if templates, err := templatestore.Templates(); err == nil {
375375
w := cmd.OutOrStdout()
376376
for _, f := range templates {
377-
_, _ = fmt.Fprintln(w, f.Name)
377+
// Don't show internal base templates like `_default/*` and `_images/*`.
378+
if !strings.HasPrefix(f.Name, "_") {
379+
_, _ = fmt.Fprintln(w, f.Name)
380+
}
378381
}
379382
return true, nil
380383
}

hack/common.inc.sh

+6
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,9 @@ _IPERF3=iperf3
2929
# https://github.com/lima-vm/socket_vmnet/issues/85
3030
[ "$(uname -s)" = "Darwin" ] && _IPERF3="iperf3-darwin"
3131
: "${IPERF3:=$_IPERF3}"
32+
33+
# Setup LIMA_TEMPLATES_PATH because the templates are not installed, but reference base templates
34+
# via template://_images/* and template://_default/*.
35+
templates_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/../templates" && pwd)"
36+
: "${LIMA_TEMPLATES_PATH:-$templates_dir}"
37+
export LIMA_TEMPLATES_PATH

hack/test-templates.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ FILE="$(cd "$(dirname "$1")" && pwd)/$(basename "$1")"
2222
NAME="$(basename -s .yaml "$FILE")"
2323
OS_HOST="$(uname -o)"
2424

25-
# On Windows $HOME of the bash runner, %USERPROFILE% of the host machine and mpunting point in the guest machine
26-
# are all different folders. This will handle path differences, when values are expilictly set.
25+
# On Windows $HOME of the bash runner, %USERPROFILE% of the host machine and mounting point in the guest machine
26+
# are all different folders. This will handle path differences, when values are explicitly set.
2727
HOME_HOST=${HOME_HOST:-$HOME}
2828
HOME_GUEST=${HOME_GUEST:-$HOME}
2929
FILE_HOST=$FILE

pkg/limayaml/limayaml_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ func TestDefaultYAML(t *testing.T) {
3737
assert.NilError(t, err)
3838
y.Images = nil // remove default images
3939
y.Mounts = nil // remove default mounts
40+
y.Base = nil // remove default base templates
41+
y.MinimumLimaVersion = nil // remove minimum Lima version
4042
y.MountTypesUnsupported = nil // remove default workaround for kernel 6.9-6.11
4143
t.Log(dumpJSON(t, y))
4244
b, err := Marshal(&y, false)

pkg/limayaml/validate_test.go

-18
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
package limayaml
55

66
import (
7-
"os"
8-
"runtime"
97
"testing"
108

119
"gotest.tools/v3/assert"
@@ -18,22 +16,6 @@ func TestValidateEmpty(t *testing.T) {
1816
assert.Error(t, err, "field `images` must be set")
1917
}
2018

21-
// Note: can't embed symbolic links, use "os"
22-
23-
func TestValidateDefault(t *testing.T) {
24-
if runtime.GOOS == "windows" {
25-
// FIXME: `assertion failed: error is not nil: field `mounts[1].location` must be an absolute path, got "/tmp/lima"`
26-
t.Skip("Skipping on windows")
27-
}
28-
29-
bytes, err := os.ReadFile("default.yaml")
30-
assert.NilError(t, err)
31-
y, err := Load(bytes, "default.yaml")
32-
assert.NilError(t, err)
33-
err = Validate(y, true)
34-
assert.NilError(t, err)
35-
}
36-
3719
func TestValidateProbes(t *testing.T) {
3820
images := `images: [{"location": "/"}]`
3921
validProbe := `probes: [{"script": "#!foo"}]`

pkg/templatestore/templatestore.go

+20-7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
package templatestore
55

66
import (
7+
"errors"
8+
"fmt"
79
"io/fs"
810
"os"
911
"path/filepath"
@@ -20,21 +22,32 @@ type Template struct {
2022
}
2123

2224
func Read(name string) ([]byte, error) {
23-
dir, err := usrlocalsharelima.Dir()
24-
if err != nil {
25-
return nil, err
25+
var pathList []string
26+
if tmplPath := os.Getenv("LIMA_TEMPLATES_PATH"); tmplPath != "" {
27+
pathList = strings.Split(tmplPath, string(filepath.ListSeparator))
28+
} else {
29+
dir, err := usrlocalsharelima.Dir()
30+
if err != nil {
31+
return nil, err
32+
}
33+
pathList = []string{filepath.Join(dir, "templates")}
2634
}
2735
ext := filepath.Ext(name)
2836
// Append .yaml extension if name doesn't have an extension, or if it starts with a digit.
2937
// So "docker.sh" would remain unchanged but "ubuntu-24.04" becomes "ubuntu-24.04.yaml".
3038
if len(ext) < 2 || unicode.IsDigit(rune(ext[1])) {
3139
name += ".yaml"
3240
}
33-
filePath, err := securejoin.SecureJoin(filepath.Join(dir, "templates"), name)
34-
if err != nil {
35-
return nil, err
41+
for _, path := range pathList {
42+
filePath, err := securejoin.SecureJoin(path, name)
43+
if err != nil {
44+
return nil, err
45+
}
46+
if b, err := os.ReadFile(filePath); !errors.Is(err, os.ErrNotExist) {
47+
return b, err
48+
}
3649
}
37-
return os.ReadFile(filePath)
50+
return nil, fmt.Errorf("template %q not found", name)
3851
}
3952

4053
const Default = "default"

templates/_default/mounts.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
mounts:
2+
- location: "~"
3+
- location: "/tmp/lima"
4+
writable: true

templates/_images/almalinux-8.yaml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# NOTE: EL8-based distros are known not to work on M1 chips: https://github.com/lima-vm/lima/issues/841
2+
# EL9-based distros are known to work.
3+
images:
4+
- location: https://repo.almalinux.org/almalinux/8.10/cloud/x86_64/images/AlmaLinux-8-GenericCloud-8.10-20240819.x86_64.qcow2
5+
arch: x86_64
6+
digest: sha256:669bd580dcef5491d4dfd5724d252cce7cde1b2b33a3ca951e688d71386875e3
7+
8+
- location: https://repo.almalinux.org/almalinux/8.10/cloud/aarch64/images/AlmaLinux-8-GenericCloud-8.10-20240819.aarch64.qcow2
9+
arch: aarch64
10+
digest: sha256:cec6736cbc562d06895e218b6f022621343c553bfa79192ca491381b4636c7b8
11+
12+
- location: https://repo.almalinux.org/almalinux/8.10/cloud/s390x/images/AlmaLinux-8-GenericCloud-8.10-20240819.s390x.qcow2
13+
arch: s390x
14+
digest: sha256:7f8866a4247ad57c81f5d2c5a0fa64940691f9df1e858a1510d34a0de008eb16
15+
16+
# Fallback to the latest release image.
17+
# Hint: run `limactl prune` to invalidate the cache
18+
19+
- location: https://repo.almalinux.org/almalinux/8/cloud/x86_64/images/AlmaLinux-8-GenericCloud-latest.x86_64.qcow2
20+
arch: x86_64
21+
22+
- location: https://repo.almalinux.org/almalinux/8/cloud/aarch64/images/AlmaLinux-8-GenericCloud-latest.aarch64.qcow2
23+
arch: aarch64
24+
25+
- location: https://repo.almalinux.org/almalinux/8/cloud/s390x/images/AlmaLinux-8-GenericCloud-latest.s390x.qcow2
26+
arch: s390x
27+
28+
mountTypesUnsupported: [9p]
29+
30+
cpuType:
31+
# Workaround for "vmx_write_mem: mmu_gva_to_gpa XXXXXXXXXXXXXXXX failed" on Intel Mac
32+
# https://bugs.launchpad.net/qemu/+bug/1838390
33+
x86_64: Haswell-v4

templates/_images/almalinux-9.yaml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
images:
2+
- location: https://repo.almalinux.org/almalinux/9.5/cloud/x86_64/images/AlmaLinux-9-GenericCloud-9.5-20241120.x86_64.qcow2
3+
arch: x86_64
4+
digest: sha256:abddf01589d46c841f718cec239392924a03b34c4fe84929af5d543c50e37e37
5+
6+
- location: https://repo.almalinux.org/almalinux/9.5/cloud/aarch64/images/AlmaLinux-9-GenericCloud-9.5-20241120.aarch64.qcow2
7+
arch: aarch64
8+
digest: sha256:5ede4affaad0a997a2b642f1628b6268bd8eba775f281346b75be3ed20ec369e
9+
10+
- location: https://repo.almalinux.org/almalinux/9.5/cloud/s390x/images/AlmaLinux-9-GenericCloud-9.5-20241120.s390x.qcow2
11+
arch: s390x
12+
digest: sha256:9948ea1c5ee1c6497bde5cec18c71c5f9e50861af4c0f1400c1af504eee2b995
13+
14+
# Fallback to the latest release image.
15+
# Hint: run `limactl prune` to invalidate the cache
16+
17+
- location: https://repo.almalinux.org/almalinux/9/cloud/x86_64/images/AlmaLinux-9-GenericCloud-latest.x86_64.qcow2
18+
arch: x86_64
19+
20+
- location: https://repo.almalinux.org/almalinux/9/cloud/aarch64/images/AlmaLinux-9-GenericCloud-latest.aarch64.qcow2
21+
arch: aarch64
22+
23+
- location: https://repo.almalinux.org/almalinux/9/cloud/s390x/images/AlmaLinux-9-GenericCloud-latest.s390x.qcow2
24+
arch: s390x
25+
26+
mountTypesUnsupported: [9p]

templates/_images/alpine-iso.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Using the Alpine 3.20 aarch64 image with vmType=vz requires macOS Ventura 13.3 or later.
2+
images:
3+
- location: https://github.com/lima-vm/alpine-lima/releases/download/v0.2.41/alpine-lima-std-3.20.3-x86_64.iso
4+
arch: x86_64
5+
digest: sha512:949a353c1676bb406561d22c1b7f9db72fb0cc899c6c50166df3b38e392280a7e7b83f58643a309816d51a48317507c46c3e7e24e52fbc9f20fe817039306db1
6+
7+
- location: https://github.com/lima-vm/alpine-lima/releases/download/v0.2.41/alpine-lima-std-3.20.3-aarch64.iso
8+
arch: aarch64
9+
digest: sha512:91ea119fea2bb638519792de2047303b26eaebcdace8df57b76373dc7b1cddcad77aaa9fed2d438fb02351b261783af3264d6bb2716519f8ba211a4b25d6f114

templates/_images/alpine.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
images:
2+
- location: https://dl-cdn.alpinelinux.org/alpine/v3.21/releases/cloud/nocloud_alpine-3.21.2-x86_64-uefi-cloudinit-r0.qcow2
3+
arch: x86_64
4+
digest: sha512:1aaf22b4a584e69e228e6aa38a295159c0143d9ccebe7ad4928e92b414714066af3bfe5f9e0ca4d4d64a70ca9fea09033af90258a6f2344130d70b660151127a
5+
6+
- location: https://dl-cdn.alpinelinux.org/alpine/v3.21/releases/cloud/nocloud_alpine-3.21.2-aarch64-uefi-cloudinit-r0.qcow2
7+
arch: aarch64
8+
digest: sha512:08d340126b222abae651a20aa63c3ee3dc601d703de7879d2a6bc1fe82a3664d058a2c55ad0cf8a874327f7535e3af8a9384ce438217d6f32200cad1462a5b32

templates/_images/archlinux.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
images:
2+
# Try to use yyyyMMdd.REV image if available. Note that yyyyMMdd.REV will be removed after several months.
3+
4+
- location: https://geo.mirror.pkgbuild.com/images/v20250315.322357/Arch-Linux-x86_64-cloudimg-20250315.322357.qcow2
5+
arch: x86_64
6+
digest: sha256:b162746f6e64064500901ecb61b76f3d2873fcd25bdab4aaa784758719a701c5
7+
8+
- location: https://github.com/mcginty/arch-boxes-arm/releases/download/v20220323/Arch-Linux-aarch64-cloudimg-20220323.0.qcow2
9+
arch: aarch64
10+
digest: sha512:27524910bf41cb9b3223c8749c6e67fd2f2fdb8b70d40648708e64d6b03c0b4a01b3c5e72d51fefd3e0c3f58487dbb400a79ca378cde2da341a3a19873612be8
11+
12+
# Fallback to the latest release image.
13+
# Hint: run `limactl prune` to invalidate the cache
14+
15+
- location: https://geo.mirror.pkgbuild.com/images/latest/Arch-Linux-x86_64-cloudimg.qcow2
16+
arch: x86_64
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
images:
2+
# Try to use release-yyyyMMdd image if available. Note that release-yyyyMMdd will be removed after several months.
3+
4+
- location: https://cloud.centos.org/centos/10-stream/x86_64/images/CentOS-Stream-GenericCloud-10-20250317.0.x86_64.qcow2
5+
arch: x86_64
6+
digest: sha256:24578ef181b03ab577acaa885cbc24b1c91fbae613d50152796cbe6c2e004aab
7+
8+
- location: https://cloud.centos.org/centos/10-stream/aarch64/images/CentOS-Stream-GenericCloud-10-20250317.0.aarch64.qcow2
9+
arch: aarch64
10+
digest: sha256:5cfd6199d9f9ada1e4e44113938981b2dce96ba3e9e670549e6e1c1a8e74f167
11+
12+
- location: https://cloud.centos.org/centos/10-stream/s390x/images/CentOS-Stream-GenericCloud-10-20250317.0.s390x.qcow2
13+
arch: s390x
14+
digest: sha256:903b47d726fa9a892853cfb805d52a0bf75a7fc710169619bdaae7c3e3a00296
15+
16+
# Fallback to the latest release image.
17+
# Hint: run `limactl prune` to invalidate the cache
18+
19+
- location: https://cloud.centos.org/centos/10-stream/x86_64/images/CentOS-Stream-GenericCloud-10-latest.x86_64.qcow2
20+
arch: x86_64
21+
22+
- location: https://cloud.centos.org/centos/10-stream/aarch64/images/CentOS-Stream-GenericCloud-10-latest.aarch64.qcow2
23+
arch: aarch64
24+
25+
- location: https://cloud.centos.org/centos/10-stream/s390x/images/CentOS-Stream-GenericCloud-10-latest.s390x.qcow2
26+
arch: s390x
27+
28+
mountTypesUnsupported: [9p]
29+
30+
firmware:
31+
# CentOS Stream 10 still requires legacyBIOS
32+
# https://issues.redhat.com/browse/CS-2672
33+
legacyBIOS: true
34+
35+
cpuType:
36+
# When emulating Intel on ARM hosts, Lima uses the "qemu64" CPU by default (https://github.com/lima-vm/lima/pull/494).
37+
# However, CentOS Stream 10 kernel reboots indefinitely due to lack of the support for x86_64-v3 instructions.
38+
# This issue is tracked in <https://github.com/lima-vm/lima/issues/3063>.
39+
x86_64: "Haswell-v4"

0 commit comments

Comments
 (0)