Skip to content

Commit

Permalink
Support ip_extra_args (cirruslabs#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
fkorotkov authored Sep 19, 2023
1 parent 8f608bd commit ed5b2b3
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
7 changes: 5 additions & 2 deletions builder/tart/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type Config struct {
Recovery bool `mapstructure:"recovery"`
Rosetta string `mapstructure:"rosetta"`
RunExtraArgs []string `mapstructure:"run_extra_args"`
IpExtraArgs []string `mapstructure:"ip_extra_args"`

ctx interpolate.Context
}
Expand Down Expand Up @@ -100,8 +101,10 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
if !b.config.Recovery {
steps = append(steps,
&communicator.StepConnect{
Config: &b.config.CommunicatorConfig,
Host: TartMachineIP(ctx, b.config.VMName),
Config: &b.config.CommunicatorConfig,
Host: func(state multistep.StateBag) (string, error) {
return TartMachineIP(ctx, b.config.VMName, b.config.IpExtraArgs)
},
SSHConfig: b.config.CommunicatorConfig.SSHConfigFunc(),
},
new(stepResize),
Expand Down
2 changes: 2 additions & 0 deletions builder/tart/builder.hcl2spec.go

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

9 changes: 5 additions & 4 deletions builder/tart/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package tart

import (
"context"
"github.com/hashicorp/packer-plugin-sdk/multistep"
)

func TartMachineIP(ctx context.Context, vmName string) func(multistep.StateBag) (string, error) {
return func(state multistep.StateBag) (string, error) {
return TartExec(ctx, "ip", "--wait", "120", vmName)
func TartMachineIP(ctx context.Context, vmName string, ipExtraArgs []string) (string, error) {
ipArgs := []string{"ip", "--wait", "120", vmName}
if len(ipExtraArgs) > 0 {
ipArgs = append(ipArgs, ipExtraArgs...)
}
return TartExec(ctx, ipArgs...)
}
2 changes: 1 addition & 1 deletion builder/tart/step_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func detectHostIP(ctx context.Context, config *Config) (string, error) {
return config.HTTPAddress, nil
}

vmIPRaw, err := TartExec(ctx, "ip", "--wait", "120", config.VMName)
vmIPRaw, err := TartMachineIP(ctx, config.VMName, config.IpExtraArgs)
if err != nil {
return "", fmt.Errorf("%w: while running \"tart ip\": %v",
ErrFailedToDetectHostIP, err)
Expand Down
1 change: 1 addition & 0 deletions docs/builders/tart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Below we'll go through available options of this Packer plugin.
- `recovery` (bool) Whether to boot the VM in recovery mode. Useful for disabling the System Integrity Protection automatically for the already created VMs.
- `rosetta` (string) - Whether to enable Rosetta support of a Linux guest VM. Useful for running non-arm64 binaries in the guest VM. A common used value is `rosetta`, for further details and explanation run `tart run --help`.
- `run_extra_args` (list(string)) - Extra arguments to pass to `tart run` command. For example, you can enable bridged networking by specifying `--net-bridged=en0`.
- `ip_extra_args` (list(string)) - Extra arguments to pass to `tart ip` command. For example, you can use a different resolver in case of bridged network by specifying `--resolver=arp`.
- `vm_base_name` (string) - The name of the VM to be used for the initial cloning. Can be either a local VM or a remote VM that will be pulled from a registry. Mutually exclusive with `from_ipsw` and `from_iso`.

### SSH connection configuration
Expand Down

0 comments on commit ed5b2b3

Please sign in to comment.