github.com/rothwerx/packer@v0.9.0/builder/amazon/chroot/step_early_cleanup.go (about)

     1  package chroot
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/mitchellh/multistep"
     6  	"github.com/mitchellh/packer/packer"
     7  	"log"
     8  )
     9  
    10  // StepEarlyCleanup performs some of the cleanup steps early in order to
    11  // prepare for snapshotting and creating an AMI.
    12  type StepEarlyCleanup struct{}
    13  
    14  func (s *StepEarlyCleanup) Run(state multistep.StateBag) multistep.StepAction {
    15  	ui := state.Get("ui").(packer.Ui)
    16  	cleanupKeys := []string{
    17  		"copy_files_cleanup",
    18  		"mount_extra_cleanup",
    19  		"mount_device_cleanup",
    20  		"attach_cleanup",
    21  	}
    22  
    23  	for _, key := range cleanupKeys {
    24  		c := state.Get(key).(Cleanup)
    25  		log.Printf("Running cleanup func: %s", key)
    26  		if err := c.CleanupFunc(state); err != nil {
    27  			err := fmt.Errorf("Error cleaning up: %s", err)
    28  			state.Put("error", err)
    29  			ui.Error(err.Error())
    30  			return multistep.ActionHalt
    31  		}
    32  	}
    33  
    34  	return multistep.ActionContinue
    35  }
    36  
    37  func (s *StepEarlyCleanup) Cleanup(state multistep.StateBag) {}