Commit 9f5a2475 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer: Builders can take multiple configs

parent a45c7fb0
......@@ -40,7 +40,7 @@ func TestBuild_Prepare(t *testing.T) {
build.Prepare()
assert.True(builder.prepareCalled, "prepare should be called")
assert.Equal(builder.prepareConfig, 42, "prepare config should be 42")
assert.Equal(builder.prepareConfig, []interface{}{42}, "prepare config should be 42")
// Verify provisioners were prepared
coreProv := coreB.provisioners[0]
......
......@@ -3,11 +3,18 @@ package packer
// Implementers of Builder are responsible for actually building images
// on some platform given some configuration.
type Builder interface {
// Prepare is responsible for reading in some configuration, in the raw form
// of map[string]interface{}, and storing that state for use later. Any setup
// should be done in this method. Note that NO side effects should really take
// place in prepare. It is meant as a state setup step only.
Prepare(config interface{}) error
// Prepare is responsible for configuring the builder and validating
// that configuration. Any setup should be done in this method. Note that
// NO side effects should take place in prepare, it is meant as a state
// setup only. Calling Prepare is not necessarilly followed by a Run.
//
// The parameters to Prepare are a set of interface{} values of the
// configuration. These are almost always `map[string]interface{}`
// parsed from a template, but no guarantee is made.
//
// Each of the configuration values should merge into the final
// configuration.
Prepare(...interface{}) error
// Run is where the actual build should take place. It takes a Build and a Ui.
Run(ui Ui, hook Hook, cache Cache) (Artifact, error)
......
......@@ -2,7 +2,7 @@ package packer
type TestBuilder struct {
prepareCalled bool
prepareConfig interface{}
prepareConfig []interface{}
runCalled bool
runCache Cache
runHook Hook
......@@ -10,7 +10,7 @@ type TestBuilder struct {
cancelCalled bool
}
func (tb *TestBuilder) Prepare(config interface{}) error {
func (tb *TestBuilder) Prepare(config ...interface{}) error {
tb.prepareCalled = true
tb.prepareConfig = config
return nil
......
......@@ -10,13 +10,13 @@ type cmdBuilder struct {
client *Client
}
func (b *cmdBuilder) Prepare(config interface{}) error {
func (b *cmdBuilder) Prepare(config ...interface{}) error {
defer func() {
r := recover()
b.checkExit(r, nil)
}()
return b.builder.Prepare(config)
return b.builder.Prepare(config...)
}
func (b *cmdBuilder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
......
......@@ -8,7 +8,7 @@ import (
type helperBuilder byte
func (helperBuilder) Prepare(interface{}) error {
func (helperBuilder) Prepare(...interface{}) error {
return nil
}
......
......@@ -21,7 +21,7 @@ type BuilderServer struct {
}
type BuilderPrepareArgs struct {
Config interface{}
Configs []interface{}
}
type BuilderRunArgs struct {
......@@ -38,7 +38,7 @@ func Builder(client *rpc.Client) *builder {
return &builder{client}
}
func (b *builder) Prepare(config interface{}) (err error) {
func (b *builder) Prepare(config ...interface{}) (err error) {
cerr := b.client.Call("Builder.Prepare", &BuilderPrepareArgs{config}, &err)
if cerr != nil {
err = cerr
......@@ -109,7 +109,7 @@ func (b *builder) Cancel() {
}
func (b *BuilderServer) Prepare(args *BuilderPrepareArgs, reply *error) error {
err := b.builder.Prepare(args.Config)
err := b.builder.Prepare(args.Configs...)
if err != nil {
*reply = NewBasicError(err)
}
......
......@@ -12,7 +12,7 @@ var testBuilderArtifact = &testArtifact{}
type testBuilder struct {
prepareCalled bool
prepareConfig interface{}
prepareConfig []interface{}
runCalled bool
runCache packer.Cache
runHook packer.Hook
......@@ -23,7 +23,7 @@ type testBuilder struct {
nilRunResult bool
}
func (b *testBuilder) Prepare(config interface{}) error {
func (b *testBuilder) Prepare(config ...interface{}) error {
b.prepareCalled = true
b.prepareConfig = config
return nil
......@@ -68,7 +68,7 @@ func TestBuilderRPC(t *testing.T) {
bClient := Builder(client)
bClient.Prepare(config)
assert.True(b.prepareCalled, "prepare should be called")
assert.Equal(b.prepareConfig, 42, "prepare should be called with right arg")
assert.Equal(b.prepareConfig, []interface{}{42}, "prepare should be called with right arg")
// Test Run
cache := new(testCache)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment