Skip to content

Commit

Permalink
fixup! Add boot steps configuration option
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-carlborg committed Nov 7, 2022
1 parent e00cc19 commit 322ce49
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 2 deletions.
39 changes: 39 additions & 0 deletions builder/qemu/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,45 @@ type Config struct {
// * ARM: tpm-tis-device
// * PPC (p-series): tpm-spapr
TPMType string `mapstructure:"tpm_device_type" required:"false"`
// This is an array of tuples of boot commands, to type when the virtual
// machine is booted. The first element of the tuple is the actual boot
// command. The second element of the tuple, which is optional, is a
// description of what the boot command does. This is intended to be used for
// interactive installers that requires many commands to complete the
// installation. Both the command and the description will be printed when
// logging is enabled. When debug mode is enabled Packer will pause after
// typing each boot command. This will make it easier to follow along the
// installation process and make sure the Packer and the installer are in
// sync. `boot_steps` and `boot_commands` are mutually exclusive.
//
// Example:
//
// In HCL:
// ```hcl
// boot_steps = [
// ["1<enter><wait5>", "Install NetBSD"],
// ["a<enter><wait5>", "Installation messages in English"],
// ["a<enter><wait5>", "Keyboard type: unchanged"],
//
// ["a<enter><wait5>", "Install NetBSD to hard disk"],
// ["b<enter><wait5>", "Yes"]
// ]
// ```
//
// In JSON:
// ```json
// {
// "boot_steps": [
// ["1<enter><wait5>", "Install NetBSD"],
// ["a<enter><wait5>", "Installation messages in English"],
// ["a<enter><wait5>", "Keyboard type: unchanged"],
//
// ["a<enter><wait5>", "Install NetBSD to hard disk"],
// ["b<enter><wait5>", "Yes"]
// ]
// }
// ```
BootSteps [][]string `mapstructure:"boot_steps" required:"false"`

// TODO(mitchellh): deprecate
RunOnce bool `mapstructure:"run_once"`
Expand Down
4 changes: 2 additions & 2 deletions builder/qemu/config.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions builder/qemu/step_type_boot_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,17 @@ type bootCommandTemplateData struct {
type stepTypeBootCommand struct{}

func (s *stepTypeBootCommand) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packersdk.Ui)
config := state.Get("config").(*Config)
command := config.VNCConfig.FlatBootCommand()
bootSteps := config.BootSteps

if len(command) > 0 && len(bootSteps) > 0 {
err := fmt.Errorf("Both boot command and boot steps cannot be used.")
ui.Error(err.Error())
return multistep.ActionHalt
}

if len(command) > 0 {
bootSteps = [][]string{{command}}
}
Expand Down
39 changes: 39 additions & 0 deletions docs-partials/builder/qemu/Config-not-required.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -350,4 +350,43 @@
* ARM: tpm-tis-device
* PPC (p-series): tpm-spapr
- `boot_steps` ([][]string) - This is an array of tuples of boot commands, to type when the virtual
machine is booted. The first element of the tuple is the actual boot
command. The second element of the tuple, which is optional, is a
description of what the boot command does. This is intended to be used for
interactive installers that requires many commands to complete the
installation. Both the command and the description will be printed when
logging is enabled. When debug mode is enabled Packer will pause after
typing each boot command. This will make it easier to follow along the
installation process and make sure the Packer and the installer are in
sync. `boot_steps` and `boot_commands` are mutually exclusive.
Example:
In HCL:
```hcl
boot_steps = [
["1<enter><wait5>", "Install NetBSD"],
["a<enter><wait5>", "Installation messages in English"],
["a<enter><wait5>", "Keyboard type: unchanged"],

["a<enter><wait5>", "Install NetBSD to hard disk"],
["b<enter><wait5>", "Yes"]
]
```
In JSON:
```json
{
"boot_steps": [
["1<enter><wait5>", "Install NetBSD"],
["a<enter><wait5>", "Installation messages in English"],
["a<enter><wait5>", "Keyboard type: unchanged"],

["a<enter><wait5>", "Install NetBSD to hard disk"],
["b<enter><wait5>", "Yes"]
]
}
```
<!-- End of code generated from the comments of the Config struct in builder/qemu/config.go; -->

0 comments on commit 322ce49

Please sign in to comment.