2016-05-26 23:21:55 -04:00
|
|
|
package lxd
|
|
|
|
|
|
|
|
import (
|
2018-01-22 18:32:33 -05:00
|
|
|
"context"
|
|
|
|
"log"
|
|
|
|
|
2020-02-14 11:42:29 -05:00
|
|
|
"github.com/hashicorp/packer/common"
|
2018-01-19 19:18:44 -05:00
|
|
|
"github.com/hashicorp/packer/helper/multistep"
|
2017-09-05 17:09:15 -04:00
|
|
|
"github.com/hashicorp/packer/packer"
|
2016-05-26 23:21:55 -04:00
|
|
|
)
|
|
|
|
|
2016-08-06 23:25:57 -04:00
|
|
|
// StepProvision provisions the container
|
2016-05-26 23:21:55 -04:00
|
|
|
type StepProvision struct{}
|
|
|
|
|
2019-03-22 09:53:28 -04:00
|
|
|
func (s *StepProvision) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
2016-05-26 23:21:55 -04:00
|
|
|
hook := state.Get("hook").(packer.Hook)
|
|
|
|
config := state.Get("config").(*Config)
|
|
|
|
ui := state.Get("ui").(packer.Ui)
|
|
|
|
wrappedCommand := state.Get("wrappedCommand").(CommandWrapper)
|
|
|
|
|
|
|
|
// Create our communicator
|
|
|
|
comm := &Communicator{
|
|
|
|
ContainerName: config.ContainerName,
|
|
|
|
CmdWrapper: wrappedCommand,
|
|
|
|
}
|
|
|
|
|
2020-01-30 05:27:58 -05:00
|
|
|
// 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)
|
|
|
|
|
2016-05-26 23:21:55 -04:00
|
|
|
// Provision
|
|
|
|
log.Println("Running the provision hook")
|
2020-01-30 05:27:58 -05:00
|
|
|
if err := hook.Run(ctx, packer.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) {}
|