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