Skip to content

Commit

Permalink
retry script upload
Browse files Browse the repository at this point in the history
  • Loading branch information
feiyushi committed Jul 30, 2021
1 parent a280561 commit c94c097
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions update/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
}

func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, _ map[string]interface{}) error {
uploadTimeout := 5 * time.Minute
ui.Say("Uploading the Windows update elevated script...")
var buffer bytes.Buffer
err := elevatedTemplate.Execute(&buffer, elevatedOptions{
Expand All @@ -125,10 +126,15 @@ func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.C
fmt.Printf("Error creating elevated template: %s", err)
return err
}
err = comm.Upload(
elevatedPath,
bytes.NewReader(buffer.Bytes()),
nil)
err = retry.Config{StartTimeout: uploadTimeout}.Run(ctx, func(context.Context) error {
if err := comm.Upload(
elevatedPath,
bytes.NewReader(buffer.Bytes()),
nil); err != nil {
return fmt.Errorf("Error uploading the Windows update elevated script: %s", err)
}
return nil
})
if err != nil {
return err
}
Expand All @@ -146,10 +152,15 @@ func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.C
fmt.Printf("Error creating elevated template: %s", err)
return err
}
err = comm.Upload(
pendingRebootElevatedPath,
bytes.NewReader(buffer.Bytes()),
nil)
err = retry.Config{StartTimeout: uploadTimeout}.Run(ctx, func(context.Context) error {
if err := comm.Upload(
pendingRebootElevatedPath,
bytes.NewReader(buffer.Bytes()),
nil); err != nil {
return fmt.Errorf("Error uploading the Windows update check for reboot required elevated script: %s", err)
}
return nil
})
if err != nil {
return err
}
Expand Down

0 comments on commit c94c097

Please sign in to comment.