diff --git a/command/build/command.go b/command/build/command.go index 664ab553d..24f127afb 100644 --- a/command/build/command.go +++ b/command/build/command.go @@ -44,6 +44,12 @@ func (Command) Run(env packer.Environment, args []string) int { builds = append(builds, build) } + // Prepare all the builds + for _, b := range builds { + log.Printf("Preparing build: %s\n", b.Name()) + b.Prepare() + } + env.Ui().Say("YAY!\n") return 0 } diff --git a/config.go b/config.go index d7faeae1e..494686202 100644 --- a/config.go +++ b/config.go @@ -11,6 +11,9 @@ import ( // This is the default, built-in configuration that ships with // Packer. const defaultConfig = ` +[builders] +amazon-ebs = "packer-builder-amazon-ebs" + [commands] build = "packer-command-build" ` diff --git a/packer/build.go b/packer/build.go index 3f1720766..ea8ada0fa 100644 --- a/packer/build.go +++ b/packer/build.go @@ -3,6 +3,7 @@ package packer // A Build represents a single job within Packer that is responsible for // building some machine image artifact. Builds are meant to be parallelized. type Build interface { + Name() string Prepare() error Run(ui Ui) } @@ -33,6 +34,11 @@ type Builder interface { Run(build Build, ui Ui) } +// Returns the name of the build. +func (b *coreBuild) Name() string { + return b.name +} + // Prepare prepares the build by doing some initialization for the builder // and any hooks. This _must_ be called prior to Run. func (b *coreBuild) Prepare() error { diff --git a/packer/build_test.go b/packer/build_test.go index ee68b0e88..d26edfcc4 100644 --- a/packer/build_test.go +++ b/packer/build_test.go @@ -37,6 +37,13 @@ func testBuilder() *TestBuilder { return &TestBuilder{} } +func TestBuild_Name(t *testing.T) { + assert := asserts.NewTestingAsserts(t, true) + + build := testBuild() + assert.Equal(build.Name(), "test", "should have a name") +} + func TestBuild_Prepare(t *testing.T) { assert := asserts.NewTestingAsserts(t, true) diff --git a/packer/rpc/build.go b/packer/rpc/build.go index d522a6215..73930a4fa 100644 --- a/packer/rpc/build.go +++ b/packer/rpc/build.go @@ -23,6 +23,11 @@ type BuildRunArgs struct { UiRPCAddress string } +func (b *Build) Name() (result string) { + b.client.Call("Build.Name", new(interface{}), &result) + return +} + func (b *Build) Prepare() (err error) { b.client.Call("Build.Prepare", new(interface{}), &err) return @@ -37,6 +42,11 @@ func (b *Build) Run(ui packer.Ui) { b.client.Call("Build.Run", args, new(interface{})) } +func (b *BuildServer) Name(args *interface{}, reply*string) error { + *reply = b.build.Name() + return nil +} + func (b *BuildServer) Prepare(args *BuildPrepareArgs, reply *error) error { *reply = b.build.Prepare() return nil diff --git a/packer/rpc/build_test.go b/packer/rpc/build_test.go index 849268433..3720f128b 100644 --- a/packer/rpc/build_test.go +++ b/packer/rpc/build_test.go @@ -8,11 +8,17 @@ import ( ) type testBuild struct { + nameCalled bool prepareCalled bool runCalled bool runUi packer.Ui } +func (b *testBuild) Name() string { + b.nameCalled = true + return "name" +} + func (b *testBuild) Prepare() error { b.prepareCalled = true return nil @@ -43,8 +49,13 @@ func TestBuildRPC(t *testing.T) { panic(err) } - // Test Prepare bClient := &Build{client} + + // Test Name + bClient.Name() + assert.True(b.nameCalled, "name should be called") + + // Test Prepare bClient.Prepare() assert.True(b.prepareCalled, "prepare should be called") diff --git a/packer/rpc/builder_test.go b/packer/rpc/builder_test.go index 27ff96bea..030b85513 100644 --- a/packer/rpc/builder_test.go +++ b/packer/rpc/builder_test.go @@ -65,7 +65,7 @@ func TestBuilderRPC(t *testing.T) { } } -func TestBuilder_ImplementsBuild(t *testing.T) { +func TestBuilder_ImplementsBuilder(t *testing.T) { assert := asserts.NewTestingAsserts(t, true) var realBuilder packer.Builder