2013-07-21 14:32:59 -04:00
|
|
|
package instance
|
|
|
|
|
|
|
|
import (
|
2013-07-24 00:19:44 -04:00
|
|
|
"fmt"
|
2013-07-24 16:41:49 -04:00
|
|
|
"github.com/mitchellh/goamz/ec2"
|
2013-07-21 14:32:59 -04:00
|
|
|
"github.com/mitchellh/multistep"
|
2013-07-24 00:19:44 -04:00
|
|
|
"github.com/mitchellh/packer/packer"
|
2013-07-21 14:32:59 -04:00
|
|
|
)
|
|
|
|
|
2013-07-24 16:41:49 -04:00
|
|
|
type bundleCmdData struct {
|
|
|
|
AccountId string
|
|
|
|
Architecture string
|
|
|
|
CertPath string
|
2013-07-25 00:22:16 -04:00
|
|
|
Destination string
|
2013-07-24 16:41:49 -04:00
|
|
|
KeyPath string
|
2013-07-25 00:22:16 -04:00
|
|
|
Prefix string
|
2013-07-24 16:41:49 -04:00
|
|
|
PrivatePath string
|
|
|
|
}
|
|
|
|
|
2013-07-21 14:32:59 -04:00
|
|
|
type StepBundleVolume struct{}
|
|
|
|
|
|
|
|
func (s *StepBundleVolume) Run(state map[string]interface{}) multistep.StepAction {
|
2013-07-24 00:19:44 -04:00
|
|
|
comm := state["communicator"].(packer.Communicator)
|
2013-07-24 16:41:49 -04:00
|
|
|
config := state["config"].(*Config)
|
|
|
|
instance := state["instance"].(*ec2.Instance)
|
2013-07-24 00:19:44 -04:00
|
|
|
ui := state["ui"].(packer.Ui)
|
2013-07-24 16:41:49 -04:00
|
|
|
x509RemoteCertPath := state["x509RemoteCertPath"].(string)
|
|
|
|
x509RemoteKeyPath := state["x509RemoteKeyPath"].(string)
|
2013-07-24 00:19:44 -04:00
|
|
|
|
2013-07-24 16:41:49 -04:00
|
|
|
// Bundle the volume
|
2013-08-08 18:27:12 -04:00
|
|
|
var err error
|
|
|
|
config.BundleVolCommand, err = config.tpl.Process(config.BundleVolCommand, bundleCmdData{
|
2013-07-24 16:41:49 -04:00
|
|
|
AccountId: config.AccountId,
|
|
|
|
Architecture: instance.Architecture,
|
|
|
|
CertPath: x509RemoteCertPath,
|
2013-07-25 00:22:16 -04:00
|
|
|
Destination: config.BundleDestination,
|
2013-07-24 16:41:49 -04:00
|
|
|
KeyPath: x509RemoteKeyPath,
|
2013-08-08 18:27:12 -04:00
|
|
|
Prefix: config.BundlePrefix,
|
2013-07-24 16:41:49 -04:00
|
|
|
PrivatePath: config.X509UploadPath,
|
2013-08-08 18:27:12 -04:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
err := fmt.Errorf("Error processing bundle volume command: %s", err)
|
|
|
|
state["error"] = err
|
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
2013-07-24 16:41:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
ui.Say("Bundling the volume...")
|
2013-08-23 18:53:54 -04:00
|
|
|
cmd := new(packer.RemoteCmd)
|
2013-08-08 18:27:12 -04:00
|
|
|
cmd.Command = config.BundleVolCommand
|
2013-07-24 16:41:49 -04:00
|
|
|
if err := cmd.StartWithUi(comm, ui); err != nil {
|
|
|
|
state["error"] = fmt.Errorf("Error bundling volume: %s", err)
|
|
|
|
ui.Error(state["error"].(error).Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
2013-07-24 16:44:58 -04:00
|
|
|
if cmd.ExitStatus != 0 {
|
|
|
|
state["error"] = fmt.Errorf(
|
|
|
|
"Volume bundling failed. Please see the output above for more\n" +
|
|
|
|
"details on what went wrong.")
|
|
|
|
ui.Error(state["error"].(error).Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
2013-07-25 00:51:46 -04:00
|
|
|
// Store the manifest path
|
2013-08-08 18:27:12 -04:00
|
|
|
manifestName := config.BundlePrefix + ".manifest.xml"
|
2013-07-25 01:19:04 -04:00
|
|
|
state["manifest_name"] = manifestName
|
2013-07-25 00:51:46 -04:00
|
|
|
state["manifest_path"] = fmt.Sprintf(
|
2013-07-25 01:19:04 -04:00
|
|
|
"%s/%s", config.BundleDestination, manifestName)
|
2013-07-25 00:51:46 -04:00
|
|
|
|
2013-07-21 14:32:59 -04:00
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StepBundleVolume) Cleanup(map[string]interface{}) {}
|