2015-12-22 15:56:33 +01:00
|
|
|
package lxc
|
|
|
|
|
|
|
|
import (
|
2018-01-22 15:32:33 -08:00
|
|
|
"context"
|
|
|
|
"log"
|
|
|
|
|
2018-01-19 16:18:44 -08:00
|
|
|
"github.com/hashicorp/packer/helper/multistep"
|
2017-09-05 15:23:22 -07:00
|
|
|
"github.com/hashicorp/packer/packer"
|
2015-12-22 15:56:33 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// StepProvision provisions the instance within a chroot.
|
2016-05-25 19:34:51 +00:00
|
|
|
type StepProvision struct{}
|
2015-12-22 15:56:33 +01:00
|
|
|
|
2018-01-22 15:31:41 -08:00
|
|
|
func (s *StepProvision) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
2015-12-22 15:56:33 +01:00
|
|
|
hook := state.Get("hook").(packer.Hook)
|
|
|
|
config := state.Get("config").(*Config)
|
|
|
|
mountPath := state.Get("mount_path").(string)
|
|
|
|
ui := state.Get("ui").(packer.Ui)
|
|
|
|
wrappedCommand := state.Get("wrappedCommand").(CommandWrapper)
|
|
|
|
|
|
|
|
// Create our communicator
|
|
|
|
comm := &LxcAttachCommunicator{
|
|
|
|
ContainerName: config.ContainerName,
|
2017-10-30 21:48:43 -04:00
|
|
|
AttachOptions: config.AttachOptions,
|
2015-12-22 15:56:33 +01:00
|
|
|
RootFs: 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 *StepProvision) Cleanup(state multistep.StateBag) {}
|