Files
Packer-Cn/common/chroot/step_early_cleanup.go
T

40 lines
957 B
Go
Raw Normal View History

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