2015-12-22 09:56:33 -05:00
|
|
|
package lxc
|
|
|
|
|
|
|
|
import (
|
2018-01-22 18:32:33 -05:00
|
|
|
"context"
|
|
|
|
"log"
|
|
|
|
|
2020-12-17 16:29:25 -05:00
|
|
|
"github.com/hashicorp/packer-plugin-sdk/multistep"
|
|
|
|
"github.com/hashicorp/packer-plugin-sdk/multistep/commonsteps"
|
|
|
|
packersdk "github.com/hashicorp/packer-plugin-sdk/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
|
|
|
|
2019-03-22 09:53:28 -04:00
|
|
|
func (s *StepProvision) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
2020-11-19 18:10:00 -05:00
|
|
|
hook := state.Get("hook").(packersdk.Hook)
|
2015-12-22 09:56:33 -05:00
|
|
|
config := state.Get("config").(*Config)
|
|
|
|
mountPath := state.Get("mount_path").(string)
|
2020-11-19 14:54:31 -05:00
|
|
|
ui := state.Get("ui").(packersdk.Ui)
|
2015-12-22 09:56:33 -05:00
|
|
|
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 09:56:33 -05:00
|
|
|
RootFs: mountPath,
|
|
|
|
CmdWrapper: wrappedCommand,
|
|
|
|
}
|
|
|
|
|
2020-01-30 05:27:58 -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-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)
|
|
|
|
|
2015-12-22 09:56:33 -05:00
|
|
|
// Provision
|
|
|
|
log.Println("Running the provision hook")
|
2020-11-19 18:10:00 -05:00
|
|
|
if err := hook.Run(ctx, packersdk.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) {}
|