Skip to content

Commit

Permalink
Introduce "always_pull" option (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
edigaryev authored Oct 4, 2024
1 parent 798502c commit 15f99fa
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
1 change: 1 addition & 0 deletions .web-docs/components/builder/tart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ For more advanced examples, please refer to the [`example/` directory](https://g
#### Optional:

- `allow_insecure` (boolean) — When cloning the image, connect to the OCI registry via an insecure HTTP protocol.
- `always_pull` (boolean) — Always do a `tart pull` before `tart clone` to have an up-to-date image before building.
- `pull_concurrency` (boolean) — Amount of layers to pull concurrently from an OCI registry when pulling the image. Default is 4 for Tart 2.0.0+.
- `cpu_count` (number) - Amount of virtual CPUs to use for the new VM. Overrides `tart create` default value when using `from_ipsw` and `from_iso` and VM settings when using `vm_base_name`.
- `create_grace_time` (duration string | ex: "1h5m2s") — Time to wait after finishing the installation process. Can be used to work around the issue when Virtualization.Framework's installation process is still running in the background for some time after `tart create` had already finished.
Expand Down
1 change: 1 addition & 0 deletions builder/tart/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type Config struct {
VMBaseName string `mapstructure:"vm_base_name"`
VMName string `mapstructure:"vm_name"`
AllowInsecure bool `mapstructure:"allow_insecure"`
AlwaysPull bool `mapstructure:"always_pull"`
PullConcurrency uint16 `mapstructure:"pull_concurrency"`

CpuCount uint8 `mapstructure:"cpu_count"`
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.

26 changes: 21 additions & 5 deletions builder/tart/step_clone_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,34 @@ func (s *stepCloneVM) Run(ctx context.Context, state multistep.StateBag) multist
config := state.Get("config").(*Config)
ui := state.Get("ui").(packersdk.Ui)

ui.Say("Cloning virtual machine...")

cmdArgs := []string{"clone", config.VMBaseName, config.VMName}
var commonArgs []string

if config.AllowInsecure {
cmdArgs = append(cmdArgs, "--insecure")
commonArgs = append(commonArgs, "--insecure")
}

if config.PullConcurrency > 0 {
cmdArgs = append(cmdArgs, "--concurrency", fmt.Sprintf("%d", config.PullConcurrency))
commonArgs = append(commonArgs, "--concurrency", fmt.Sprintf("%d", config.PullConcurrency))
}

if config.AlwaysPull {
ui.Say("Pulling virtual machine...")

cmdArgs := []string{"pull", config.VMBaseName}
cmdArgs = append(cmdArgs, commonArgs...)

if _, err := TartExec(ctx, ui, cmdArgs...); err != nil {
err := fmt.Errorf("Error pulling VM: %s", err)
state.Put("error", err)
return multistep.ActionHalt
}
}

ui.Say("Cloning virtual machine...")

cmdArgs := []string{"clone", config.VMBaseName, config.VMName}
cmdArgs = append(cmdArgs, commonArgs...)

if _, err := TartExec(ctx, ui, cmdArgs...); err != nil {
err := fmt.Errorf("Error cloning VM: %s", err)
state.Put("error", 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 @@ -55,6 +55,7 @@ For more advanced examples, please refer to the [`example/` directory](https://g
#### Optional:

- `allow_insecure` (boolean) — When cloning the image, connect to the OCI registry via an insecure HTTP protocol.
- `always_pull` (boolean) — Always do a `tart pull` before `tart clone` to have an up-to-date image before building.
- `pull_concurrency` (boolean) — Amount of layers to pull concurrently from an OCI registry when pulling the image. Default is 4 for Tart 2.0.0+.
- `cpu_count` (number) - Amount of virtual CPUs to use for the new VM. Overrides `tart create` default value when using `from_ipsw` and `from_iso` and VM settings when using `vm_base_name`.
- `create_grace_time` (duration string | ex: "1h5m2s") — Time to wait after finishing the installation process. Can be used to work around the issue when Virtualization.Framework's installation process is still running in the background for some time after `tart create` had already finished.
Expand Down

0 comments on commit 15f99fa

Please sign in to comment.