github.com/sneal/packer@v0.5.2/builder/amazon/instance/step_bundle_volume.go (about)

     1  package instance
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/mitchellh/goamz/ec2"
     6  	"github.com/mitchellh/multistep"
     7  	"github.com/mitchellh/packer/packer"
     8  )
     9  
    10  type bundleCmdData struct {
    11  	AccountId    string
    12  	Architecture string
    13  	CertPath     string
    14  	Destination  string
    15  	KeyPath      string
    16  	Prefix       string
    17  	PrivatePath  string
    18  }
    19  
    20  type StepBundleVolume struct{}
    21  
    22  func (s *StepBundleVolume) Run(state multistep.StateBag) multistep.StepAction {
    23  	comm := state.Get("communicator").(packer.Communicator)
    24  	config := state.Get("config").(*Config)
    25  	instance := state.Get("instance").(*ec2.Instance)
    26  	ui := state.Get("ui").(packer.Ui)
    27  	x509RemoteCertPath := state.Get("x509RemoteCertPath").(string)
    28  	x509RemoteKeyPath := state.Get("x509RemoteKeyPath").(string)
    29  
    30  	// Bundle the volume
    31  	var err error
    32  	config.BundleVolCommand, err = config.tpl.Process(config.BundleVolCommand, bundleCmdData{
    33  		AccountId:    config.AccountId,
    34  		Architecture: instance.Architecture,
    35  		CertPath:     x509RemoteCertPath,
    36  		Destination:  config.BundleDestination,
    37  		KeyPath:      x509RemoteKeyPath,
    38  		Prefix:       config.BundlePrefix,
    39  		PrivatePath:  config.X509UploadPath,
    40  	})
    41  	if err != nil {
    42  		err := fmt.Errorf("Error processing bundle volume command: %s", err)
    43  		state.Put("error", err)
    44  		ui.Error(err.Error())
    45  		return multistep.ActionHalt
    46  	}
    47  
    48  	ui.Say("Bundling the volume...")
    49  	cmd := new(packer.RemoteCmd)
    50  	cmd.Command = config.BundleVolCommand
    51  	if err := cmd.StartWithUi(comm, ui); err != nil {
    52  		state.Put("error", fmt.Errorf("Error bundling volume: %s", err))
    53  		ui.Error(state.Get("error").(error).Error())
    54  		return multistep.ActionHalt
    55  	}
    56  
    57  	if cmd.ExitStatus != 0 {
    58  		state.Put("error", fmt.Errorf(
    59  			"Volume bundling failed. Please see the output above for more\n"+
    60  				"details on what went wrong."))
    61  		ui.Error(state.Get("error").(error).Error())
    62  		return multistep.ActionHalt
    63  	}
    64  
    65  	// Store the manifest path
    66  	manifestName := config.BundlePrefix + ".manifest.xml"
    67  	state.Put("manifest_name", manifestName)
    68  	state.Put("manifest_path", fmt.Sprintf(
    69  		"%s/%s", config.BundleDestination, manifestName))
    70  
    71  	return multistep.ActionContinue
    72  }
    73  
    74  func (s *StepBundleVolume) Cleanup(multistep.StateBag) {}