2013-07-30 19:41:29 -04:00
|
|
|
package chroot
|
|
|
|
|
|
|
|
import (
|
2018-01-22 18:32:33 -05:00
|
|
|
"context"
|
2013-07-30 19:41:29 -04:00
|
|
|
"fmt"
|
2018-01-22 18:32:33 -05:00
|
|
|
"log"
|
|
|
|
|
2018-01-19 19:18:44 -05:00
|
|
|
"github.com/hashicorp/packer/helper/multistep"
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/packer"
|
2013-07-30 19:41:29 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// StepEarlyCleanup performs some of the cleanup steps early in order to
|
|
|
|
// prepare for snapshotting and creating an AMI.
|
|
|
|
type StepEarlyCleanup struct{}
|
|
|
|
|
2019-03-29 11:50:02 -04:00
|
|
|
func (s *StepEarlyCleanup) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
2013-08-31 15:58:55 -04:00
|
|
|
ui := state.Get("ui").(packer.Ui)
|
2013-07-30 19:41:29 -04:00
|
|
|
cleanupKeys := []string{
|
|
|
|
"copy_files_cleanup",
|
|
|
|
"mount_extra_cleanup",
|
|
|
|
"mount_device_cleanup",
|
|
|
|
"attach_cleanup",
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, key := range cleanupKeys {
|
2013-08-31 15:58:55 -04:00
|
|
|
c := state.Get(key).(Cleanup)
|
2013-07-30 19:41:29 -04:00
|
|
|
log.Printf("Running cleanup func: %s", key)
|
2013-07-30 20:56:42 -04:00
|
|
|
if err := c.CleanupFunc(state); err != nil {
|
2013-07-30 19:41:29 -04:00
|
|
|
err := fmt.Errorf("Error cleaning up: %s", err)
|
2013-08-31 15:58:55 -04:00
|
|
|
state.Put("error", err)
|
2013-07-30 19:41:29 -04:00
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
2013-08-31 15:58:55 -04:00
|
|
|
func (s *StepEarlyCleanup) Cleanup(state multistep.StateBag) {}
|