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
21869295
Commit
21869295
authored
Jun 18, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer: Build can return multiple artifacts
parent
9c89e33b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
31 deletions
+49
-31
command/build/command.go
command/build/command.go
+14
-12
packer/build.go
packer/build.go
+10
-3
packer/rpc/build.go
packer/rpc/build.go
+20
-13
packer/rpc/build_test.go
packer/rpc/build_test.go
+5
-3
No files found.
command/build/command.go
View file @
21869295
...
...
@@ -163,7 +163,7 @@ func (c Command) Run(env packer.Environment, args []string) int {
// Run all the builds in parallel and wait for them to complete
var
interruptWg
,
wg
sync
.
WaitGroup
interrupted
:=
false
artifacts
:=
make
(
map
[
string
]
packer
.
Artifact
)
artifacts
:=
make
(
map
[
string
]
[]
packer
.
Artifact
)
errors
:=
make
(
map
[
string
]
error
)
for
_
,
b
:=
range
builds
{
// Increment the waitgroup so we wait for this item to finish properly
...
...
@@ -191,14 +191,14 @@ func (c Command) Run(env packer.Environment, args []string) int {
name
:=
b
.
Name
()
log
.
Printf
(
"Starting build run: %s"
,
name
)
ui
:=
buildUis
[
name
]
artifact
,
err
:=
b
.
Run
(
ui
,
env
.
Cache
())
runArtifacts
,
err
:=
b
.
Run
(
ui
,
env
.
Cache
())
if
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Build errored: %s"
,
err
))
errors
[
name
]
=
err
}
else
{
ui
.
Say
(
"Build finished."
)
artifacts
[
name
]
=
artifact
artifacts
[
name
]
=
runArtifacts
}
}(
b
)
...
...
@@ -235,17 +235,19 @@ func (c Command) Run(env packer.Environment, args []string) int {
if
len
(
artifacts
)
>
0
{
env
.
Ui
()
.
Say
(
"
\n
==> Builds finished. The artifacts of successful builds are:"
)
for
name
,
artifact
:=
range
artifacts
{
var
message
bytes
.
Buffer
fmt
.
Fprintf
(
&
message
,
"--> %s: "
,
name
)
for
name
,
buildArtifacts
:=
range
artifacts
{
for
_
,
artifact
:=
range
buildArtifacts
{
var
message
bytes
.
Buffer
fmt
.
Fprintf
(
&
message
,
"--> %s: "
,
name
)
if
artifact
!=
nil
{
fmt
.
Fprintf
(
&
message
,
artifact
.
String
())
}
else
{
fmt
.
Print
(
"<nothing>"
)
}
if
artifact
!=
nil
{
fmt
.
Fprintf
(
&
message
,
artifact
.
String
())
}
else
{
fmt
.
Print
(
"<nothing>"
)
env
.
Ui
()
.
Say
(
message
.
String
())
}
env
.
Ui
()
.
Say
(
message
.
String
())
}
}
...
...
packer/build.go
View file @
21869295
...
...
@@ -23,7 +23,7 @@ type Build interface {
// Run runs the actual builder, returning an artifact implementation
// of what is built. If anything goes wrong, an error is returned.
Run
(
Ui
,
Cache
)
(
Artifact
,
error
)
Run
(
Ui
,
Cache
)
(
[]
Artifact
,
error
)
// Cancel will cancel a running build. This will block until the build
// is actually completely cancelled.
...
...
@@ -113,7 +113,7 @@ func (b *coreBuild) Prepare() (err error) {
}
// Runs the actual build. Prepare must be called prior to running this.
func
(
b
*
coreBuild
)
Run
(
ui
Ui
,
cache
Cache
)
(
Artifact
,
error
)
{
func
(
b
*
coreBuild
)
Run
(
ui
Ui
,
cache
Cache
)
(
[]
Artifact
,
error
)
{
if
!
b
.
prepareCalled
{
panic
(
"Prepare must be called first"
)
}
...
...
@@ -140,7 +140,14 @@ func (b *coreBuild) Run(ui Ui, cache Cache) (Artifact, error) {
}
hook
:=
&
DispatchHook
{
hooks
}
return
b
.
builder
.
Run
(
ui
,
hook
,
cache
)
artifacts
:=
make
([]
Artifact
,
0
,
1
)
artifact
,
err
:=
b
.
builder
.
Run
(
ui
,
hook
,
cache
)
if
artifact
!=
nil
{
artifacts
=
append
(
artifacts
,
artifact
)
}
return
artifacts
,
err
}
func
(
b
*
coreBuild
)
SetDebug
(
val
bool
)
{
...
...
packer/rpc/build.go
View file @
21869295
...
...
@@ -38,24 +38,29 @@ func (b *build) Prepare() (err error) {
return
}
func
(
b
*
build
)
Run
(
ui
packer
.
Ui
,
cache
packer
.
Cache
)
(
packer
.
Artifact
,
error
)
{
func
(
b
*
build
)
Run
(
ui
packer
.
Ui
,
cache
packer
.
Cache
)
(
[]
packer
.
Artifact
,
error
)
{
// Create and start the server for the UI
server
:=
rpc
.
NewServer
()
RegisterCache
(
server
,
cache
)
RegisterUi
(
server
,
ui
)
args
:=
&
BuildRunArgs
{
serveSingleConn
(
server
)}
var
re
ply
string
if
err
:=
b
.
client
.
Call
(
"Build.Run"
,
args
,
&
re
ply
);
err
!=
nil
{
var
re
sult
[]
string
if
err
:=
b
.
client
.
Call
(
"Build.Run"
,
args
,
&
re
sult
);
err
!=
nil
{
return
nil
,
err
}
client
,
err
:=
rpc
.
Dial
(
"tcp"
,
reply
)
if
err
!=
nil
{
return
nil
,
err
artifacts
:=
make
([]
packer
.
Artifact
,
len
(
result
))
for
i
,
addr
:=
range
result
{
client
,
err
:=
rpc
.
Dial
(
"tcp"
,
addr
)
if
err
!=
nil
{
return
nil
,
err
}
artifacts
[
i
]
=
Artifact
(
client
)
}
return
Artifact
(
client
)
,
nil
return
artifacts
,
nil
}
func
(
b
*
build
)
SetDebug
(
val
bool
)
{
...
...
@@ -80,22 +85,24 @@ func (b *BuildServer) Prepare(args interface{}, reply *error) error {
return
nil
}
func
(
b
*
BuildServer
)
Run
(
args
*
BuildRunArgs
,
reply
*
string
)
error
{
func
(
b
*
BuildServer
)
Run
(
args
*
BuildRunArgs
,
reply
*
[]
string
)
error
{
client
,
err
:=
rpc
.
Dial
(
"tcp"
,
args
.
UiRPCAddress
)
if
err
!=
nil
{
return
err
}
artifact
,
err
:=
b
.
build
.
Run
(
&
Ui
{
client
},
Cache
(
client
))
artifact
s
,
err
:=
b
.
build
.
Run
(
&
Ui
{
client
},
Cache
(
client
))
if
err
!=
nil
{
return
NewBasicError
(
err
)
}
// Wrap the artifact
server
:=
rpc
.
NewServer
()
RegisterArtifact
(
server
,
artifact
)
*
reply
=
make
([]
string
,
len
(
artifacts
))
for
i
,
artifact
:=
range
artifacts
{
server
:=
rpc
.
NewServer
()
RegisterArtifact
(
server
,
artifact
)
(
*
reply
)[
i
]
=
serveSingleConn
(
server
)
}
*
reply
=
serveSingleConn
(
server
)
return
nil
}
...
...
packer/rpc/build_test.go
View file @
21869295
...
...
@@ -32,7 +32,7 @@ func (b *testBuild) Prepare() error {
return
nil
}
func
(
b
*
testBuild
)
Run
(
ui
packer
.
Ui
,
cache
packer
.
Cache
)
(
packer
.
Artifact
,
error
)
{
func
(
b
*
testBuild
)
Run
(
ui
packer
.
Ui
,
cache
packer
.
Cache
)
(
[]
packer
.
Artifact
,
error
)
{
b
.
runCalled
=
true
b
.
runCache
=
cache
b
.
runUi
=
ui
...
...
@@ -40,7 +40,7 @@ func (b *testBuild) Run(ui packer.Ui, cache packer.Cache) (packer.Artifact, erro
if
b
.
errRunResult
{
return
nil
,
errors
.
New
(
"foo"
)
}
else
{
return
testBuildArtifact
,
nil
return
[]
packer
.
Artifact
{
testBuildArtifact
}
,
nil
}
}
...
...
@@ -79,9 +79,11 @@ func TestBuildRPC(t *testing.T) {
// Test Run
cache
:=
new
(
testCache
)
ui
:=
new
(
testUi
)
_
,
err
=
bClient
.
Run
(
ui
,
cache
)
artifacts
,
err
:
=
bClient
.
Run
(
ui
,
cache
)
assert
.
True
(
b
.
runCalled
,
"run should be called"
)
assert
.
Nil
(
err
,
"should not error"
)
assert
.
Equal
(
len
(
artifacts
),
1
,
"should have one artifact"
)
assert
.
Equal
(
artifacts
[
0
]
.
BuilderId
(),
"bid"
,
"should have proper builder id"
)
// Test the UI given to run, which should be fully functional
if
b
.
runCalled
{
...
...
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