Skip to content

Commit d8bb155

Browse files
committed
Do guest template expansion for provisioning scripts
The LIMA_CIDATA_* variables are not a supported API and can change without warning. Signed-off-by: Jan Dubois <[email protected]>
1 parent bd7442e commit d8bb155

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

examples/default.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ containerd:
184184

185185
# Provisioning scripts need to be idempotent because they might be called
186186
# multiple times, e.g. when the host VM is being restarted.
187+
# The scripts can use the following template variables: {{.Home}}, {{.UID}}, and {{.User}}
187188
# 🟢 Builtin default: null
188189
# provision:
189190
# # `system` is executed with the root privilege

pkg/limayaml/defaults.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,11 @@ func FillDefault(y, d, o *LimaYAML, filePath string) {
427427
if provision.Mode == ProvisionModeDependency && provision.SkipDefaultDependencyResolution == nil {
428428
provision.SkipDefaultDependencyResolution = ptr.Of(false)
429429
}
430+
if out, err := executeGuestTemplate(provision.Script); err == nil {
431+
provision.Script = out.String()
432+
} else {
433+
logrus.WithError(err).Warnf("Couldn't process provisioning script %q as a template", provision.Script)
434+
}
430435
}
431436

432437
if y.GuestInstallPrefix == nil {
@@ -795,7 +800,7 @@ func executeHostTemplate(format, instDir string) (bytes.Buffer, error) {
795800
"User": user.Username,
796801

797802
"Instance": filepath.Base(instDir), // DEPRECATED, use `{{.Name}}`
798-
"LimaHome": limaHome, // DEPRECATED, (use `Dir` instead of `{{.LimaHome}}/{{.Instance}}`
803+
"LimaHome": limaHome, // DEPRECATED, use `{{.Dir}}` instead of `{{.LimaHome}}/{{.Instance}}`
799804
}
800805
var out bytes.Buffer
801806
if err := tmpl.Execute(&out, data); err == nil {

0 commit comments

Comments
 (0)