From 06f54e56289def98b201cf083c54bc9113953846 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Fri, 3 Oct 2025 17:16:35 -0400 Subject: [PATCH] engine: resources: Virt builder needs HOME sometimes Seems this is new or got pulled in automatically somehow. This fixes: virt-builder: error: ssh-inject: $HOME environment variable is not set --- engine/resources/virt_builder.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/engine/resources/virt_builder.go b/engine/resources/virt_builder.go index 6faf2c80..6652b3c7 100644 --- a/engine/resources/virt_builder.go +++ b/engine/resources/virt_builder.go @@ -36,6 +36,7 @@ import ( "net/url" "os" "os/exec" + "os/user" "path" "path/filepath" "runtime" @@ -621,6 +622,15 @@ func (obj *VirtBuilderRes) CheckApply(ctx context.Context, apply bool) (bool, er cmd := exec.CommandContext(ctx, cmdName, cmdArgs...) + usr, err := user.Current() + if err != nil { + return false, err + } + // FIXME: consider building this from an empty environment? + cmd.Env = append(os.Environ(), + fmt.Sprintf("HOME=%s", usr.HomeDir), + ) + // ignore signals sent to parent process (we're in our own group) cmd.SysProcAttr = &syscall.SysProcAttr{ Setpgid: true, @@ -638,7 +648,7 @@ func (obj *VirtBuilderRes) CheckApply(ctx context.Context, apply bool) (bool, er return false, errwrap.Wrapf(err, "error starting cmd") } - err := cmd.Wait() // we can unblock this with the timeout + cmderr := cmd.Wait() // we can unblock this with the timeout out := b.String() p := path.Join(obj.varDir, fmt.Sprintf("%d.log", start)) @@ -648,7 +658,7 @@ func (obj *VirtBuilderRes) CheckApply(ctx context.Context, apply bool) (bool, er } } - if err == nil { + if cmderr == nil { obj.init.Logf("built image successfully!") return false, nil // success! } @@ -667,7 +677,7 @@ func (obj *VirtBuilderRes) CheckApply(ctx context.Context, apply bool) (bool, er obj.init.Logf("deleted partial output") } - exitErr, ok := err.(*exec.ExitError) // embeds an os.ProcessState + exitErr, ok := cmderr.(*exec.ExitError) // embeds an os.ProcessState if !ok { // command failed in some bad way return false, errwrap.Wrapf(err, "cmd failed in some bad way")