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
9f5a2475
Commit
9f5a2475
authored
Jun 14, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer: Builders can take multiple configs
parent
a45c7fb0
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
24 additions
and
17 deletions
+24
-17
packer/build_test.go
packer/build_test.go
+1
-1
packer/builder.go
packer/builder.go
+12
-5
packer/builder_test.go
packer/builder_test.go
+2
-2
packer/plugin/builder.go
packer/plugin/builder.go
+2
-2
packer/plugin/builder_test.go
packer/plugin/builder_test.go
+1
-1
packer/rpc/builder.go
packer/rpc/builder.go
+3
-3
packer/rpc/builder_test.go
packer/rpc/builder_test.go
+3
-3
No files found.
packer/build_test.go
View file @
9f5a2475
...
@@ -40,7 +40,7 @@ func TestBuild_Prepare(t *testing.T) {
...
@@ -40,7 +40,7 @@ func TestBuild_Prepare(t *testing.T) {
build
.
Prepare
()
build
.
Prepare
()
assert
.
True
(
builder
.
prepareCalled
,
"prepare should be called"
)
assert
.
True
(
builder
.
prepareCalled
,
"prepare should be called"
)
assert
.
Equal
(
builder
.
prepareConfig
,
42
,
"prepare config should be 42"
)
assert
.
Equal
(
builder
.
prepareConfig
,
[]
interface
{}{
42
}
,
"prepare config should be 42"
)
// Verify provisioners were prepared
// Verify provisioners were prepared
coreProv
:=
coreB
.
provisioners
[
0
]
coreProv
:=
coreB
.
provisioners
[
0
]
...
...
packer/builder.go
View file @
9f5a2475
...
@@ -3,11 +3,18 @@ package packer
...
@@ -3,11 +3,18 @@ package packer
// Implementers of Builder are responsible for actually building images
// Implementers of Builder are responsible for actually building images
// on some platform given some configuration.
// on some platform given some configuration.
type
Builder
interface
{
type
Builder
interface
{
// Prepare is responsible for reading in some configuration, in the raw form
// Prepare is responsible for configuring the builder and validating
// of map[string]interface{}, and storing that state for use later. Any setup
// that configuration. Any setup should be done in this method. Note that
// should be done in this method. Note that NO side effects should really take
// NO side effects should take place in prepare, it is meant as a state
// place in prepare. It is meant as a state setup step only.
// setup only. Calling Prepare is not necessarilly followed by a Run.
Prepare
(
config
interface
{})
error
//
// The parameters to Prepare are a set of interface{} values of the
// configuration. These are almost always `map[string]interface{}`
// parsed from a template, but no guarantee is made.
//
// Each of the configuration values should merge into the final
// configuration.
Prepare
(
...
interface
{})
error
// Run is where the actual build should take place. It takes a Build and a Ui.
// Run is where the actual build should take place. It takes a Build and a Ui.
Run
(
ui
Ui
,
hook
Hook
,
cache
Cache
)
(
Artifact
,
error
)
Run
(
ui
Ui
,
hook
Hook
,
cache
Cache
)
(
Artifact
,
error
)
...
...
packer/builder_test.go
View file @
9f5a2475
...
@@ -2,7 +2,7 @@ package packer
...
@@ -2,7 +2,7 @@ package packer
type
TestBuilder
struct
{
type
TestBuilder
struct
{
prepareCalled
bool
prepareCalled
bool
prepareConfig
interface
{}
prepareConfig
[]
interface
{}
runCalled
bool
runCalled
bool
runCache
Cache
runCache
Cache
runHook
Hook
runHook
Hook
...
@@ -10,7 +10,7 @@ type TestBuilder struct {
...
@@ -10,7 +10,7 @@ type TestBuilder struct {
cancelCalled
bool
cancelCalled
bool
}
}
func
(
tb
*
TestBuilder
)
Prepare
(
config
interface
{})
error
{
func
(
tb
*
TestBuilder
)
Prepare
(
config
...
interface
{})
error
{
tb
.
prepareCalled
=
true
tb
.
prepareCalled
=
true
tb
.
prepareConfig
=
config
tb
.
prepareConfig
=
config
return
nil
return
nil
...
...
packer/plugin/builder.go
View file @
9f5a2475
...
@@ -10,13 +10,13 @@ type cmdBuilder struct {
...
@@ -10,13 +10,13 @@ type cmdBuilder struct {
client
*
Client
client
*
Client
}
}
func
(
b
*
cmdBuilder
)
Prepare
(
config
interface
{})
error
{
func
(
b
*
cmdBuilder
)
Prepare
(
config
...
interface
{})
error
{
defer
func
()
{
defer
func
()
{
r
:=
recover
()
r
:=
recover
()
b
.
checkExit
(
r
,
nil
)
b
.
checkExit
(
r
,
nil
)
}()
}()
return
b
.
builder
.
Prepare
(
config
)
return
b
.
builder
.
Prepare
(
config
...
)
}
}
func
(
b
*
cmdBuilder
)
Run
(
ui
packer
.
Ui
,
hook
packer
.
Hook
,
cache
packer
.
Cache
)
(
packer
.
Artifact
,
error
)
{
func
(
b
*
cmdBuilder
)
Run
(
ui
packer
.
Ui
,
hook
packer
.
Hook
,
cache
packer
.
Cache
)
(
packer
.
Artifact
,
error
)
{
...
...
packer/plugin/builder_test.go
View file @
9f5a2475
...
@@ -8,7 +8,7 @@ import (
...
@@ -8,7 +8,7 @@ import (
type
helperBuilder
byte
type
helperBuilder
byte
func
(
helperBuilder
)
Prepare
(
interface
{})
error
{
func
(
helperBuilder
)
Prepare
(
...
interface
{})
error
{
return
nil
return
nil
}
}
...
...
packer/rpc/builder.go
View file @
9f5a2475
...
@@ -21,7 +21,7 @@ type BuilderServer struct {
...
@@ -21,7 +21,7 @@ type BuilderServer struct {
}
}
type
BuilderPrepareArgs
struct
{
type
BuilderPrepareArgs
struct
{
Config
interface
{}
Config
s
[]
interface
{}
}
}
type
BuilderRunArgs
struct
{
type
BuilderRunArgs
struct
{
...
@@ -38,7 +38,7 @@ func Builder(client *rpc.Client) *builder {
...
@@ -38,7 +38,7 @@ func Builder(client *rpc.Client) *builder {
return
&
builder
{
client
}
return
&
builder
{
client
}
}
}
func
(
b
*
builder
)
Prepare
(
config
interface
{})
(
err
error
)
{
func
(
b
*
builder
)
Prepare
(
config
...
interface
{})
(
err
error
)
{
cerr
:=
b
.
client
.
Call
(
"Builder.Prepare"
,
&
BuilderPrepareArgs
{
config
},
&
err
)
cerr
:=
b
.
client
.
Call
(
"Builder.Prepare"
,
&
BuilderPrepareArgs
{
config
},
&
err
)
if
cerr
!=
nil
{
if
cerr
!=
nil
{
err
=
cerr
err
=
cerr
...
@@ -109,7 +109,7 @@ func (b *builder) Cancel() {
...
@@ -109,7 +109,7 @@ func (b *builder) Cancel() {
}
}
func
(
b
*
BuilderServer
)
Prepare
(
args
*
BuilderPrepareArgs
,
reply
*
error
)
error
{
func
(
b
*
BuilderServer
)
Prepare
(
args
*
BuilderPrepareArgs
,
reply
*
error
)
error
{
err
:=
b
.
builder
.
Prepare
(
args
.
Config
)
err
:=
b
.
builder
.
Prepare
(
args
.
Config
s
...
)
if
err
!=
nil
{
if
err
!=
nil
{
*
reply
=
NewBasicError
(
err
)
*
reply
=
NewBasicError
(
err
)
}
}
...
...
packer/rpc/builder_test.go
View file @
9f5a2475
...
@@ -12,7 +12,7 @@ var testBuilderArtifact = &testArtifact{}
...
@@ -12,7 +12,7 @@ var testBuilderArtifact = &testArtifact{}
type
testBuilder
struct
{
type
testBuilder
struct
{
prepareCalled
bool
prepareCalled
bool
prepareConfig
interface
{}
prepareConfig
[]
interface
{}
runCalled
bool
runCalled
bool
runCache
packer
.
Cache
runCache
packer
.
Cache
runHook
packer
.
Hook
runHook
packer
.
Hook
...
@@ -23,7 +23,7 @@ type testBuilder struct {
...
@@ -23,7 +23,7 @@ type testBuilder struct {
nilRunResult
bool
nilRunResult
bool
}
}
func
(
b
*
testBuilder
)
Prepare
(
config
interface
{})
error
{
func
(
b
*
testBuilder
)
Prepare
(
config
...
interface
{})
error
{
b
.
prepareCalled
=
true
b
.
prepareCalled
=
true
b
.
prepareConfig
=
config
b
.
prepareConfig
=
config
return
nil
return
nil
...
@@ -68,7 +68,7 @@ func TestBuilderRPC(t *testing.T) {
...
@@ -68,7 +68,7 @@ func TestBuilderRPC(t *testing.T) {
bClient
:=
Builder
(
client
)
bClient
:=
Builder
(
client
)
bClient
.
Prepare
(
config
)
bClient
.
Prepare
(
config
)
assert
.
True
(
b
.
prepareCalled
,
"prepare should be called"
)
assert
.
True
(
b
.
prepareCalled
,
"prepare should be called"
)
assert
.
Equal
(
b
.
prepareConfig
,
42
,
"prepare should be called with right arg"
)
assert
.
Equal
(
b
.
prepareConfig
,
[]
interface
{}{
42
}
,
"prepare should be called with right arg"
)
// Test Run
// Test Run
cache
:=
new
(
testCache
)
cache
:=
new
(
testCache
)
...
...
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