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
8edbcf95
Commit
8edbcf95
authored
Apr 26, 2014
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1067 from mitchellh/f-msgpack-rpc
core: Replace Gob RPC with MsgPack RPC
parents
130c0b1c
5dec2ddb
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
38 additions
and
15 deletions
+38
-15
common/config.go
common/config.go
+10
-1
packer/plugin/server.go
packer/plugin/server.go
+1
-1
packer/rpc/builder.go
packer/rpc/builder.go
+7
-7
packer/rpc/builder_test.go
packer/rpc/builder_test.go
+3
-2
packer/rpc/client.go
packer/rpc/client.go
+5
-1
packer/rpc/error.go
packer/rpc/error.go
+4
-0
packer/rpc/post_processor_test.go
packer/rpc/post_processor_test.go
+2
-1
packer/rpc/provisioner_test.go
packer/rpc/provisioner_test.go
+2
-1
packer/rpc/server.go
packer/rpc/server.go
+4
-1
No files found.
common/config.go
View file @
8edbcf95
...
...
@@ -191,8 +191,17 @@ func decodeConfigHook(raws []interface{}) (mapstructure.DecodeHookFunc, error) {
// First thing we do is decode PackerConfig so that we can have access
// to the user variables so that we can process some templates.
var
pc
PackerConfig
decoderConfig
:=
&
mapstructure
.
DecoderConfig
{
Result
:
&
pc
,
WeaklyTypedInput
:
true
,
}
decoder
,
err
:=
mapstructure
.
NewDecoder
(
decoderConfig
)
if
err
!=
nil
{
return
nil
,
err
}
for
_
,
raw
:=
range
raws
{
if
err
:=
mapstructure
.
Decode
(
raw
,
&
pc
);
err
!=
nil
{
if
err
:=
decoder
.
Decode
(
raw
);
err
!=
nil
{
return
nil
,
err
}
}
...
...
packer/plugin/server.go
View file @
8edbcf95
...
...
@@ -33,7 +33,7 @@ const MagicCookieValue = "d602bf8f470bc67ca7faa0386276bbdd4330efaf76d1a219cb4d69
// The APIVersion is outputted along with the RPC address. The plugin
// client validates this API version and will show an error if it doesn't
// know how to speak it.
const
APIVersion
=
"
2
"
const
APIVersion
=
"
3
"
// Server waits for a connection to this plugin and returns a Packer
// RPC server that you can use to register components and serve them.
...
...
packer/rpc/builder.go
View file @
8edbcf95
...
...
@@ -26,7 +26,7 @@ type BuilderPrepareArgs struct {
type
BuilderPrepareResponse
struct
{
Warnings
[]
string
Error
e
rror
Error
*
BasicE
rror
}
func
(
b
*
builder
)
Prepare
(
config
...
interface
{})
([]
string
,
error
)
{
...
...
@@ -35,8 +35,12 @@ func (b *builder) Prepare(config ...interface{}) ([]string, error) {
if
cerr
!=
nil
{
return
nil
,
cerr
}
var
err
error
=
nil
if
resp
.
Error
!=
nil
{
err
=
resp
.
Error
}
return
resp
.
Warnings
,
resp
.
Erro
r
return
resp
.
Warnings
,
er
r
}
func
(
b
*
builder
)
Run
(
ui
packer
.
Ui
,
hook
packer
.
Hook
,
cache
packer
.
Cache
)
(
packer
.
Artifact
,
error
)
{
...
...
@@ -72,13 +76,9 @@ func (b *builder) Cancel() {
func
(
b
*
BuilderServer
)
Prepare
(
args
*
BuilderPrepareArgs
,
reply
*
BuilderPrepareResponse
)
error
{
warnings
,
err
:=
b
.
builder
.
Prepare
(
args
.
Configs
...
)
if
err
!=
nil
{
err
=
NewBasicError
(
err
)
}
*
reply
=
BuilderPrepareResponse
{
Warnings
:
warnings
,
Error
:
err
,
Error
:
NewBasicError
(
err
)
,
}
return
nil
}
...
...
packer/rpc/builder_test.go
View file @
8edbcf95
...
...
@@ -30,8 +30,9 @@ func TestBuilderPrepare(t *testing.T) {
t
.
Fatal
(
"should be called"
)
}
if
!
reflect
.
DeepEqual
(
b
.
PrepareConfig
,
[]
interface
{}{
42
})
{
t
.
Fatalf
(
"bad: %#v"
,
b
.
PrepareConfig
)
expected
:=
[]
interface
{}{
int64
(
42
)}
if
!
reflect
.
DeepEqual
(
b
.
PrepareConfig
,
expected
)
{
t
.
Fatalf
(
"bad: %#v != %#v"
,
b
.
PrepareConfig
,
expected
)
}
}
...
...
packer/rpc/client.go
View file @
8edbcf95
...
...
@@ -2,6 +2,7 @@ package rpc
import
(
"github.com/mitchellh/packer/packer"
"github.com/ugorji/go/codec"
"io"
"log"
"net/rpc"
...
...
@@ -32,9 +33,12 @@ func newClientWithMux(mux *MuxConn, streamId uint32) (*Client, error) {
return
nil
,
err
}
var
h
codec
.
MsgpackHandle
clientCodec
:=
codec
.
GoRpc
.
ClientCodec
(
clientConn
,
&
h
)
return
&
Client
{
mux
:
mux
,
client
:
rpc
.
NewClient
(
clientConn
),
client
:
rpc
.
NewClient
WithCodec
(
clientCodec
),
closeMux
:
false
,
},
nil
}
...
...
packer/rpc/error.go
View file @
8edbcf95
...
...
@@ -9,6 +9,10 @@ type BasicError struct {
}
func
NewBasicError
(
err
error
)
*
BasicError
{
if
err
==
nil
{
return
nil
}
return
&
BasicError
{
err
.
Error
()}
}
...
...
packer/rpc/post_processor_test.go
View file @
8edbcf95
...
...
@@ -54,7 +54,8 @@ func TestPostProcessorRPC(t *testing.T) {
t
.
Fatal
(
"config should be called"
)
}
if
!
reflect
.
DeepEqual
(
p
.
configVal
,
[]
interface
{}{
42
})
{
expected
:=
[]
interface
{}{
int64
(
42
)}
if
!
reflect
.
DeepEqual
(
p
.
configVal
,
expected
)
{
t
.
Fatalf
(
"unknown config value: %#v"
,
p
.
configVal
)
}
...
...
packer/rpc/provisioner_test.go
View file @
8edbcf95
...
...
@@ -23,7 +23,8 @@ func TestProvisionerRPC(t *testing.T) {
if
!
p
.
PrepCalled
{
t
.
Fatal
(
"should be called"
)
}
if
!
reflect
.
DeepEqual
(
p
.
PrepConfigs
,
[]
interface
{}{
42
})
{
expected
:=
[]
interface
{}{
int64
(
42
)}
if
!
reflect
.
DeepEqual
(
p
.
PrepConfigs
,
expected
)
{
t
.
Fatalf
(
"bad: %#v"
,
p
.
PrepConfigs
)
}
...
...
packer/rpc/server.go
View file @
8edbcf95
...
...
@@ -3,6 +3,7 @@ package rpc
import
(
"fmt"
"github.com/mitchellh/packer/packer"
"github.com/ugorji/go/codec"
"io"
"log"
"net/rpc"
...
...
@@ -145,7 +146,9 @@ func (s *Server) Serve() {
return
}
s
.
server
.
ServeConn
(
stream
)
var
h
codec
.
MsgpackHandle
rpcCodec
:=
codec
.
GoRpc
.
ServerCodec
(
stream
,
&
h
)
s
.
server
.
ServeCodec
(
rpcCodec
)
}
// registerComponent registers a single Packer RPC component onto
...
...
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