builder/digitalocean: add snapshotTimeout option

This commit is contained in:
hbdgr 2019-07-04 16:25:42 +02:00
parent 750e4b0f31
commit 7d723b7c7b
3 changed files with 15 additions and 3 deletions

View File

@ -95,7 +95,9 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
},
new(stepShutdown),
new(stepPowerOff),
new(stepSnapshot),
&stepSnapshot{
snapshotTimeout: b.config.SnapshotTimeout,
},
}
// Run the steps

View File

@ -33,6 +33,7 @@ type Config struct {
SnapshotName string `mapstructure:"snapshot_name"`
SnapshotRegions []string `mapstructure:"snapshot_regions"`
StateTimeout time.Duration `mapstructure:"state_timeout"`
SnapshotTimeout time.Duration `mapstructure:"snapshot_timeout"`
DropletName string `mapstructure:"droplet_name"`
UserData string `mapstructure:"user_data"`
UserDataFile string `mapstructure:"user_data_file"`
@ -88,6 +89,11 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
c.StateTimeout = 6 * time.Minute
}
if c.SnapshotTimeout == 0 {
// Default to 60 minutes timeout, waiting for snapshot action to finish
c.SnapshotTimeout = 60 * time.Minute
}
var errs *packer.MultiError
if es := c.Comm.Prepare(&c.ctx); len(es) > 0 {
errs = packer.MultiErrorAppend(errs, es...)

View File

@ -12,7 +12,9 @@ import (
"github.com/hashicorp/packer/packer"
)
type stepSnapshot struct{}
type stepSnapshot struct {
snapshotTimeout time.Duration
}
func (s *stepSnapshot) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
client := state.Get("client").(*godo.Client)
@ -31,9 +33,11 @@ func (s *stepSnapshot) Run(ctx context.Context, state multistep.StateBag) multis
}
// With the pending state over, verify that we're in the active state
// because action can take a long time and may depend on the size of the final snapshot,
// the timeout is parameterized
ui.Say("Waiting for snapshot to complete...")
if err := waitForActionState(godo.ActionCompleted, dropletId, action.ID,
client, 60*time.Minute); err != nil {
client, s.snapshotTimeout); err != nil {
// If we get an error the first time, actually report it
err := fmt.Errorf("Error waiting for snapshot: %s", err)
state.Put("error", err)