|
|
|
|
@ -1,10 +1,17 @@
|
|
|
|
|
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 {
|
|
|
|
|
Prepare()
|
|
|
|
|
Run(ui Ui)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// A build struct represents a single build job, the result of which should
|
|
|
|
|
// be a single machine image artifact. This artifact may be comprised of
|
|
|
|
|
// multiple files, of course, but it should be for only a single provider
|
|
|
|
|
// (such as VirtualBox, EC2, etc.).
|
|
|
|
|
type Build struct {
|
|
|
|
|
type coreBuild struct {
|
|
|
|
|
name string
|
|
|
|
|
builder Builder
|
|
|
|
|
rawConfig interface{}
|
|
|
|
|
@ -23,7 +30,7 @@ type Build struct {
|
|
|
|
|
// Run is where the actual build should take place. It takes a Build and a Ui.
|
|
|
|
|
type Builder interface {
|
|
|
|
|
Prepare(config interface{})
|
|
|
|
|
Run(build *Build, ui Ui)
|
|
|
|
|
Run(build Build, ui Ui)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This factory is responsible for returning Builders for the given name.
|
|
|
|
|
@ -44,13 +51,13 @@ func (NilBuilderFactory) CreateBuilder(name string) Builder {
|
|
|
|
|
|
|
|
|
|
// Prepare prepares the build by doing some initialization for the builder
|
|
|
|
|
// and any hooks. This _must_ be called prior to Run.
|
|
|
|
|
func (b *Build) Prepare() {
|
|
|
|
|
func (b *coreBuild) Prepare() {
|
|
|
|
|
b.prepareCalled = true
|
|
|
|
|
b.builder.Prepare(b.rawConfig)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Runs the actual build. Prepare must be called prior to running this.
|
|
|
|
|
func (b *Build) Run(ui Ui) {
|
|
|
|
|
func (b *coreBuild) Run(ui Ui) {
|
|
|
|
|
if !b.prepareCalled {
|
|
|
|
|
panic("Prepare must be called first")
|
|
|
|
|
}
|
|
|
|
|
|