Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce "create_grace_time" option #26

Merged
merged 2 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions builder/tart/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/hashicorp/packer-plugin-sdk/template/config"
"github.com/hashicorp/packer-plugin-sdk/template/interpolate"
"time"
)

const BuilderId = "tart.builder"
Expand All @@ -30,6 +31,7 @@ type Config struct {
Display string `mapstructure:"display" required:"false"`
DiskSizeGb uint16 `mapstructure:"disk_size_gb" required:"false"`
Headless bool `mapstructure:"headless" required:"false"`
CreateGraceTime time.Duration `mapstructure:"create_grace_time" required:"false"`
Comm communicator.Config `mapstructure:",squash"`

ctx interpolate.Context
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.

8 changes: 8 additions & 0 deletions builder/tart/step_create_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/hashicorp/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"strconv"
"time"
)

type stepCreateVM struct{}
Expand Down Expand Up @@ -34,6 +35,13 @@ func (s *stepCreateVM) Run(ctx context.Context, state multistep.StateBag) multis
return multistep.ActionHalt
}

if config.CreateGraceTime != 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we always wait if that seems the case? Why we need to configure it? Or maybe set some default timeout?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there's a golden value that we can hardcode for this racy situation. Some people might want it as short as possible, some might want it to be rather large to be on the safe side.

I'd suggest we leave as for now and see how well it works out in https://github.com/cirruslabs/macos-image-templates.

message := fmt.Sprintf("Waiting %v to let the Virtualization.Framework's installation process "+
"to finish correctly...", config.CreateGraceTime)
ui.Say(message)
time.Sleep(config.CreateGraceTime)
}

return multistep.ActionContinue
}

Expand Down