2013-07-25 00:29:21 -04:00
|
|
|
package instance
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/mitchellh/multistep"
|
|
|
|
"github.com/mitchellh/packer/packer"
|
|
|
|
)
|
|
|
|
|
|
|
|
type uploadCmdData struct {
|
|
|
|
AccessKey string
|
|
|
|
BucketName string
|
|
|
|
BundleDirectory string
|
|
|
|
ManifestPath string
|
|
|
|
SecretKey string
|
|
|
|
}
|
|
|
|
|
|
|
|
type StepUploadBundle struct{}
|
|
|
|
|
2013-08-31 16:03:13 -04:00
|
|
|
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)
|
2013-07-25 00:29:21 -04:00
|
|
|
|
2013-08-08 18:27:12 -04:00
|
|
|
var err error
|
|
|
|
config.BundleUploadCommand, err = config.tpl.Process(config.BundleUploadCommand, uploadCmdData{
|
2013-07-25 00:29:21 -04:00
|
|
|
AccessKey: config.AccessKey,
|
|
|
|
BucketName: config.S3Bucket,
|
|
|
|
BundleDirectory: config.BundleDestination,
|
2013-07-25 00:51:46 -04:00
|
|
|
ManifestPath: manifestPath,
|
|
|
|
SecretKey: config.SecretKey,
|
2013-08-08 18:27:12 -04:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
err := fmt.Errorf("Error processing bundle upload command: %s", err)
|
2013-08-31 16:03:13 -04:00
|
|
|
state.Put("error", err)
|
2013-08-08 18:27:12 -04:00
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
2013-07-25 00:29:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
ui.Say("Uploading the bundle...")
|
2013-08-08 18:27:12 -04:00
|
|
|
cmd := &packer.RemoteCmd{Command: config.BundleUploadCommand}
|
2013-07-25 00:29:21 -04:00
|
|
|
if err := cmd.StartWithUi(comm, ui); err != nil {
|
2013-08-31 16:03:13 -04:00
|
|
|
state.Put("error", fmt.Errorf("Error uploading volume: %s", err))
|
|
|
|
ui.Error(state.Get("error").(error).Error())
|
2013-07-25 00:29:21 -04:00
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
if cmd.ExitStatus != 0 {
|
2013-08-31 16:03:13 -04:00
|
|
|
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())
|
2013-07-25 00:29:21 -04:00
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
2013-08-31 16:03:13 -04:00
|
|
|
state.Put("remote_manifest_path", fmt.Sprintf(
|
|
|
|
"%s/%s", config.S3Bucket, manifestName))
|
2013-07-25 01:19:04 -04:00
|
|
|
|
2013-07-25 00:29:21 -04:00
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
2013-08-31 16:03:13 -04:00
|
|
|
func (s *StepUploadBundle) Cleanup(state multistep.StateBag) {}
|