github.phpd.cn/hashicorp/packer@v1.3.2/builder/amazon/chroot/step_early_cleanup.go (about)

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