2013-07-21 14:32:59 -04:00
|
|
|
package instance
|
|
|
|
|
|
|
|
import (
|
2013-07-24 00:19:44 -04:00
|
|
|
"fmt"
|
2014-07-24 19:30:30 -04:00
|
|
|
|
2015-06-03 17:13:52 -04:00
|
|
|
"github.com/aws/aws-sdk-go/service/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"
|
2015-05-27 14:47:45 -04:00
|
|
|
"github.com/mitchellh/packer/template/interpolate"
|
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
|
|
|
|
}
|
|
|
|
|
2014-07-24 19:30:30 -04:00
|
|
|
type StepBundleVolume struct {
|
|
|
|
Debug bool
|
|
|
|
}
|
2013-07-21 14:32:59 -04:00
|
|
|
|
2013-08-31 16:03:13 -04:00
|
|
|
func (s *StepBundleVolume) Run(state multistep.StateBag) multistep.StepAction {
|
|
|
|
comm := state.Get("communicator").(packer.Communicator)
|
|
|
|
config := state.Get("config").(*Config)
|
|
|
|
instance := state.Get("instance").(*ec2.Instance)
|
|
|
|
ui := state.Get("ui").(packer.Ui)
|
|
|
|
x509RemoteCertPath := state.Get("x509RemoteCertPath").(string)
|
|
|
|
x509RemoteKeyPath := state.Get("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
|
2015-05-27 14:47:45 -04:00
|
|
|
config.ctx.Data = bundleCmdData{
|
2013-07-24 16:41:49 -04:00
|
|
|
AccountId: config.AccountId,
|
2015-04-05 17:58:48 -04:00
|
|
|
Architecture: *instance.Architecture,
|
2013-07-24 16:41:49 -04:00
|
|
|
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,
|
2015-05-27 14:47:45 -04:00
|
|
|
}
|
2015-06-22 12:22:42 -04:00
|
|
|
config.BundleVolCommand, err = interpolate.Render(config.BundleVolCommand, &config.ctx)
|
2013-08-08 18:27:12 -04:00
|
|
|
if err != nil {
|
|
|
|
err := fmt.Errorf("Error processing bundle volume 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-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
|
2014-07-24 19:30:30 -04:00
|
|
|
|
|
|
|
if s.Debug {
|
|
|
|
ui.Say(fmt.Sprintf("Running: %s", config.BundleVolCommand))
|
|
|
|
}
|
|
|
|
|
2013-07-24 16:41:49 -04:00
|
|
|
if err := cmd.StartWithUi(comm, ui); err != nil {
|
2013-08-31 16:03:13 -04:00
|
|
|
state.Put("error", fmt.Errorf("Error bundling volume: %s", err))
|
|
|
|
ui.Error(state.Get("error").(error).Error())
|
2013-07-24 16:41:49 -04:00
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
2013-07-24 16:44:58 -04:00
|
|
|
if cmd.ExitStatus != 0 {
|
2013-08-31 16:03:13 -04:00
|
|
|
state.Put("error", fmt.Errorf(
|
|
|
|
"Volume bundling failed. Please see the output above for more\n"+
|
|
|
|
"details on what went wrong."))
|
|
|
|
ui.Error(state.Get("error").(error).Error())
|
2013-07-24 16:44:58 -04:00
|
|
|
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-08-31 16:03:13 -04:00
|
|
|
state.Put("manifest_name", manifestName)
|
|
|
|
state.Put("manifest_path", fmt.Sprintf(
|
|
|
|
"%s/%s", config.BundleDestination, manifestName))
|
2013-07-25 00:51:46 -04:00
|
|
|
|
2013-07-21 14:32:59 -04:00
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
2013-08-31 16:03:13 -04:00
|
|
|
func (s *StepBundleVolume) Cleanup(multistep.StateBag) {}
|