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
3f0a268e
Commit
3f0a268e
authored
Aug 09, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer, packer/rpc: Update Build interface to allow variable overrides
parent
95b598f7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
19 deletions
+29
-19
packer/build.go
packer/build.go
+4
-3
packer/build_test.go
packer/build_test.go
+10
-10
packer/rpc/build.go
packer/rpc/build.go
+4
-4
packer/rpc/build_test.go
packer/rpc/build_test.go
+11
-2
No files found.
packer/build.go
View file @
3f0a268e
...
...
@@ -35,7 +35,7 @@ type Build interface {
// Prepare configures the various components of this build and reports
// any errors in doing so (such as syntax errors, validation errors, etc.)
Prepare
()
error
Prepare
(
v
map
[
string
]
string
)
error
// Run runs the actual builder, returning an artifact implementation
// of what is built. If anything goes wrong, an error is returned.
...
...
@@ -103,8 +103,9 @@ func (b *coreBuild) Name() string {
}
// 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
()
(
err
error
)
{
// and any hooks. This _must_ be called prior to Run. The parameter is the
// overrides for the variables within the template (if any).
func
(
b
*
coreBuild
)
Prepare
(
v
map
[
string
]
string
)
(
err
error
)
{
b
.
l
.
Lock
()
defer
b
.
l
.
Unlock
()
...
...
packer/build_test.go
View file @
3f0a268e
...
...
@@ -50,7 +50,7 @@ func TestBuild_Prepare(t *testing.T) {
build
:=
testBuild
()
builder
:=
build
.
builder
.
(
*
TestBuilder
)
build
.
Prepare
()
build
.
Prepare
(
nil
)
assert
.
True
(
builder
.
prepareCalled
,
"prepare should be called"
)
assert
.
Equal
(
builder
.
prepareConfig
,
[]
interface
{}{
42
,
packerConfig
},
"prepare config should be 42"
)
...
...
@@ -67,7 +67,7 @@ func TestBuild_Prepare(t *testing.T) {
func
TestBuild_Prepare_Twice
(
t
*
testing
.
T
)
{
build
:=
testBuild
()
if
err
:=
build
.
Prepare
();
err
!=
nil
{
if
err
:=
build
.
Prepare
(
nil
);
err
!=
nil
{
t
.
Fatalf
(
"bad error: %s"
,
err
)
}
...
...
@@ -82,7 +82,7 @@ func TestBuild_Prepare_Twice(t *testing.T) {
}
}()
build
.
Prepare
()
build
.
Prepare
(
nil
)
}
func
TestBuild_Prepare_Debug
(
t
*
testing
.
T
)
{
...
...
@@ -99,7 +99,7 @@ func TestBuild_Prepare_Debug(t *testing.T) {
builder
:=
build
.
builder
.
(
*
TestBuilder
)
build
.
SetDebug
(
true
)
build
.
Prepare
()
build
.
Prepare
(
nil
)
assert
.
True
(
builder
.
prepareCalled
,
"prepare should be called"
)
assert
.
Equal
(
builder
.
prepareConfig
,
[]
interface
{}{
42
,
packerConfig
},
"prepare config should be 42"
)
...
...
@@ -116,7 +116,7 @@ func TestBuild_Run(t *testing.T) {
ui
:=
testUi
()
build
:=
testBuild
()
build
.
Prepare
()
build
.
Prepare
(
nil
)
artifacts
,
err
:=
build
.
Run
(
ui
,
cache
)
assert
.
Nil
(
err
,
"should not error"
)
assert
.
Equal
(
len
(
artifacts
),
2
,
"should have two artifacts"
)
...
...
@@ -152,7 +152,7 @@ func TestBuild_Run_Artifacts(t *testing.T) {
build
:=
testBuild
()
build
.
postProcessors
=
[][]
coreBuildPostProcessor
{}
build
.
Prepare
()
build
.
Prepare
(
nil
)
artifacts
,
err
:=
build
.
Run
(
ui
,
cache
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
...
...
@@ -177,7 +177,7 @@ func TestBuild_Run_Artifacts(t *testing.T) {
},
}
build
.
Prepare
()
build
.
Prepare
(
nil
)
artifacts
,
err
=
build
.
Run
(
ui
,
cache
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
...
...
@@ -205,7 +205,7 @@ func TestBuild_Run_Artifacts(t *testing.T) {
},
}
build
.
Prepare
()
build
.
Prepare
(
nil
)
artifacts
,
err
=
build
.
Run
(
ui
,
cache
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
...
...
@@ -235,7 +235,7 @@ func TestBuild_Run_Artifacts(t *testing.T) {
},
}
build
.
Prepare
()
build
.
Prepare
(
nil
)
artifacts
,
err
=
build
.
Run
(
ui
,
cache
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
...
...
@@ -262,7 +262,7 @@ func TestBuild_Run_Artifacts(t *testing.T) {
},
}
build
.
Prepare
()
build
.
Prepare
(
nil
)
artifacts
,
err
=
build
.
Run
(
ui
,
cache
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
...
...
packer/rpc/build.go
View file @
3f0a268e
...
...
@@ -30,8 +30,8 @@ func (b *build) Name() (result string) {
return
}
func
(
b
*
build
)
Prepare
()
(
err
error
)
{
if
cerr
:=
b
.
client
.
Call
(
"Build.Prepare"
,
new
(
interface
{})
,
&
err
);
cerr
!=
nil
{
func
(
b
*
build
)
Prepare
(
v
map
[
string
]
string
)
(
err
error
)
{
if
cerr
:=
b
.
client
.
Call
(
"Build.Prepare"
,
v
,
&
err
);
cerr
!=
nil
{
return
cerr
}
...
...
@@ -86,8 +86,8 @@ func (b *BuildServer) Name(args *interface{}, reply *string) error {
return
nil
}
func
(
b
*
BuildServer
)
Prepare
(
args
interface
{}
,
reply
*
error
)
error
{
*
reply
=
b
.
build
.
Prepare
()
func
(
b
*
BuildServer
)
Prepare
(
v
map
[
string
]
string
,
reply
*
error
)
error
{
*
reply
=
b
.
build
.
Prepare
(
v
)
return
nil
}
...
...
packer/rpc/build_test.go
View file @
3f0a268e
...
...
@@ -13,6 +13,7 @@ var testBuildArtifact = &testArtifact{}
type
testBuild
struct
{
nameCalled
bool
prepareCalled
bool
prepareVars
map
[
string
]
string
runCalled
bool
runCache
packer
.
Cache
runUi
packer
.
Ui
...
...
@@ -28,8 +29,9 @@ func (b *testBuild) Name() string {
return
"name"
}
func
(
b
*
testBuild
)
Prepare
()
error
{
func
(
b
*
testBuild
)
Prepare
(
v
map
[
string
]
string
)
error
{
b
.
prepareCalled
=
true
b
.
prepareVars
=
v
return
nil
}
...
...
@@ -78,8 +80,15 @@ func TestBuildRPC(t *testing.T) {
assert
.
True
(
b
.
nameCalled
,
"name should be called"
)
// Test Prepare
bClient
.
Prepare
()
bClient
.
Prepare
(
map
[
string
]
string
{
"foo"
:
"bar"
}
)
assert
.
True
(
b
.
prepareCalled
,
"prepare should be called"
)
if
len
(
b
.
prepareVars
)
!=
1
{
t
.
Fatalf
(
"bad vars: %#v"
,
b
.
prepareVars
)
}
if
b
.
prepareVars
[
"foo"
]
!=
"bar"
{
t
.
Fatalf
(
"bad vars: %#v"
,
b
.
prepareVars
)
}
// Test Run
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