Replies: 4 comments 7 replies
-
I wrote the braindump above to show where I think we should go over time with the However, it leaves us with the dilema of 2 conflicting goals:
Having too many templates that are mostly identical and just have minor configuration differences are eventually becoming confusing too (and harder to maintain with all the duplication). I don't think there is a hard and fast rule, but I think if 2 templates share a significant amount of code/settings, then they may be candidates for combination. For example we might have just a single This is all very new, and the It may end up that having 2 templates remains the better choice, but let's give it some time to try different approaches. |
Beta Was this translation helpful? Give feedback.
-
The |
Beta Was this translation helpful? Give feedback.
-
Parameters (and using "templates") is one way, there could be other ways to simplify the provisioning. images:
- ubuntu-24.04
mounts:
- default
# containerd is managed by Docker, not by Lima, so the values are set to false here.
containerd:
system: false
user: false
### ⬇️ talking about this part below
provision:
- mode: system
# This script defines the host.docker.internal hostname when hostResolver is disabled.
# It is also needed for lima 0.8.2 and earlier, which does not support hostResolver.hosts.
# Names defined in /etc/hosts inside the VM are not resolved inside containers when
# using the hostResolver; use hostResolver.hosts instead (requires lima 0.8.3 or later).
script: |
#!/bin/sh
sed -i 's/host.lima.internal.*/host.lima.internal host.docker.internal/' /etc/hosts
- mode: system
script: |
#!/bin/bash
set -eux -o pipefail
command -v docker >/dev/null 2>&1 && exit 0
export DEBIAN_FRONTEND=noninteractive
curl -fsSL https://get.docker.com | sh
# NOTE: you may remove the lines below, if you prefer to use rootful docker, not rootless
systemctl disable --now docker
apt-get install -y uidmap dbus-user-session
- mode: user
script: |
#!/bin/bash
set -eux -o pipefail
systemctl --user start dbus
dockerd-rootless-setuptool.sh install
docker context use rootless
probes:
- script: |
#!/bin/bash
set -eux -o pipefail
if ! timeout 30s bash -c "until command -v docker >/dev/null 2>&1; do sleep 3; done"; then
echo >&2 "docker is not installed yet"
exit 1
fi
if ! timeout 30s bash -c "until pgrep rootlesskit; do sleep 3; done"; then
echo >&2 "rootlesskit (used by rootless docker) is not running"
exit 1
fi
hint: See "/var/log/cloud-init-output.log" in the guest
### ⬆️ talking about this part above
hostResolver:
# hostResolver.hosts requires lima 0.8.3 or later. Names defined here will also
# resolve inside containers, and not just inside the VM itself.
hosts:
host.docker.internal: host.lima.internal
portForwards:
- guestSocket: "/run/user/{{.UID}}/docker.sock"
hostSocket: "{{.Dir}}/sock/docker.sock"
message: |
To run `docker` on the host (assumes docker-cli is installed), run the following commands:
------
docker context create lima-{{.Name}} --docker "host=unix://{{.Dir}}/sock/docker.sock"
docker context use lima-{{.Name}}
docker run hello-world
------ For instance having more types of provisioners and probes, than always using It's not the same discussion, but something to keep in mind? e.g. "rootful" could be a top-level concept*. * like it is in EDIT: Added some whitespace |
Beta Was this translation helpful? Give feedback.
-
Personally, I feel that enhancing validation offers little benefit relative to the effort required.
Rather than adding mounts:
- location: "{{.Dir}}/log"
mountPoint: "/var/log"
writable: true If mounts:
- location: "{{if eq .Param.MOUNT_USB \"true\"}}/Volumes/USB{{end}}"
param:
MOUNT_USB: false |
Beta Was this translation helpful? Give feedback.
-
Lima Param Evolution
I think the new
param
mechanism by @norio-nomura (#2498) is a great way to make our templates much more configurable.I've been brainstorming on how to extend this basic mechanism. While I think some of the ideas below are good, I reserve the right to change my mind once I think some more about them. 😄
Additional attributes
I would like to attach additional attributes to parameters, so the current format should be as short-form:
is going to be the same as:
Validation
We are (trying to) validate all settings in
lima.yaml
as much as possible before we actually create an instance based on it. We should provide a mechanism to do the same forparam
values.When you specify any other value, you will now get an error:
Validation can be a list of choices
Instead of a regex you should be able to enumerate the valid choices. That is easier to read:
And allows us to generate better error messages:
Custom error messages
For more complex settings we may want to specify the error message outself:
Default validation for numbers and boolean
As a convenience we can auto-generate validation and error message if the
default
is a boolean (true
/false
, oryes
/no
), or a number. For example:would be expanded to
Prompt for params in TTY mode
When we are creating a new instance while in
--tty
mode, we may want to ask for the value of some of the params.The
validate
setting will be auto-generate to[yes, no]
because of the default value, and theerror
is then auto-generated from that enum.Creating a new instance will prompt you:
The optional prompting is why I proposed
yes
/no
as alternate boolen values because they work better when asking a question interactively.Adding
if
condition on list entriesThe
override.yaml
anddefaults.yaml
mechanism has limited utility for lists because it has limited capabilities for overwriting (some entries can merge attributes when the entries have a unique key).With the new
param
mechanism we could addif
conditions to all lists (images
,mounts
,networks
,portForwardings
,provision
scripts,probes
, etc).I could put this snippet into my
override.yaml
file to optionally mount an additional volume without having to manually edit thelima.yaml
file:When I need access to the USB volume I create the instance like this:
limactl start --set '.params.MOUNT_USB=true' template://docker
The value of the
if
attribute is a Go template expression. The entry will be ignored if the expression evaluates to the empty string,0
,false
, orno
.Don't error if param from
override.yaml
ordefaults.yaml
is unusedThis already works the way I want; I just want to confirm this is intentional, and not accidental: we only check that params declared in the template itself are used by the template. We don't check params declared in either
override.yaml
ordefaults.yaml
.E.g. I may want to use rootful docker when I run
limactl start template://docker
, so would put this inoverride.yaml
:I don't want to see a warning about
param.ROOTFUL
being unused when I create a default instance withlimactl start
.URL params on templates
We could add support for query parameters to template URLs:
limactl start --name rootful "template://docker?ROOTFUL=true"
It feels a bit weird though to put them on regular URLs:
limactl start "https://raw.githubusercontent.com/lima-vm/lima/master/examples/docker.yaml?ROOTFUL=true"
And even worse on plain filenames:
docker.yaml?ROOTFUL=true
.It is also redundant with
--set
:But then e.g.
--rosetta
is also redundant with--set .rosetta.enabled=true
, so I don't know.We could also add a
--param
option:Or (assuming we use Go parsing for boolean
param
):Beta Was this translation helpful? Give feedback.
All reactions