mirror of
https://github.com/hashicorp/packer.git
synced 2026-03-14 22:53:36 -04:00
- Startup scripts can be provided through the instance creation metadata field 'startup-script'. - Script log can be copied to a GCS location by setting the metadata field 'startup-script-log-dest'. Added Retry method to googlecompute package. Added GetSerialPortOutput to googlecompute Drivers. Added StepWaitInstanceStartup (and associated test) which waits for an instance startup-script to finish. Changed the instance service account to use the same service account as the one provided in the Packer config template. It was the project default service account. Tested googlecompute package with 'go test' and also performed builds with a startup script and without a startup script.
47 lines
1.3 KiB
Go
47 lines
1.3 KiB
Go
package googlecompute
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/mitchellh/multistep"
|
|
"github.com/mitchellh/packer/packer"
|
|
)
|
|
|
|
// StepCreateImage represents a Packer build step that creates GCE machine
|
|
// images.
|
|
type StepCreateImage int
|
|
|
|
// Run executes the Packer build step that creates a GCE machine image.
|
|
//
|
|
// The image is created from the persistent disk used by the instance. The
|
|
// instance must be deleted and the disk retained before doing this step.
|
|
func (s *StepCreateImage) Run(state multistep.StateBag) multistep.StepAction {
|
|
config := state.Get("config").(*Config)
|
|
driver := state.Get("driver").(Driver)
|
|
ui := state.Get("ui").(packer.Ui)
|
|
|
|
ui.Say("Creating image...")
|
|
|
|
imageCh, errCh := driver.CreateImage(config.ImageName, config.ImageDescription, config.ImageFamily, config.Zone, config.DiskName)
|
|
var err error
|
|
select {
|
|
case err = <-errCh:
|
|
case <-time.After(config.stateTimeout):
|
|
err = errors.New("time out while waiting for image to register")
|
|
}
|
|
|
|
if err != nil {
|
|
err := fmt.Errorf("Error waiting for image: %s", err)
|
|
state.Put("error", err)
|
|
ui.Error(err.Error())
|
|
return multistep.ActionHalt
|
|
}
|
|
|
|
state.Put("image", <-imageCh)
|
|
return multistep.ActionContinue
|
|
}
|
|
|
|
// Cleanup.
|
|
func (s *StepCreateImage) Cleanup(state multistep.StateBag) {}
|