Pause between boot_commands when debugging a Virtualbox build

When debugging a build (or maintaining an existing packer file), teach `packer build -debug` how to step through individual `boot_command`s in order to triage the packer file.
This commit is contained in:
Sean Chittenden 2016-05-17 04:03:45 -04:00
parent 9b3f8a4be9
commit 3ca4782b56
No known key found for this signature in database
GPG Key ID: 4EBC9DC16C2E5E16
3 changed files with 19 additions and 3 deletions

View File

@ -38,11 +38,17 @@ type StepTypeBootCommand struct {
}
func (s *StepTypeBootCommand) Run(state multistep.StateBag) multistep.StepAction {
debug := state.Get("debug").(bool)
driver := state.Get("driver").(Driver)
httpPort := state.Get("http_port").(uint)
ui := state.Get("ui").(packer.Ui)
vmName := state.Get("vmName").(string)
var pauseFn multistep.DebugPauseFn
if debug {
pauseFn = state.Get("pauseFn").(multistep.DebugPauseFn)
}
s.Ctx.Data = &bootCommandTemplateData{
"10.0.2.2",
httpPort,
@ -50,7 +56,7 @@ func (s *StepTypeBootCommand) Run(state multistep.StateBag) multistep.StepAction
}
ui.Say("Typing the boot command...")
for _, command := range s.BootCommand {
for i, command := range s.BootCommand {
command, err := interpolate.Render(command, &s.Ctx)
if err != nil {
err := fmt.Errorf("Error preparing boot command: %s", err)
@ -81,6 +87,10 @@ func (s *StepTypeBootCommand) Run(state multistep.StateBag) multistep.StepAction
return multistep.ActionHalt
}
if pauseFn != nil {
pauseFn(multistep.DebugLocationAfterRun, fmt.Sprintf("boot_command[%d]: %s", i, command), state)
}
if err := driver.VBoxManage("controlvm", vmName, "keyboardputscancode", code); err != nil {
err := fmt.Errorf("Error sending boot command: %s", err)
state.Put("error", err)

View File

@ -268,15 +268,18 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
state := new(multistep.BasicStateBag)
state.Put("cache", cache)
state.Put("config", &b.config)
state.Put("debug", b.config.PackerDebug)
state.Put("driver", driver)
state.Put("hook", hook)
state.Put("ui", ui)
// Run
if b.config.PackerDebug {
pauseFn := common.MultistepDebugFn(ui)
state.Put("pauseFn", pauseFn)
b.runner = &multistep.DebugRunner{
Steps: steps,
PauseFn: common.MultistepDebugFn(ui),
PauseFn: pauseFn,
}
} else {
b.runner = &multistep.BasicRunner{Steps: steps}

View File

@ -42,6 +42,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
// Set up the state.
state := new(multistep.BasicStateBag)
state.Put("config", b.config)
state.Put("debug", b.config.PackerDebug)
state.Put("driver", driver)
state.Put("cache", cache)
state.Put("hook", hook)
@ -134,9 +135,11 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
// Run the steps.
if b.config.PackerDebug {
pauseFn := common.MultistepDebugFn(ui)
state.Put("pauseFn", pauseFn)
b.runner = &multistep.DebugRunner{
Steps: steps,
PauseFn: common.MultistepDebugFn(ui),
PauseFn: pauseFn,
}
} else {
b.runner = &multistep.BasicRunner{Steps: steps}