@@ -147,6 +147,7 @@ func defaultGuestInstallPrefix() string {
147
147
// - DNS are picked from the highest priority where DNS is not empty.
148
148
// - CACertificates Files and Certs are uniquely appended in d, y, o order
149
149
func FillDefault (y , d , o * LimaYAML , filePath string ) {
150
+ instDir := filepath .Dir (filePath )
150
151
if y .VMType == nil {
151
152
y .VMType = d .VMType
152
153
}
@@ -393,7 +394,7 @@ func FillDefault(y, d, o *LimaYAML, filePath string) {
393
394
if provision .Mode == ProvisionModeDependency && provision .SkipDefaultDependencyResolution == nil {
394
395
provision .SkipDefaultDependencyResolution = ptr .Of (false )
395
396
}
396
- if out , err := executeGuestTemplate (provision .Script ); err == nil {
397
+ if out , err := executeGuestTemplate (provision .Script , instDir ); err == nil {
397
398
provision .Script = out .String ()
398
399
} else {
399
400
logrus .WithError (err ).Warnf ("Couldn't process provisioning script %q as a template" , provision .Script )
@@ -462,7 +463,6 @@ func FillDefault(y, d, o *LimaYAML, filePath string) {
462
463
}
463
464
464
465
y .PortForwards = append (append (o .PortForwards , y .PortForwards ... ), d .PortForwards ... )
465
- instDir := filepath .Dir (filePath )
466
466
for i := range y .PortForwards {
467
467
FillPortForwardDefaults (& y .PortForwards [i ], instDir )
468
468
// After defaults processing the singular HostPort and GuestPort values should not be used again.
@@ -745,12 +745,13 @@ func fixUpForPlainMode(y *LimaYAML) {
745
745
y .TimeZone = ptr .Of ("" )
746
746
}
747
747
748
- func executeGuestTemplate (format string ) (bytes.Buffer , error ) {
748
+ func executeGuestTemplate (format , instDir string ) (bytes.Buffer , error ) {
749
749
tmpl , err := template .New ("" ).Parse (format )
750
750
if err == nil {
751
751
user , _ := osutil .LimaUser (false )
752
752
data := map [string ]string {
753
753
"Home" : fmt .Sprintf ("/home/%s.linux" , user .Username ),
754
+ "Name" : filepath .Base (instDir ),
754
755
"UID" : user .Uid ,
755
756
"User" : user .Username ,
756
757
}
@@ -818,7 +819,7 @@ func FillPortForwardDefaults(rule *PortForward, instDir string) {
818
819
}
819
820
}
820
821
if rule .GuestSocket != "" {
821
- if out , err := executeGuestTemplate (rule .GuestSocket ); err == nil {
822
+ if out , err := executeGuestTemplate (rule .GuestSocket , instDir ); err == nil {
822
823
rule .GuestSocket = out .String ()
823
824
} else {
824
825
logrus .WithError (err ).Warnf ("Couldn't process guestSocket %q as a template" , rule .GuestSocket )
@@ -838,7 +839,7 @@ func FillPortForwardDefaults(rule *PortForward, instDir string) {
838
839
839
840
func FillCopyToHostDefaults (rule * CopyToHost , instDir string ) {
840
841
if rule .GuestFile != "" {
841
- if out , err := executeGuestTemplate (rule .GuestFile ); err == nil {
842
+ if out , err := executeGuestTemplate (rule .GuestFile , instDir ); err == nil {
842
843
rule .GuestFile = out .String ()
843
844
} else {
844
845
logrus .WithError (err ).Warnf ("Couldn't process guest %q as a template" , rule .GuestFile )
0 commit comments