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

46 lines
1.2 KiB
Go
Raw Normal View History

package chroot
import (
2018-01-22 15:32:33 -08:00
"context"
2017-03-28 18:02:51 -07:00
"log"
"github.com/hashicorp/packer/common"
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"
)
// StepChrootProvision provisions the instance within a chroot.
type StepChrootProvision struct {
}
func (s *StepChrootProvision) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
2013-08-31 12:58:55 -07:00
hook := state.Get("hook").(packer.Hook)
mountPath := state.Get("mount_path").(string)
ui := state.Get("ui").(packer.Ui)
wrappedCommand := state.Get("wrappedCommand").(common.CommandWrapper)
// Create our communicator
comm := &Communicator{
2013-09-30 09:33:57 -07:00
Chroot: mountPath,
CmdWrapper: wrappedCommand,
}
// Loads hook data from builder's state, if it has been set.
hookData := common.PopulateProvisionHookData(state)
// Update state generated_data with complete hookData
// to make them accessible by post-processors
state.Put("generated_data", hookData)
// Provision
log.Println("Running the provision hook")
if err := hook.Run(ctx, packer.HookProvision, ui, comm, hookData); err != nil {
2013-08-31 12:58:55 -07:00
state.Put("error", err)
return multistep.ActionHalt
}
return multistep.ActionContinue
}
2013-08-31 12:58:55 -07:00
func (s *StepChrootProvision) Cleanup(state multistep.StateBag) {}