/cc @mwhooker - I changed the interface up a bit to return an error, since things should return errors in Go (the ui.Error bit was kind of ghetto because it had no way to bubble that error up except through the UI). Using this, I made it so that the communicator uses both a CommandWrapper and ShellCommand with chroot so that the chroot commannd is also wrapped (it wasn't before). I think the functionality of all this is the same but I'd love if you could look it over and make sure.
37 lines
898 B
Go
37 lines
898 B
Go
package chroot
|
|
|
|
import (
|
|
"github.com/mitchellh/multistep"
|
|
"github.com/mitchellh/packer/packer"
|
|
"log"
|
|
)
|
|
|
|
// StepChrootProvision provisions the instance within a chroot.
|
|
type StepChrootProvision struct {
|
|
mounts []string
|
|
}
|
|
|
|
func (s *StepChrootProvision) Run(state multistep.StateBag) multistep.StepAction {
|
|
hook := state.Get("hook").(packer.Hook)
|
|
mountPath := state.Get("mount_path").(string)
|
|
ui := state.Get("ui").(packer.Ui)
|
|
wrappedCommand := state.Get("wrappedCommand").(CommandWrapper)
|
|
|
|
// Create our communicator
|
|
comm := &Communicator{
|
|
Chroot: mountPath,
|
|
CmdWrapper: wrappedCommand,
|
|
}
|
|
|
|
// Provision
|
|
log.Println("Running the provision hook")
|
|
if err := hook.Run(packer.HookProvision, ui, comm, nil); err != nil {
|
|
state.Put("error", err)
|
|
return multistep.ActionHalt
|
|
}
|
|
|
|
return multistep.ActionContinue
|
|
}
|
|
|
|
func (s *StepChrootProvision) Cleanup(state multistep.StateBag) {}
|