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"
|
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)
|
2013-09-30 12:33:57 -04:00
|
|
|
wrappedCommand := state.Get("wrappedCommand").(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
|
|
|
}
|
|
|
|
|
|
|
|
// Provision
|
|
|
|
log.Println("Running the provision hook")
|
2019-03-22 09:53:28 -04:00
|
|
|
if err := hook.Run(ctx, packer.HookProvision, ui, comm, nil); 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) {}
|