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
a8b056e9
Commit
a8b056e9
authored
Dec 10, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer/rpc: builds
parent
bd6fbc05
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
54 additions
and
63 deletions
+54
-63
packer/rpc/build.go
packer/rpc/build.go
+26
-25
packer/rpc/build_test.go
packer/rpc/build_test.go
+12
-37
packer/rpc/client.go
packer/rpc/client.go
+7
-0
packer/rpc/server.go
packer/rpc/server.go
+1
-1
packer/rpc/server_new.go
packer/rpc/server_new.go
+8
-0
No files found.
packer/rpc/build.go
View file @
a8b056e9
...
...
@@ -9,16 +9,14 @@ import (
// over an RPC connection.
type
build
struct
{
client
*
rpc
.
Client
mux
*
MuxConn
}
// BuildServer wraps a packer.Build implementation and makes it exportable
// as part of a Golang RPC server.
type
BuildServer
struct
{
build
packer
.
Build
}
type
BuildRunArgs
struct
{
UiRPCAddress
string
mux
*
MuxConn
}
type
BuildPrepareResponse
struct
{
...
...
@@ -27,7 +25,7 @@ type BuildPrepareResponse struct {
}
func
Build
(
client
*
rpc
.
Client
)
*
build
{
return
&
build
{
client
}
return
&
build
{
client
:
client
}
}
func
(
b
*
build
)
Name
()
(
result
string
)
{
...
...
@@ -45,25 +43,25 @@ func (b *build) Prepare(v map[string]string) ([]string, 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
result
[]
string
if
err
:=
b
.
client
.
Call
(
"Build.Run"
,
args
,
&
result
);
err
!=
nil
{
nextId
:=
b
.
mux
.
NextId
()
server
:=
NewServerWithMux
(
b
.
mux
,
nextId
)
server
.
RegisterCache
(
cache
)
server
.
RegisterUi
(
ui
)
go
server
.
Serve
()
var
result
[]
uint32
if
err
:=
b
.
client
.
Call
(
"Build.Run"
,
nextId
,
&
result
);
err
!=
nil
{
return
nil
,
err
}
artifacts
:=
make
([]
packer
.
Artifact
,
len
(
result
))
for
i
,
addr
:=
range
result
{
client
,
err
:=
rpcDial
(
addr
)
for
i
,
streamId
:=
range
result
{
client
,
err
:=
NewClientWithMux
(
b
.
mux
,
streamId
)
if
err
!=
nil
{
return
nil
,
err
}
artifacts
[
i
]
=
Artifact
(
client
)
artifacts
[
i
]
=
client
.
Artifact
(
)
}
return
artifacts
,
nil
...
...
@@ -101,23 +99,26 @@ func (b *BuildServer) Prepare(v map[string]string, resp *BuildPrepareResponse) e
return
nil
}
func
(
b
*
BuildServer
)
Run
(
args
*
BuildRunArgs
,
reply
*
[]
string
)
error
{
client
,
err
:=
rpcDial
(
args
.
UiRPCAddress
)
func
(
b
*
BuildServer
)
Run
(
streamId
uint32
,
reply
*
[]
uint32
)
error
{
client
,
err
:=
NewClientWithMux
(
b
.
mux
,
streamId
)
if
err
!=
nil
{
return
err
return
NewBasicError
(
err
)
}
defer
client
.
Close
()
ui
:=
&
Ui
{
client
:
client
}
artifacts
,
err
:=
b
.
build
.
Run
(
ui
,
Cache
(
client
))
artifacts
,
err
:=
b
.
build
.
Run
(
client
.
Ui
(),
client
.
Cache
())
if
err
!=
nil
{
return
NewBasicError
(
err
)
}
*
reply
=
make
([]
string
,
len
(
artifacts
))
*
reply
=
make
([]
uint32
,
len
(
artifacts
))
for
i
,
artifact
:=
range
artifacts
{
server
:=
rpc
.
NewServer
()
RegisterArtifact
(
server
,
artifact
)
(
*
reply
)[
i
]
=
serveSingleConn
(
server
)
streamId
:=
b
.
mux
.
NextId
()
server
:=
NewServerWithMux
(
b
.
mux
,
streamId
)
server
.
RegisterArtifact
(
artifact
)
go
server
.
Serve
()
(
*
reply
)[
i
]
=
streamId
}
return
nil
...
...
packer/rpc/build_test.go
View file @
a8b056e9
...
...
@@ -3,7 +3,6 @@ package rpc
import
(
"errors"
"github.com/mitchellh/packer/packer"
"net/rpc"
"reflect"
"testing"
)
...
...
@@ -60,25 +59,13 @@ func (b *testBuild) Cancel() {
b
.
cancelCalled
=
true
}
func
buildRPCClient
(
t
*
testing
.
T
)
(
*
testBuild
,
packer
.
Build
)
{
// Create the interface to test
b
:=
new
(
testBuild
)
// Start the server
server
:=
rpc
.
NewServer
()
RegisterBuild
(
server
,
b
)
address
:=
serveSingleConn
(
server
)
// Create the client over RPC and run some methods to verify it works
client
,
err
:=
rpc
.
Dial
(
"tcp"
,
address
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
return
b
,
Build
(
client
)
}
func
TestBuild
(
t
*
testing
.
T
)
{
b
,
bClient
:=
buildRPCClient
(
t
)
b
:=
new
(
testBuild
)
client
,
server
:=
testClientServer
(
t
)
defer
client
.
Close
()
defer
server
.
Close
()
server
.
RegisterBuild
(
b
)
bClient
:=
client
.
Build
()
// Test Name
bClient
.
Name
()
...
...
@@ -120,23 +107,6 @@ func TestBuild(t *testing.T) {
t
.
Fatalf
(
"bad: %#v"
,
artifacts
)
}
// Test the UI given to run, which should be fully functional
if
b
.
runCalled
{
b
.
runCache
.
Lock
(
"foo"
)
if
!
cache
.
lockCalled
{
t
.
Fatal
(
"lock shuld be called"
)
}
b
.
runUi
.
Say
(
"format"
)
if
!
ui
.
sayCalled
{
t
.
Fatal
(
"say should be called"
)
}
if
ui
.
sayMessage
!=
"format"
{
t
.
Fatalf
(
"bad: %#v"
,
ui
.
sayMessage
)
}
}
// Test run with an error
b
.
errRunResult
=
true
_
,
err
=
bClient
.
Run
(
ui
,
cache
)
...
...
@@ -164,7 +134,12 @@ func TestBuild(t *testing.T) {
}
func
TestBuildPrepare_Warnings
(
t
*
testing
.
T
)
{
b
,
bClient
:=
buildRPCClient
(
t
)
b
:=
new
(
testBuild
)
client
,
server
:=
testClientServer
(
t
)
defer
client
.
Close
()
defer
server
.
Close
()
server
.
RegisterBuild
(
b
)
bClient
:=
client
.
Build
()
expected
:=
[]
string
{
"foo"
}
b
.
prepareWarnings
=
expected
...
...
packer/rpc/client.go
View file @
a8b056e9
...
...
@@ -45,6 +45,13 @@ func (c *Client) Artifact() packer.Artifact {
}
}
func
(
c
*
Client
)
Build
()
packer
.
Build
{
return
&
build
{
client
:
c
.
client
,
mux
:
c
.
mux
,
}
}
func
(
c
*
Client
)
Builder
()
packer
.
Builder
{
return
&
builder
{
client
:
c
.
client
,
...
...
packer/rpc/server.go
View file @
a8b056e9
...
...
@@ -14,7 +14,7 @@ func RegisterArtifact(s *rpc.Server, a packer.Artifact) {
// Registers the appropriate endpoint on an RPC server to serve a
// Packer Build.
func
RegisterBuild
(
s
*
rpc
.
Server
,
b
packer
.
Build
)
{
registerComponent
(
s
,
"Build"
,
&
BuildServer
{
b
},
false
)
registerComponent
(
s
,
"Build"
,
&
BuildServer
{
b
uild
:
b
},
false
)
}
// Registers the appropriate endpoint on an RPC server to serve a
...
...
packer/rpc/server_new.go
View file @
a8b056e9
...
...
@@ -13,6 +13,7 @@ var endpointId uint64
const
(
DefaultArtifactEndpoint
string
=
"Artifact"
DefaultBuildEndpoint
=
"Build"
DefaultBuilderEndpoint
=
"Builder"
DefaultCacheEndpoint
=
"Cache"
DefaultCommandEndpoint
=
"Command"
...
...
@@ -55,6 +56,13 @@ func (s *Server) RegisterArtifact(a packer.Artifact) {
})
}
func
(
s
*
Server
)
RegisterBuild
(
b
packer
.
Build
)
{
s
.
server
.
RegisterName
(
DefaultBuildEndpoint
,
&
BuildServer
{
build
:
b
,
mux
:
s
.
mux
,
})
}
func
(
s
*
Server
)
RegisterBuilder
(
b
packer
.
Builder
)
{
s
.
server
.
RegisterName
(
DefaultBuilderEndpoint
,
&
BuilderServer
{
builder
:
b
,
...
...
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