Skip to content

Conversation

@jandubois
Copy link
Member

@jandubois jandubois commented Mar 11, 2025

The template.Read() method will guess the architecture based on the image filename and construct a template dynamically.

It also strips generic tags from the image name to generate an instance name candidate.

limactl start --containerd none https://dl-cdn.alpinelinux.org/alpine/v3.21/releases/cloud/nocloud_alpine-3.21.2-aarch64-uefi-cloudinit-r0.qcow2
...limactl shell alpine-3.21.2-r0 uname -a
Linux lima-alpine-3-21-2-r0 6.12.8-0-virt #1-Alpine SMP PREEMPT_DYNAMIC 2025-01-02 12:14:41 aarch64 Linux

Closes #3322

This code needs to be updated with s390x heuristics once #3319 is merged (or the other way around, depending on which one is merged first).

@jandubois
Copy link
Member Author

This implementation also allows you to use image URLs as base templates:

cat my.yaml
base: https://yum.oracle.com/templates/OracleLinux/OL8/u10/aarch64/OL8U10_aarch64-kvm-cloud-b100.qcow2limactl tmpl copy --embed my.yaml -
WARN[0000] `base` is experimental

arch: "aarch64"
images:
- location: "https://yum.oracle.com/templates/OracleLinux/OL8/u10/aarch64/OL8U10_aarch64-kvm-cloud-b100.qcow2"
  arch: "aarch64"limactl start my.yaml
...limactl shell my grep PRETTY /etc/os-release
PRETTY_NAME="Oracle Linux Server 8.10"

@jandubois jandubois added this to the v1.1.0 milestone Mar 11, 2025
"stream", // CentOS
"uefi", // Alpine
"vm", // openSUSE
}
Copy link
Member

@AkihiroSuda AkihiroSuda Mar 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MaybefileName.trimPrefix("nocloud_").splitWords[0].toLower() just suffices

e.g.,

  • nocloud_alpine-3.21.2-x86_64-uefi-cloudinit-r0.qcow2 -> alpine
  • ubuntu-24.10-server-cloudimg-arm64.img -> ubuntu

Arch-Linux-x86_64-cloudimg-20250201.304316.qcow2 may still needs an exceptional rule though, if we want the instance name to be archlinux, not arch

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kind of like the more descriptive names. You can always use --name ubuntu https//... if you want a really short name or predictable name.

So I would prefer to keep the current logic, unless you really dislike it.

Also don't want to add unit tests if you are going to make me remove it again. 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lima-vm/maintainers Thoughts?

Copy link
Member Author

@jandubois jandubois Mar 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arch-Linux-x86_64-cloudimg-20250201.304316.qcow2 may still needs an exceptional rule though, if we want the instance name to be archlinux, not arch

I just noticed that I didn't add linux to the list of generic tags. I would want to strip that too, so the default instance name for this image would be arch-20250201.304316.

Copy link
Member Author

@jandubois jandubois Mar 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've selected all image names from all our templates and filtered out just the amd64 ones:

find templates -name "*.yaml" -exec yq '.images[].location' {} \; | xargs basename | sed s/nocloud_// | sort -fu | grep -E 'amd|x86'

I've then manually transformed each of them into the instance name produced by the current algorithm:

almalinux-8
almalinux-8-8.10-20240819
almalinux-9
almalinux-9-9.5-20241120
alpine-3.21.2-r0
alpine-lima-3.20.3
arch
arch-20250201.304316
centos-10
centos-10-20250210.0
centos-9
centos-9-20250210.0
debian-11
debian-11-20241202-1949
debian-12
debian-12-20250210-2019
debian-sid
fedora-41-1.4
gentoo
ol8u10-b237
ol9u5-b253
opensuse-leap-15.6
opensuse-tumbleweed
rocky-8
rocky-8-8.10-20240528.0
rocky-9
rocky-9-9.5-20241118.0
ubuntu-20.04
ubuntu-22.04
ubuntu-24.04
ubuntu-24.10

I think the names look reasonable, and I would prefer them to just picking the first word from the string.

Copy link
Member Author

@jandubois jandubois Mar 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a special rule to translate arch to archlinux and another rule to strip the datestamps, which leaves us with this list of instance names (duplicates pruned):

almalinux-8
almalinux-8-8.10
almalinux-9
almalinux-9-9.5
alpine-3.21.2-r0
alpine-lima-3.20.3
archlinux
centos-10
centos-9
debian-11
debian-12
debian-sid
fedora-41-1.4
gentoo
ol8u10-b237
ol9u5-b253
opensuse-leap-15.6
opensuse-tumbleweed
rocky-8
rocky-8-8.10
rocky-9
rocky-9-9.5
ubuntu-20.04
ubuntu-22.04
ubuntu-24.04
ubuntu-24.10

@jandubois
Copy link
Member Author

jandubois commented Mar 12, 2025

Changes:

  • Add "linux" and "daily" to list of generic tags
  • Change "arch" to "archlinux"
  • Strip timestamps from instance names
  • Created InstNameFromImageURL function and added unit tests
  • Remove blank first line from the generated image template
  • Added unit test for image URL expansion into a template

@jandubois jandubois force-pushed the image-templates branch 3 times, most recently from b0474bb to 4cd31db Compare March 12, 2025 07:26
@jandubois jandubois requested a review from AkihiroSuda March 12, 2025 07:28
@jandubois jandubois force-pushed the image-templates branch 2 times, most recently from ab3ddfe to d75dae4 Compare March 12, 2025 17:36
The template.Read() method will guess the architecture based on the
image filename and construct a template dynamically.

It also strips generic tags from the image name to generate an
instance name candidate.

Signed-off-by: Jan Dubois <[email protected]>
Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@AkihiroSuda AkihiroSuda merged commit 0cff556 into lima-vm:master Mar 12, 2025
31 checks passed
@jandubois jandubois deleted the image-templates branch March 13, 2025 02:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

limactl create URL should accept image URLs too

2 participants