mirror of
https://github.com/hashicorp/packer.git
synced 2026-02-24 18:30:41 -05:00
This commit moves the Amazon builders of Packer away from the Hashicorp fork of the goamz library to the official AWS SDK for Go, in order that third party plugins may depend on the more complete official library more easily.
80 lines
2.1 KiB
Go
80 lines
2.1 KiB
Go
package instance
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/mitchellh/multistep"
|
|
"github.com/mitchellh/packer/packer"
|
|
)
|
|
|
|
type uploadCmdData struct {
|
|
AccessKey string
|
|
BucketName string
|
|
BundleDirectory string
|
|
ManifestPath string
|
|
Region string
|
|
SecretKey string
|
|
}
|
|
|
|
type StepUploadBundle struct {
|
|
Debug bool
|
|
}
|
|
|
|
func (s *StepUploadBundle) Run(state multistep.StateBag) multistep.StepAction {
|
|
comm := state.Get("communicator").(packer.Communicator)
|
|
config := state.Get("config").(*Config)
|
|
manifestName := state.Get("manifest_name").(string)
|
|
manifestPath := state.Get("manifest_path").(string)
|
|
ui := state.Get("ui").(packer.Ui)
|
|
|
|
region, err := config.Region()
|
|
if err != nil {
|
|
err := fmt.Errorf("Error retrieving region: %s", err)
|
|
state.Put("error", err)
|
|
ui.Error(err.Error())
|
|
return multistep.ActionHalt
|
|
}
|
|
|
|
config.BundleUploadCommand, err = config.tpl.Process(config.BundleUploadCommand, uploadCmdData{
|
|
AccessKey: config.AccessKey,
|
|
BucketName: config.S3Bucket,
|
|
BundleDirectory: config.BundleDestination,
|
|
ManifestPath: manifestPath,
|
|
Region: region,
|
|
SecretKey: config.SecretKey,
|
|
})
|
|
if err != nil {
|
|
err := fmt.Errorf("Error processing bundle upload command: %s", err)
|
|
state.Put("error", err)
|
|
ui.Error(err.Error())
|
|
return multistep.ActionHalt
|
|
}
|
|
|
|
ui.Say("Uploading the bundle...")
|
|
cmd := &packer.RemoteCmd{Command: config.BundleUploadCommand}
|
|
|
|
if s.Debug {
|
|
ui.Say(fmt.Sprintf("Running: %s", config.BundleUploadCommand))
|
|
}
|
|
|
|
if err := cmd.StartWithUi(comm, ui); err != nil {
|
|
state.Put("error", fmt.Errorf("Error uploading volume: %s", err))
|
|
ui.Error(state.Get("error").(error).Error())
|
|
return multistep.ActionHalt
|
|
}
|
|
|
|
if cmd.ExitStatus != 0 {
|
|
state.Put("error", fmt.Errorf(
|
|
"Bundle upload failed. Please see the output above for more\n"+
|
|
"details on what went wrong."))
|
|
ui.Error(state.Get("error").(error).Error())
|
|
return multistep.ActionHalt
|
|
}
|
|
|
|
state.Put("remote_manifest_path", fmt.Sprintf(
|
|
"%s/%s", config.S3Bucket, manifestName))
|
|
|
|
return multistep.ActionContinue
|
|
}
|
|
|
|
func (s *StepUploadBundle) Cleanup(state multistep.StateBag) {}
|