packer-cn/builder/lxd/step_provision.go

45 lines
1.3 KiB
Go
Raw Normal View History

2016-05-26 23:21:55 -04:00
package lxd
import (
"context"
"log"
2020-11-17 19:31:03 -05:00
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
"github.com/hashicorp/packer/packer-plugin-sdk/multistep/commonsteps"
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
2016-05-26 23:21:55 -04:00
)
// StepProvision provisions the container
2016-05-26 23:21:55 -04:00
type StepProvision struct{}
func (s *StepProvision) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
hook := state.Get("hook").(packersdk.Hook)
2016-05-26 23:21:55 -04:00
config := state.Get("config").(*Config)
ui := state.Get("ui").(packersdk.Ui)
2016-05-26 23:21:55 -04:00
wrappedCommand := state.Get("wrappedCommand").(CommandWrapper)
// Create our communicator
comm := &Communicator{
ContainerName: config.ContainerName,
CmdWrapper: wrappedCommand,
}
// Loads hook data from builder's state, if it has been set.
hookData := commonsteps.PopulateProvisionHookData(state)
// Update state generated_data with complete hookData
// to make them accessible by post-processors
state.Put("generated_data", hookData)
2016-05-26 23:21:55 -04:00
// Provision
log.Println("Running the provision hook")
if err := hook.Run(ctx, packersdk.HookProvision, ui, comm, hookData); err != nil {
2016-05-26 23:21:55 -04:00
state.Put("error", err)
return multistep.ActionHalt
}
return multistep.ActionContinue
}
func (s *StepProvision) Cleanup(state multistep.StateBag) {}