From 8599425e83fa437569f2635145170dda15b81570 Mon Sep 17 00:00:00 2001 From: fedor Date: Tue, 6 Feb 2024 13:39:36 -0500 Subject: [PATCH] Allow to configure `--concurrency` for pulling --- builder/tart/builder.go | 11 ++++++----- builder/tart/builder.hcl2spec.go | 2 ++ builder/tart/step_clone_vm.go | 4 ++++ docs/builders/tart.mdx | 1 + 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/builder/tart/builder.go b/builder/tart/builder.go index fe14872..71e83cf 100644 --- a/builder/tart/builder.go +++ b/builder/tart/builder.go @@ -26,11 +26,12 @@ type Config struct { commonsteps.HTTPConfig `mapstructure:",squash"` CommunicatorConfig communicator.Config `mapstructure:",squash"` - FromIPSW string `mapstructure:"from_ipsw"` - FromISO []string `mapstructure:"from_iso"` - VMBaseName string `mapstructure:"vm_base_name"` - VMName string `mapstructure:"vm_name"` - AllowInsecure bool `mapstructure:"allow_insecure"` + FromIPSW string `mapstructure:"from_ipsw"` + FromISO []string `mapstructure:"from_iso"` + VMBaseName string `mapstructure:"vm_base_name"` + VMName string `mapstructure:"vm_name"` + AllowInsecure bool `mapstructure:"allow_insecure"` + PullConcurrency uint16 `mapstructure:"pull_concurrency"` CpuCount uint8 `mapstructure:"cpu_count"` CreateGraceTime time.Duration `mapstructure:"create_grace_time"` diff --git a/builder/tart/builder.hcl2spec.go b/builder/tart/builder.hcl2spec.go index 4e28a2a..041006e 100644 --- a/builder/tart/builder.hcl2spec.go +++ b/builder/tart/builder.hcl2spec.go @@ -83,6 +83,7 @@ type FlatConfig struct { VMBaseName *string `mapstructure:"vm_base_name" cty:"vm_base_name" hcl:"vm_base_name"` VMName *string `mapstructure:"vm_name" cty:"vm_name" hcl:"vm_name"` AllowInsecure *bool `mapstructure:"allow_insecure" cty:"allow_insecure" hcl:"allow_insecure"` + PullConcurrency *uint16 `mapstructure:"pull_concurrency" cty:"pull_concurrency" hcl:"pull_concurrency"` CpuCount *uint8 `mapstructure:"cpu_count" cty:"cpu_count" hcl:"cpu_count"` CreateGraceTime *string `mapstructure:"create_grace_time" cty:"create_grace_time" hcl:"create_grace_time"` DiskSizeGb *uint16 `mapstructure:"disk_size_gb" cty:"disk_size_gb" hcl:"disk_size_gb"` @@ -180,6 +181,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "vm_base_name": &hcldec.AttrSpec{Name: "vm_base_name", Type: cty.String, Required: false}, "vm_name": &hcldec.AttrSpec{Name: "vm_name", Type: cty.String, Required: false}, "allow_insecure": &hcldec.AttrSpec{Name: "allow_insecure", Type: cty.Bool, Required: false}, + "pull_concurrency": &hcldec.AttrSpec{Name: "pull_concurrency", Type: cty.Number, Required: false}, "cpu_count": &hcldec.AttrSpec{Name: "cpu_count", Type: cty.Number, Required: false}, "create_grace_time": &hcldec.AttrSpec{Name: "create_grace_time", Type: cty.String, Required: false}, "disk_size_gb": &hcldec.AttrSpec{Name: "disk_size_gb", Type: cty.Number, Required: false}, diff --git a/builder/tart/step_clone_vm.go b/builder/tart/step_clone_vm.go index ba2241d..e88a4e0 100644 --- a/builder/tart/step_clone_vm.go +++ b/builder/tart/step_clone_vm.go @@ -22,6 +22,10 @@ func (s *stepCloneVM) Run(ctx context.Context, state multistep.StateBag) multist cmdArgs = append(cmdArgs, "--insecure") } + if config.PullConcurrency > 0 { + cmdArgs = append(cmdArgs, "--concurrency", fmt.Sprintf("%d", config.PullConcurrency)) + } + if _, err := TartExec(ctx, cmdArgs...); err != nil { err := fmt.Errorf("Error cloning VM: %s", err) state.Put("error", err) diff --git a/docs/builders/tart.mdx b/docs/builders/tart.mdx index 6499820..e01159e 100644 --- a/docs/builders/tart.mdx +++ b/docs/builders/tart.mdx @@ -39,6 +39,7 @@ Below we'll go through available options of this Packer plugin. ### Optional Configuration - `allow_insecure` (boolean) — When cloning the image, connect to the OCI registry via an insecure HTTP protocol. +- `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. - `disk_size_gb` — Disk size in GB 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`.