packer: Template takes a component finder
This commit is contained in:
parent
30ab944437
commit
779f489894
@ -31,12 +31,18 @@ func (Command) Run(env packer.Environment, args []string) int {
|
||||
return 1
|
||||
}
|
||||
|
||||
// The component finder for our builds
|
||||
components := &packer.ComponentFinder{
|
||||
Builder: env.Builder,
|
||||
Hook: env.Hook,
|
||||
}
|
||||
|
||||
// Go through each builder and compile the builds that we care about
|
||||
buildNames := tpl.BuildNames()
|
||||
builds := make([]packer.Build, 0, len(buildNames))
|
||||
for _, buildName := range buildNames {
|
||||
log.Printf("Creating build: %s\n", buildName)
|
||||
build, err := tpl.Build(buildName, env.Builder)
|
||||
build, err := tpl.Build(buildName, components)
|
||||
if err != nil {
|
||||
env.Ui().Error("Failed to create build '%s': \n\n%s\n", buildName, err.Error())
|
||||
return 1
|
||||
|
@ -96,14 +96,14 @@ func (t *Template) BuildNames() []string {
|
||||
//
|
||||
// If the build does not exist as part of this template, an error is
|
||||
// returned.
|
||||
func (t *Template) Build(name string, bf BuilderFunc) (b Build, err error) {
|
||||
func (t *Template) Build(name string, components *ComponentFinder) (b Build, err error) {
|
||||
builderConfig, ok := t.Builders[name]
|
||||
if !ok {
|
||||
err = fmt.Errorf("No such build found in template: %s", name)
|
||||
return
|
||||
}
|
||||
|
||||
builder, err := bf(builderConfig.builderName)
|
||||
builder, err := components.Builder(builderConfig.builderName)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -181,7 +181,8 @@ func TestTemplate_BuildUnknownBuilder(t *testing.T) {
|
||||
assert.Nil(err, "should not error")
|
||||
|
||||
builderFactory := func(string) (Builder, error) { return nil, nil }
|
||||
build, err := template.Build("test1", builderFactory)
|
||||
components := &ComponentFinder{Builder: builderFactory}
|
||||
build, err := template.Build("test1", components)
|
||||
assert.Nil(build, "build should be nil")
|
||||
assert.NotNil(err, "should have error")
|
||||
}
|
||||
@ -215,10 +216,11 @@ func TestTemplate_Build(t *testing.T) {
|
||||
}
|
||||
|
||||
builderFactory := func(n string) (Builder, error) { return builderMap[n], nil }
|
||||
components := &ComponentFinder{Builder: builderFactory}
|
||||
|
||||
// Get the build, verifying we can get it without issue, but also
|
||||
// that the proper builder was looked up and used for the build.
|
||||
build, err := template.Build("test1", builderFactory)
|
||||
build, err := template.Build("test1", components)
|
||||
assert.Nil(err, "should not error")
|
||||
|
||||
build.Prepare()
|
||||
|
Loading…
x
Reference in New Issue
Block a user