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 {
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
}
......
......@@ -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"
`
......
......@@ -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 {
......
......@@ -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)
......
......@@ -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
......
......@@ -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")
......
......@@ -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
......
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