From 1b78fc88a93f84ceab559edc5574ef2894d7a036 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 23 May 2013 21:26:24 -0700 Subject: [PATCH] packer: coreBuild runs provisioners as part of Run --- packer/build.go | 14 ++++++++++++++ packer/build_test.go | 5 +++++ 2 files changed, 19 insertions(+) diff --git a/packer/build.go b/packer/build.go index 534cca249..be1bf05b9 100644 --- a/packer/build.go +++ b/packer/build.go @@ -70,6 +70,20 @@ func (b *coreBuild) Run(ui Ui) Artifact { copy(hooks[hookName], hookList) } + // Add a hook for the provisioners if we have provisioners + if len(b.provisioners) > 0 { + provisioners := make([]Provisioner, len(b.provisioners)) + for i, p := range b.provisioners { + provisioners[i] = p.provisioner + } + + if _, ok := hooks[HookProvision]; !ok { + hooks[HookProvision] = make([]Hook, 0, 1) + } + + hooks[HookProvision] = append(hooks[HookProvision], &ProvisionHook{provisioners}) + } + hook := &DispatchHook{hooks} return b.builder.Run(ui, hook) } diff --git a/packer/build_test.go b/packer/build_test.go index 9caa8dd2e..aed5b8ecb 100644 --- a/packer/build_test.go +++ b/packer/build_test.go @@ -74,6 +74,11 @@ func TestBuild_Run(t *testing.T) { hook := coreB.hooks["foo"][0].(*TestHook) assert.True(hook.runCalled, "run should be called") assert.Equal(hook.runData, 42, "should have correct data") + + // Verify provisioners run + dispatchHook.Run(HookProvision, nil, nil, 42) + prov := coreB.provisioners[0].provisioner.(*TestProvisioner) + assert.True(prov.provCalled, "provision should be called") } func TestBuild_RunBeforePrepare(t *testing.T) {