Skip to content

Commit

Permalink
builder: make transfer timeout configurable.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewsomething committed Feb 13, 2024
1 parent 42849d6 commit e994273
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 19 deletions.
12 changes: 6 additions & 6 deletions .web-docs/components/builder/digitalocean/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,17 @@ each category, the available configuration keys are alphabetized.
and report errors. When false, Packer will initiate the snapshot transfers
and exit successfully without waiting for completion. Defaults to true.

- `transfer_timeout` (duration string | ex: "1h5m2s") - How long to wait for a snapshot to be transferred to an additional region
before timing out. The default transfer timeout is "30m" (valid time units
include `s` for seconds, `m` for minutes, and `h` for hours).

- `state_timeout` (duration string | ex: "1h5m2s") - The time to wait, as a duration string, for a
droplet to enter a desired state (such as "active") before timing out. The
default state timeout is "6m".

- `snapshot_timeout` (duration string | ex: "1h5m2s") - How long to wait for an image to be published to the shared image
gallery before timing out. If your Packer build is failing on the
Publishing to Shared Image Gallery step with the error `Original Error:
context deadline exceeded`, but the image is present when you check your
Azure dashboard, then you probably need to increase this timeout from
its default of "60m" (valid time units include `s` for seconds, `m` for
minutes, and `h` for hours.)
gallery before timing out. The default snapshot timeout is "60m" (valid time
units include `s` for seconds, `m` for minutes, and `h` for hours).

- `droplet_name` (string) - The name assigned to the droplet. DigitalOcean
sets the hostname of the machine to this value.
Expand Down
1 change: 1 addition & 0 deletions builder/digitalocean/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
new(stepPowerOff),
&stepSnapshot{
snapshotTimeout: b.config.SnapshotTimeout,
transferTimeout: b.config.TransferTimeout,
waitForSnapshotTransfer: *b.config.WaitSnapshotTransfer,
},
}
Expand Down
16 changes: 10 additions & 6 deletions builder/digitalocean/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,17 @@ type Config struct {
// and report errors. When false, Packer will initiate the snapshot transfers
// and exit successfully without waiting for completion. Defaults to true.
WaitSnapshotTransfer *bool `mapstructure:"wait_snapshot_transfer" required:"false"`
// How long to wait for a snapshot to be transferred to an additional region
// before timing out. The default transfer timeout is "30m" (valid time units
// include `s` for seconds, `m` for minutes, and `h` for hours).
TransferTimeout time.Duration `mapstructure:"transfer_timeout" required:"false"`
// The time to wait, as a duration string, for a
// droplet to enter a desired state (such as "active") before timing out. The
// default state timeout is "6m".
StateTimeout time.Duration `mapstructure:"state_timeout" required:"false"`
// How long to wait for an image to be published to the shared image
// gallery before timing out. If your Packer build is failing on the
// Publishing to Shared Image Gallery step with the error `Original Error:
// context deadline exceeded`, but the image is present when you check your
// Azure dashboard, then you probably need to increase this timeout from
// its default of "60m" (valid time units include `s` for seconds, `m` for
// minutes, and `h` for hours.)
// gallery before timing out. The default snapshot timeout is "60m" (valid time
// units include `s` for seconds, `m` for minutes, and `h` for hours).
SnapshotTimeout time.Duration `mapstructure:"snapshot_timeout" required:"false"`
// The name assigned to the droplet. DigitalOcean
// sets the hostname of the machine to this value.
Expand Down Expand Up @@ -215,6 +215,10 @@ func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
c.SnapshotTimeout = 60 * time.Minute
}

if c.TransferTimeout == 0 {
c.TransferTimeout = 30 * time.Minute
}

if c.WaitSnapshotTransfer == nil {
c.WaitSnapshotTransfer = godo.PtrTo(true)
}
Expand Down
2 changes: 2 additions & 0 deletions builder/digitalocean/config.hcl2spec.go

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

3 changes: 2 additions & 1 deletion builder/digitalocean/step_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

type stepSnapshot struct {
snapshotTimeout time.Duration
transferTimeout time.Duration
waitForSnapshotTransfer bool
}

Expand Down Expand Up @@ -114,7 +115,7 @@ func (s *stepSnapshot) Run(ctx context.Context, state multistep.StateBag) multis
godo.ActionCompleted,
imageId,
imageTransfer.ID,
client, 20*time.Minute); err != nil {
client, s.transferTimeout); err != nil {
return fmt.Errorf("Error waiting for snapshot transfer: %s", err)
}
ui.Say(fmt.Sprintf("Transfer to %s is complete.", region))
Expand Down
12 changes: 6 additions & 6 deletions docs-partials/builder/digitalocean/Config-not-required.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@
and report errors. When false, Packer will initiate the snapshot transfers
and exit successfully without waiting for completion. Defaults to true.

- `transfer_timeout` (duration string | ex: "1h5m2s") - How long to wait for a snapshot to be transferred to an additional region
before timing out. The default transfer timeout is "30m" (valid time units
include `s` for seconds, `m` for minutes, and `h` for hours).

- `state_timeout` (duration string | ex: "1h5m2s") - The time to wait, as a duration string, for a
droplet to enter a desired state (such as "active") before timing out. The
default state timeout is "6m".

- `snapshot_timeout` (duration string | ex: "1h5m2s") - How long to wait for an image to be published to the shared image
gallery before timing out. If your Packer build is failing on the
Publishing to Shared Image Gallery step with the error `Original Error:
context deadline exceeded`, but the image is present when you check your
Azure dashboard, then you probably need to increase this timeout from
its default of "60m" (valid time units include `s` for seconds, `m` for
minutes, and `h` for hours.)
gallery before timing out. The default snapshot timeout is "60m" (valid time
units include `s` for seconds, `m` for minutes, and `h` for hours).

- `droplet_name` (string) - The name assigned to the droplet. DigitalOcean
sets the hostname of the machine to this value.
Expand Down

0 comments on commit e994273

Please sign in to comment.