github.com/jerryclinesmith/packer@v0.3.7/builder/amazon/instance/step_upload_bundle.go (about)

     1  package instance
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/mitchellh/multistep"
     6  	"github.com/mitchellh/packer/packer"
     7  )
     8  
     9  type uploadCmdData struct {
    10  	AccessKey       string
    11  	BucketName      string
    12  	BundleDirectory string
    13  	ManifestPath    string
    14  	SecretKey       string
    15  }
    16  
    17  type StepUploadBundle struct{}
    18  
    19  func (s *StepUploadBundle) Run(state multistep.StateBag) multistep.StepAction {
    20  	comm := state.Get("communicator").(packer.Communicator)
    21  	config := state.Get("config").(*Config)
    22  	manifestName := state.Get("manifest_name").(string)
    23  	manifestPath := state.Get("manifest_path").(string)
    24  	ui := state.Get("ui").(packer.Ui)
    25  
    26  	var err error
    27  	config.BundleUploadCommand, err = config.tpl.Process(config.BundleUploadCommand, uploadCmdData{
    28  		AccessKey:       config.AccessKey,
    29  		BucketName:      config.S3Bucket,
    30  		BundleDirectory: config.BundleDestination,
    31  		ManifestPath:    manifestPath,
    32  		SecretKey:       config.SecretKey,
    33  	})
    34  	if err != nil {
    35  		err := fmt.Errorf("Error processing bundle upload command: %s", err)
    36  		state.Put("error", err)
    37  		ui.Error(err.Error())
    38  		return multistep.ActionHalt
    39  	}
    40  
    41  	ui.Say("Uploading the bundle...")
    42  	cmd := &packer.RemoteCmd{Command: config.BundleUploadCommand}
    43  	if err := cmd.StartWithUi(comm, ui); err != nil {
    44  		state.Put("error", fmt.Errorf("Error uploading volume: %s", err))
    45  		ui.Error(state.Get("error").(error).Error())
    46  		return multistep.ActionHalt
    47  	}
    48  
    49  	if cmd.ExitStatus != 0 {
    50  		state.Put("error", fmt.Errorf(
    51  			"Bundle upload failed. Please see the output above for more\n"+
    52  				"details on what went wrong."))
    53  		ui.Error(state.Get("error").(error).Error())
    54  		return multistep.ActionHalt
    55  	}
    56  
    57  	state.Put("remote_manifest_path", fmt.Sprintf(
    58  		"%s/%s", config.S3Bucket, manifestName))
    59  
    60  	return multistep.ActionContinue
    61  }
    62  
    63  func (s *StepUploadBundle) Cleanup(state multistep.StateBag) {}