Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
0985d261
Commit
0985d261
authored
May 03, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make Build an interface
parent
8dea7206
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
12 deletions
+19
-12
packer/build.go
packer/build.go
+11
-4
packer/build_test.go
packer/build_test.go
+6
-6
packer/template.go
packer/template.go
+2
-2
No files found.
packer/build.go
View file @
0985d261
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
core
Build
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
*
core
Build
)
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
*
core
Build
)
Run
(
ui
Ui
)
{
if
!
b
.
prepareCalled
{
panic
(
"Prepare must be called first"
)
}
...
...
packer/build_test.go
View file @
0985d261
...
...
@@ -17,7 +17,7 @@ type TestBuilder struct {
prepareCalled
bool
prepareConfig
interface
{}
runCalled
bool
runBuild
*
Build
runBuild
Build
runUi
Ui
}
...
...
@@ -26,14 +26,14 @@ func (tb *TestBuilder) Prepare(config interface{}) {
tb
.
prepareConfig
=
config
}
func
(
tb
*
TestBuilder
)
Run
(
b
*
Build
,
ui
Ui
)
{
func
(
tb
*
TestBuilder
)
Run
(
b
Build
,
ui
Ui
)
{
tb
.
runCalled
=
true
tb
.
runBuild
=
b
tb
.
runUi
=
ui
}
func
testBuild
()
*
Build
{
return
&
Build
{
func
testBuild
()
Build
{
return
&
core
Build
{
name
:
"test"
,
builder
:
&
TestBuilder
{},
rawConfig
:
42
,
...
...
@@ -52,7 +52,7 @@ func TestBuild_Prepare(t *testing.T) {
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
build
:=
testBuild
()
builder
:=
build
.
builder
.
(
*
TestBuilder
)
builder
:=
build
.
(
*
coreBuild
)
.
builder
.
(
*
TestBuilder
)
build
.
Prepare
()
assert
.
True
(
builder
.
prepareCalled
,
"prepare should be called"
)
...
...
@@ -68,7 +68,7 @@ func TestBuild_Run(t *testing.T) {
build
.
Prepare
()
build
.
Run
(
ui
)
builder
:=
build
.
builder
.
(
*
TestBuilder
)
builder
:=
build
.
(
*
coreBuild
)
.
builder
.
(
*
TestBuilder
)
assert
.
True
(
builder
.
runCalled
,
"run should be called"
)
assert
.
Equal
(
builder
.
runBuild
,
build
,
"run should be called with build"
)
...
...
packer/template.go
View file @
0985d261
...
...
@@ -95,7 +95,7 @@ func (t *Template) BuildNames() []string {
//
// If the build does not exist as part of this template, an error is
// returned.
func
(
t
*
Template
)
Build
(
name
string
,
bf
BuilderFactory
)
(
b
*
Build
,
err
error
)
{
func
(
t
*
Template
)
Build
(
name
string
,
bf
BuilderFactory
)
(
b
Build
,
err
error
)
{
builderConfig
,
ok
:=
t
.
Builders
[
name
]
if
!
ok
{
err
=
fmt
.
Errorf
(
"No such build found in template: %s"
,
name
)
...
...
@@ -108,7 +108,7 @@ func (t *Template) Build(name string, bf BuilderFactory) (b *Build, err error) {
return
}
b
=
&
Build
{
b
=
&
core
Build
{
name
:
name
,
builder
:
builder
,
rawConfig
:
builderConfig
.
rawConfig
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment