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
62309cb6
Commit
62309cb6
authored
Jun 09, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Build/Builder take a Cache object now
parent
a23500e0
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
55 additions
and
25 deletions
+55
-25
builder/amazonebs/builder.go
builder/amazonebs/builder.go
+1
-1
builder/vmware/builder.go
builder/vmware/builder.go
+1
-1
command/build/command.go
command/build/command.go
+1
-1
packer/build.go
packer/build.go
+3
-3
packer/build_test.go
packer/build_test.go
+3
-2
packer/builder.go
packer/builder.go
+1
-1
packer/builder_test.go
packer/builder_test.go
+3
-1
packer/cache_test.go
packer/cache_test.go
+14
-0
packer/plugin/builder.go
packer/plugin/builder.go
+2
-2
packer/plugin/builder_test.go
packer/plugin/builder_test.go
+1
-1
packer/rpc/build.go
packer/rpc/build.go
+3
-3
packer/rpc/build_test.go
packer/rpc/build_test.go
+8
-2
packer/rpc/builder.go
packer/rpc/builder.go
+5
-4
packer/rpc/builder_test.go
packer/rpc/builder_test.go
+9
-3
No files found.
builder/amazonebs/builder.go
View file @
62309cb6
...
...
@@ -87,7 +87,7 @@ func (b *Builder) Prepare(raw interface{}) (err error) {
return
}
func
(
b
*
Builder
)
Run
(
ui
packer
.
Ui
,
hook
packer
.
Hook
)
packer
.
Artifact
{
func
(
b
*
Builder
)
Run
(
ui
packer
.
Ui
,
hook
packer
.
Hook
,
cache
packer
.
Cache
)
packer
.
Artifact
{
// Basic sanity checks. These are panics now because the Prepare
// method should verify these exist and such.
if
b
.
config
.
AccessKey
==
""
{
...
...
builder/vmware/builder.go
View file @
62309cb6
...
...
@@ -172,7 +172,7 @@ func (b *Builder) Prepare(raw interface{}) (err error) {
return
nil
}
func
(
b
*
Builder
)
Run
(
ui
packer
.
Ui
,
hook
packer
.
Hook
)
packer
.
Artifact
{
func
(
b
*
Builder
)
Run
(
ui
packer
.
Ui
,
hook
packer
.
Hook
,
cache
packer
.
Cache
)
packer
.
Artifact
{
// Seed the random number generator
rand
.
Seed
(
time
.
Now
()
.
UTC
()
.
UnixNano
())
...
...
command/build/command.go
View file @
62309cb6
...
...
@@ -138,7 +138,7 @@ func (c Command) Run(env packer.Environment, args []string) int {
log
.
Printf
(
"Starting build run: %s"
,
b
.
Name
())
ui
:=
buildUis
[
b
.
Name
()]
artifacts
[
b
.
Name
()]
=
b
.
Run
(
ui
)
artifacts
[
b
.
Name
()]
=
b
.
Run
(
ui
,
env
.
Cache
()
)
ui
.
Say
(
"Build finished."
)
}(
b
)
}
...
...
packer/build.go
View file @
62309cb6
...
...
@@ -7,7 +7,7 @@ import "log"
type
Build
interface
{
Name
()
string
Prepare
(
Ui
)
error
Run
(
Ui
)
Artifact
Run
(
Ui
,
Cache
)
Artifact
Cancel
()
}
...
...
@@ -60,7 +60,7 @@ func (b *coreBuild) Prepare(ui Ui) (err error) {
}
// Runs the actual build. Prepare must be called prior to running this.
func
(
b
*
coreBuild
)
Run
(
ui
Ui
)
Artifact
{
func
(
b
*
coreBuild
)
Run
(
ui
Ui
,
cache
Cache
)
Artifact
{
if
!
b
.
prepareCalled
{
panic
(
"Prepare must be called first"
)
}
...
...
@@ -87,7 +87,7 @@ func (b *coreBuild) Run(ui Ui) Artifact {
}
hook
:=
&
DispatchHook
{
hooks
}
return
b
.
builder
.
Run
(
ui
,
hook
)
return
b
.
builder
.
Run
(
ui
,
hook
,
cache
)
}
// Cancels the build if it is running.
...
...
packer/build_test.go
View file @
62309cb6
...
...
@@ -53,11 +53,12 @@ func TestBuild_Prepare(t *testing.T) {
func
TestBuild_Run
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
cache
:=
&
TestCache
{}
ui
:=
testUi
()
build
:=
testBuild
()
build
.
Prepare
(
ui
)
build
.
Run
(
ui
)
build
.
Run
(
ui
,
cache
)
coreB
:=
build
.
(
*
coreBuild
)
...
...
@@ -89,7 +90,7 @@ func TestBuild_RunBeforePrepare(t *testing.T) {
assert
.
Equal
(
p
.
(
string
),
"Prepare must be called first"
,
"right panic"
)
}()
testBuild
()
.
Run
(
testUi
())
testBuild
()
.
Run
(
testUi
()
,
&
TestCache
{}
)
}
func
TestBuild_Cancel
(
t
*
testing
.
T
)
{
...
...
packer/builder.go
View file @
62309cb6
...
...
@@ -10,7 +10,7 @@ type Builder interface {
Prepare
(
config
interface
{})
error
// Run is where the actual build should take place. It takes a Build and a Ui.
Run
(
ui
Ui
,
hook
Hook
)
Artifact
Run
(
ui
Ui
,
hook
Hook
,
cache
Cache
)
Artifact
// Cancel cancels a possibly running Builder. This should block until
// the builder actually cancels and cleans up after itself.
...
...
packer/builder_test.go
View file @
62309cb6
...
...
@@ -4,6 +4,7 @@ type TestBuilder struct {
prepareCalled
bool
prepareConfig
interface
{}
runCalled
bool
runCache
Cache
runHook
Hook
runUi
Ui
cancelCalled
bool
...
...
@@ -15,10 +16,11 @@ func (tb *TestBuilder) Prepare(config interface{}) error {
return
nil
}
func
(
tb
*
TestBuilder
)
Run
(
ui
Ui
,
h
Hook
)
Artifact
{
func
(
tb
*
TestBuilder
)
Run
(
ui
Ui
,
h
Hook
,
c
Cache
)
Artifact
{
tb
.
runCalled
=
true
tb
.
runHook
=
h
tb
.
runUi
=
ui
tb
.
runCache
=
c
return
nil
}
...
...
packer/cache_test.go
View file @
62309cb6
...
...
@@ -6,6 +6,20 @@ import (
"testing"
)
type
TestCache
struct
{}
func
(
TestCache
)
Lock
(
string
)
string
{
return
""
}
func
(
TestCache
)
Unlock
(
string
)
{}
func
(
TestCache
)
RLock
(
string
)
(
string
,
bool
)
{
return
""
,
false
}
func
(
TestCache
)
RUnlock
(
string
)
{}
func
TestFileCache_Implements
(
t
*
testing
.
T
)
{
var
raw
interface
{}
raw
=
&
FileCache
{}
...
...
packer/plugin/builder.go
View file @
62309cb6
...
...
@@ -22,13 +22,13 @@ func (b *cmdBuilder) Prepare(config interface{}) error {
return
b
.
builder
.
Prepare
(
config
)
}
func
(
b
*
cmdBuilder
)
Run
(
ui
packer
.
Ui
,
hook
packer
.
Hook
)
packer
.
Artifact
{
func
(
b
*
cmdBuilder
)
Run
(
ui
packer
.
Ui
,
hook
packer
.
Hook
,
cache
packer
.
Cache
)
packer
.
Artifact
{
defer
func
()
{
r
:=
recover
()
b
.
checkExit
(
r
,
nil
)
}()
return
b
.
builder
.
Run
(
ui
,
hook
)
return
b
.
builder
.
Run
(
ui
,
hook
,
cache
)
}
func
(
b
*
cmdBuilder
)
Cancel
()
{
...
...
packer/plugin/builder_test.go
View file @
62309cb6
...
...
@@ -13,7 +13,7 @@ func (helperBuilder) Prepare(interface{}) error {
return
nil
}
func
(
helperBuilder
)
Run
(
packer
.
Ui
,
packer
.
Hook
)
packer
.
Artifact
{
func
(
helperBuilder
)
Run
(
packer
.
Ui
,
packer
.
Hook
,
packer
.
Cache
)
packer
.
Artifact
{
return
nil
}
...
...
packer/rpc/build.go
View file @
62309cb6
...
...
@@ -48,10 +48,10 @@ func (b *build) Prepare(ui packer.Ui) (err error) {
return
}
func
(
b
*
build
)
Run
(
ui
packer
.
Ui
)
packer
.
Artifact
{
func
(
b
*
build
)
Run
(
ui
packer
.
Ui
,
cache
packer
.
Cache
)
packer
.
Artifact
{
// Create and start the server for the UI
// TODO: Error handling
server
:=
rpc
.
NewServer
()
RegisterCache
(
server
,
cache
)
RegisterUi
(
server
,
ui
)
args
:=
&
BuildRunArgs
{
serveSingleConn
(
server
)}
...
...
@@ -95,7 +95,7 @@ func (b *BuildServer) Run(args *BuildRunArgs, reply *string) error {
return
err
}
artifact
:=
b
.
build
.
Run
(
&
Ui
{
client
})
artifact
:=
b
.
build
.
Run
(
&
Ui
{
client
}
,
Cache
(
client
)
)
// Wrap the artifact
server
:=
rpc
.
NewServer
()
...
...
packer/rpc/build_test.go
View file @
62309cb6
...
...
@@ -14,6 +14,7 @@ type testBuild struct {
prepareCalled
bool
prepareUi
packer
.
Ui
runCalled
bool
runCache
packer
.
Cache
runUi
packer
.
Ui
cancelCalled
bool
}
...
...
@@ -29,8 +30,9 @@ func (b *testBuild) Prepare(ui packer.Ui) error {
return
nil
}
func
(
b
*
testBuild
)
Run
(
ui
packer
.
Ui
)
packer
.
Artifact
{
func
(
b
*
testBuild
)
Run
(
ui
packer
.
Ui
,
cache
packer
.
Cache
)
packer
.
Artifact
{
b
.
runCalled
=
true
b
.
runCache
=
cache
b
.
runUi
=
ui
return
testBuildArtifact
}
...
...
@@ -65,12 +67,16 @@ func TestBuildRPC(t *testing.T) {
assert
.
True
(
b
.
prepareCalled
,
"prepare should be called"
)
// Test Run
cache
:=
new
(
testCache
)
ui
=
new
(
testUi
)
bClient
.
Run
(
ui
)
bClient
.
Run
(
ui
,
cache
)
assert
.
True
(
b
.
runCalled
,
"run should be called"
)
// Test the UI given to run, which should be fully functional
if
b
.
runCalled
{
b
.
runCache
.
Lock
(
"foo"
)
assert
.
True
(
cache
.
lockCalled
,
"lock should be called"
)
b
.
runUi
.
Say
(
"format"
)
assert
.
True
(
ui
.
sayCalled
,
"say should be called"
)
assert
.
Equal
(
ui
.
sayMessage
,
"format"
,
"message should be correct"
)
...
...
packer/rpc/builder.go
View file @
62309cb6
...
...
@@ -46,12 +46,12 @@ func (b *builder) Prepare(config interface{}) (err error) {
return
}
func
(
b
*
builder
)
Run
(
ui
packer
.
Ui
,
hook
packer
.
Hook
)
packer
.
Artifact
{
func
(
b
*
builder
)
Run
(
ui
packer
.
Ui
,
hook
packer
.
Hook
,
cache
packer
.
Cache
)
packer
.
Artifact
{
// Create and start the server for the Build and UI
// TODO: Error handling
server
:=
rpc
.
NewServer
()
Register
Ui
(
server
,
ui
)
Register
Cache
(
server
,
cache
)
RegisterHook
(
server
,
hook
)
RegisterUi
(
server
,
ui
)
// Create a server for the response
responseL
:=
netListenerInRange
(
portRangeMin
,
portRangeMax
)
...
...
@@ -129,9 +129,10 @@ func (b *BuilderServer) Run(args *BuilderRunArgs, reply *interface{}) error {
go
func
()
{
defer
responseC
.
Close
()
cache
:=
Cache
(
client
)
hook
:=
Hook
(
client
)
ui
:=
&
Ui
{
client
}
artifact
:=
b
.
builder
.
Run
(
ui
,
hook
)
artifact
:=
b
.
builder
.
Run
(
ui
,
hook
,
cache
)
responseAddress
:=
""
if
artifact
!=
nil
{
...
...
packer/rpc/builder_test.go
View file @
62309cb6
...
...
@@ -13,6 +13,7 @@ type testBuilder struct {
prepareCalled
bool
prepareConfig
interface
{}
runCalled
bool
runCache
packer
.
Cache
runHook
packer
.
Hook
runUi
packer
.
Ui
cancelCalled
bool
...
...
@@ -26,7 +27,8 @@ func (b *testBuilder) Prepare(config interface{}) error {
return
nil
}
func
(
b
*
testBuilder
)
Run
(
ui
packer
.
Ui
,
hook
packer
.
Hook
)
packer
.
Artifact
{
func
(
b
*
testBuilder
)
Run
(
ui
packer
.
Ui
,
hook
packer
.
Hook
,
cache
packer
.
Cache
)
packer
.
Artifact
{
b
.
runCache
=
cache
b
.
runCalled
=
true
b
.
runHook
=
hook
b
.
runUi
=
ui
...
...
@@ -65,12 +67,16 @@ func TestBuilderRPC(t *testing.T) {
assert
.
Equal
(
b
.
prepareConfig
,
42
,
"prepare should be called with right arg"
)
// Test Run
cache
:=
new
(
testCache
)
hook
:=
&
testHook
{}
ui
:=
&
testUi
{}
artifact
:=
bClient
.
Run
(
ui
,
hook
)
artifact
:=
bClient
.
Run
(
ui
,
hook
,
cache
)
assert
.
True
(
b
.
runCalled
,
"runs hould be called"
)
if
b
.
runCalled
{
b
.
runCache
.
Lock
(
"foo"
)
assert
.
True
(
cache
.
lockCalled
,
"lock should be called"
)
b
.
runHook
.
Run
(
"foo"
,
nil
,
nil
,
nil
)
assert
.
True
(
hook
.
runCalled
,
"run should be called"
)
...
...
@@ -83,7 +89,7 @@ func TestBuilderRPC(t *testing.T) {
// Test run with nil result
b
.
nilRunResult
=
true
artifact
=
bClient
.
Run
(
ui
,
hook
)
artifact
=
bClient
.
Run
(
ui
,
hook
,
cache
)
assert
.
Nil
(
artifact
,
"should be nil"
)
// Test Cancel
...
...
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