packer-cn/builder/lxc/step_provision.go

48 lines
1.3 KiB
Go
Raw Normal View History

2015-12-22 09:56:33 -05:00
package lxc
import (
"context"
"github.com/hashicorp/packer/common"
"log"
"github.com/hashicorp/packer/helper/multistep"
2017-09-05 18:23:22 -04:00
"github.com/hashicorp/packer/packer"
2015-12-22 09:56:33 -05:00
)
// StepProvision provisions the instance within a chroot.
2016-05-25 15:34:51 -04:00
type StepProvision struct{}
2015-12-22 09:56:33 -05:00
func (s *StepProvision) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
2015-12-22 09:56:33 -05: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,
AttachOptions: config.AttachOptions,
2015-12-22 09:56:33 -05:00
RootFs: 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)
2015-12-22 09:56:33 -05:00
// Provision
log.Println("Running the provision hook")
if err := hook.Run(ctx, packer.HookProvision, ui, comm, hookData); err != nil {
2015-12-22 09:56:33 -05:00
state.Put("error", err)
return multistep.ActionHalt
}
return multistep.ActionContinue
}
func (s *StepProvision) Cleanup(state multistep.StateBag) {}