Commit 9600bf5b authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer: Build.Name

parent 587d3598
...@@ -44,6 +44,12 @@ func (Command) Run(env packer.Environment, args []string) int { ...@@ -44,6 +44,12 @@ func (Command) Run(env packer.Environment, args []string) int {
builds = append(builds, build) 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") env.Ui().Say("YAY!\n")
return 0 return 0
} }
......
...@@ -11,6 +11,9 @@ import ( ...@@ -11,6 +11,9 @@ import (
// This is the default, built-in configuration that ships with // This is the default, built-in configuration that ships with
// Packer. // Packer.
const defaultConfig = ` const defaultConfig = `
[builders]
amazon-ebs = "packer-builder-amazon-ebs"
[commands] [commands]
build = "packer-command-build" build = "packer-command-build"
` `
......
...@@ -3,6 +3,7 @@ package packer ...@@ -3,6 +3,7 @@ package packer
// A Build represents a single job within Packer that is responsible for // A Build represents a single job within Packer that is responsible for
// building some machine image artifact. Builds are meant to be parallelized. // building some machine image artifact. Builds are meant to be parallelized.
type Build interface { type Build interface {
Name() string
Prepare() error Prepare() error
Run(ui Ui) Run(ui Ui)
} }
...@@ -33,6 +34,11 @@ type Builder interface { ...@@ -33,6 +34,11 @@ type Builder interface {
Run(build Build, ui Ui) 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 // Prepare prepares the build by doing some initialization for the builder
// and any hooks. This _must_ be called prior to Run. // and any hooks. This _must_ be called prior to Run.
func (b *coreBuild) Prepare() error { func (b *coreBuild) Prepare() error {
......
...@@ -37,6 +37,13 @@ func testBuilder() *TestBuilder { ...@@ -37,6 +37,13 @@ func testBuilder() *TestBuilder {
return &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) { func TestBuild_Prepare(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true) assert := asserts.NewTestingAsserts(t, true)
......
...@@ -23,6 +23,11 @@ type BuildRunArgs struct { ...@@ -23,6 +23,11 @@ type BuildRunArgs struct {
UiRPCAddress string UiRPCAddress string
} }
func (b *Build) Name() (result string) {
b.client.Call("Build.Name", new(interface{}), &result)
return
}
func (b *Build) Prepare() (err error) { func (b *Build) Prepare() (err error) {
b.client.Call("Build.Prepare", new(interface{}), &err) b.client.Call("Build.Prepare", new(interface{}), &err)
return return
...@@ -37,6 +42,11 @@ func (b *Build) Run(ui packer.Ui) { ...@@ -37,6 +42,11 @@ func (b *Build) Run(ui packer.Ui) {
b.client.Call("Build.Run", args, new(interface{})) 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 { func (b *BuildServer) Prepare(args *BuildPrepareArgs, reply *error) error {
*reply = b.build.Prepare() *reply = b.build.Prepare()
return nil return nil
......
...@@ -8,11 +8,17 @@ import ( ...@@ -8,11 +8,17 @@ import (
) )
type testBuild struct { type testBuild struct {
nameCalled bool
prepareCalled bool prepareCalled bool
runCalled bool runCalled bool
runUi packer.Ui runUi packer.Ui
} }
func (b *testBuild) Name() string {
b.nameCalled = true
return "name"
}
func (b *testBuild) Prepare() error { func (b *testBuild) Prepare() error {
b.prepareCalled = true b.prepareCalled = true
return nil return nil
...@@ -43,8 +49,13 @@ func TestBuildRPC(t *testing.T) { ...@@ -43,8 +49,13 @@ func TestBuildRPC(t *testing.T) {
panic(err) panic(err)
} }
// Test Prepare
bClient := &Build{client} bClient := &Build{client}
// Test Name
bClient.Name()
assert.True(b.nameCalled, "name should be called")
// Test Prepare
bClient.Prepare() bClient.Prepare()
assert.True(b.prepareCalled, "prepare should be called") assert.True(b.prepareCalled, "prepare should be called")
......
...@@ -65,7 +65,7 @@ func TestBuilderRPC(t *testing.T) { ...@@ -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) assert := asserts.NewTestingAsserts(t, true)
var realBuilder packer.Builder var realBuilder packer.Builder
......
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