packer: Add BuildNameConfigKey to all configs which has the build name
This commit is contained in:
parent
222b15e8f3
commit
8120cf9adf
|
@ -6,6 +6,10 @@ import (
|
|||
"sync"
|
||||
)
|
||||
|
||||
// This is the key in configurations that is set to the name of the
|
||||
// build.
|
||||
const BuildNameConfigKey = "packer_build_name"
|
||||
|
||||
// This is the key in configurations that is set to "true" when Packer
|
||||
// debugging is enabled.
|
||||
const DebugConfigKey = "packer_debug"
|
||||
|
@ -91,12 +95,13 @@ func (b *coreBuild) Prepare() (err error) {
|
|||
|
||||
b.prepareCalled = true
|
||||
|
||||
debugConfig := map[string]interface{}{
|
||||
packerConfig := map[string]interface{}{
|
||||
BuildNameConfigKey: b.name,
|
||||
DebugConfigKey: b.debug,
|
||||
}
|
||||
|
||||
// Prepare the builder
|
||||
err = b.builder.Prepare(b.builderConfig, debugConfig)
|
||||
err = b.builder.Prepare(b.builderConfig, packerConfig)
|
||||
if err != nil {
|
||||
log.Printf("Build '%s' prepare failure: %s\n", b.name, err)
|
||||
return
|
||||
|
@ -106,7 +111,7 @@ func (b *coreBuild) Prepare() (err error) {
|
|||
for _, coreProv := range b.provisioners {
|
||||
configs := make([]interface{}, len(coreProv.config), len(coreProv.config)+1)
|
||||
copy(configs, coreProv.config)
|
||||
configs = append(configs, debugConfig)
|
||||
configs = append(configs, packerConfig)
|
||||
|
||||
if err = coreProv.provisioner.Prepare(configs...); err != nil {
|
||||
return
|
||||
|
|
|
@ -39,19 +39,22 @@ func TestBuild_Name(t *testing.T) {
|
|||
func TestBuild_Prepare(t *testing.T) {
|
||||
assert := asserts.NewTestingAsserts(t, true)
|
||||
|
||||
debugFalseConfig := map[string]interface{}{DebugConfigKey: false}
|
||||
packerConfig := map[string]interface{}{
|
||||
BuildNameConfigKey: "test",
|
||||
DebugConfigKey: false,
|
||||
}
|
||||
|
||||
build := testBuild()
|
||||
builder := build.builder.(*TestBuilder)
|
||||
|
||||
build.Prepare()
|
||||
assert.True(builder.prepareCalled, "prepare should be called")
|
||||
assert.Equal(builder.prepareConfig, []interface{}{42, debugFalseConfig}, "prepare config should be 42")
|
||||
assert.Equal(builder.prepareConfig, []interface{}{42, packerConfig}, "prepare config should be 42")
|
||||
|
||||
coreProv := build.provisioners[0]
|
||||
prov := coreProv.provisioner.(*TestProvisioner)
|
||||
assert.True(prov.prepCalled, "prepare should be called")
|
||||
assert.Equal(prov.prepConfigs, []interface{}{42, debugFalseConfig}, "prepare should be called with proper config")
|
||||
assert.Equal(prov.prepConfigs, []interface{}{42, packerConfig}, "prepare should be called with proper config")
|
||||
|
||||
corePP := build.postProcessors[0][0]
|
||||
pp := corePP.processor.(*TestPostProcessor)
|
||||
|
@ -82,7 +85,10 @@ func TestBuild_Prepare_Twice(t *testing.T) {
|
|||
func TestBuild_Prepare_Debug(t *testing.T) {
|
||||
assert := asserts.NewTestingAsserts(t, true)
|
||||
|
||||
debugConfig := map[string]interface{}{DebugConfigKey: true}
|
||||
packerConfig := map[string]interface{}{
|
||||
BuildNameConfigKey: "test",
|
||||
DebugConfigKey: true,
|
||||
}
|
||||
|
||||
build := testBuild()
|
||||
builder := build.builder.(*TestBuilder)
|
||||
|
@ -90,12 +96,12 @@ func TestBuild_Prepare_Debug(t *testing.T) {
|
|||
build.SetDebug(true)
|
||||
build.Prepare()
|
||||
assert.True(builder.prepareCalled, "prepare should be called")
|
||||
assert.Equal(builder.prepareConfig, []interface{}{42, debugConfig}, "prepare config should be 42")
|
||||
assert.Equal(builder.prepareConfig, []interface{}{42, packerConfig}, "prepare config should be 42")
|
||||
|
||||
coreProv := build.provisioners[0]
|
||||
prov := coreProv.provisioner.(*TestProvisioner)
|
||||
assert.True(prov.prepCalled, "prepare should be called")
|
||||
assert.Equal(prov.prepConfigs, []interface{}{42, debugConfig}, "prepare should be called with proper config")
|
||||
assert.Equal(prov.prepConfigs, []interface{}{42, packerConfig}, "prepare should be called with proper config")
|
||||
}
|
||||
|
||||
func TestBuild_Run(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue