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
9b406a90
Commit
9b406a90
authored
Jun 18, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer/plugin: Support PostProcessor
parent
d823d255
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
91 additions
and
3 deletions
+91
-3
packer/plugin/client.go
packer/plugin/client.go
+2
-3
packer/plugin/plugin.go
packer/plugin/plugin.go
+13
-0
packer/plugin/plugin_test.go
packer/plugin/plugin_test.go
+2
-0
packer/plugin/post_processor.go
packer/plugin/post_processor.go
+37
-0
packer/plugin/post_processor_test.go
packer/plugin/post_processor_test.go
+37
-0
No files found.
packer/plugin/client.go
View file @
9b406a90
...
@@ -143,13 +143,12 @@ func (c *Client) Hook() (packer.Hook, error) {
...
@@ -143,13 +143,12 @@ func (c *Client) Hook() (packer.Hook, error) {
// Returns a post-processor implementation that is communicating over
// Returns a post-processor implementation that is communicating over
// this client. If the client hasn't been started, this will start it.
// this client. If the client hasn't been started, this will start it.
func
(
c
*
Client
)
PostProcessor
()
(
packer
.
PostProcessor
,
error
)
{
func
(
c
*
Client
)
PostProcessor
()
(
packer
.
PostProcessor
,
error
)
{
_
,
err
:=
c
.
rpcClient
()
client
,
err
:=
c
.
rpcClient
()
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
// TODO
return
&
cmdPostProcessor
{
packrpc
.
PostProcessor
(
client
),
c
},
nil
return
nil
,
nil
}
}
// Returns a provisioner implementation that is communicating over this
// Returns a provisioner implementation that is communicating over this
...
...
packer/plugin/plugin.go
View file @
9b406a90
...
@@ -137,6 +137,19 @@ func ServeHook(hook packer.Hook) {
...
@@ -137,6 +137,19 @@ func ServeHook(hook packer.Hook) {
}
}
}
}
// Serves a post-processor from a plugin.
func
ServePostProcessor
(
p
packer
.
PostProcessor
)
{
log
.
Println
(
"Preparing to serve a post-processor plugin..."
)
server
:=
rpc
.
NewServer
()
packrpc
.
RegisterPostProcessor
(
server
,
p
)
swallowInterrupts
()
if
err
:=
serve
(
server
);
err
!=
nil
{
log
.
Panic
(
err
)
}
}
// Serves a provisioner from a plugin.
// Serves a provisioner from a plugin.
func
ServeProvisioner
(
p
packer
.
Provisioner
)
{
func
ServeProvisioner
(
p
packer
.
Provisioner
)
{
log
.
Println
(
"Preparing to serve a provisioner plugin..."
)
log
.
Println
(
"Preparing to serve a provisioner plugin..."
)
...
...
packer/plugin/plugin_test.go
View file @
9b406a90
...
@@ -59,6 +59,8 @@ func TestHelperProcess(*testing.T) {
...
@@ -59,6 +59,8 @@ func TestHelperProcess(*testing.T) {
case
"mock"
:
case
"mock"
:
fmt
.
Println
(
":1234"
)
fmt
.
Println
(
":1234"
)
<-
make
(
chan
int
)
<-
make
(
chan
int
)
case
"post-processor"
:
ServePostProcessor
(
new
(
helperPostProcessor
))
case
"provisioner"
:
case
"provisioner"
:
ServeProvisioner
(
new
(
helperProvisioner
))
ServeProvisioner
(
new
(
helperProvisioner
))
case
"start-timeout"
:
case
"start-timeout"
:
...
...
packer/plugin/post_processor.go
0 → 100644
View file @
9b406a90
package
plugin
import
(
"github.com/mitchellh/packer/packer"
"log"
)
type
cmdPostProcessor
struct
{
p
packer
.
PostProcessor
client
*
Client
}
func
(
c
*
cmdPostProcessor
)
Configure
(
config
interface
{})
error
{
defer
func
()
{
r
:=
recover
()
c
.
checkExit
(
r
,
nil
)
}()
return
c
.
p
.
Configure
(
config
)
}
func
(
c
*
cmdPostProcessor
)
PostProcess
(
a
packer
.
Artifact
)
(
packer
.
Artifact
,
error
)
{
defer
func
()
{
r
:=
recover
()
c
.
checkExit
(
r
,
nil
)
}()
return
c
.
p
.
PostProcess
(
a
)
}
func
(
c
*
cmdPostProcessor
)
checkExit
(
p
interface
{},
cb
func
())
{
if
c
.
client
.
Exited
()
{
cb
()
}
else
if
p
!=
nil
{
log
.
Panic
(
p
)
}
}
packer/plugin/post_processor_test.go
0 → 100644
View file @
9b406a90
package
plugin
import
(
"github.com/mitchellh/packer/packer"
"os/exec"
"testing"
)
type
helperPostProcessor
byte
func
(
helperPostProcessor
)
Configure
(
interface
{})
error
{
return
nil
}
func
(
helperPostProcessor
)
PostProcess
(
packer
.
Artifact
)
(
packer
.
Artifact
,
error
)
{
return
nil
,
nil
}
func
TestPostProcessor_NoExist
(
t
*
testing
.
T
)
{
c
:=
NewClient
(
&
ClientConfig
{
Cmd
:
exec
.
Command
(
"i-should-not-exist"
)})
defer
c
.
Kill
()
_
,
err
:=
c
.
PostProcessor
()
if
err
==
nil
{
t
.
Fatal
(
"should have error"
)
}
}
func
TestPostProcessor_Good
(
t
*
testing
.
T
)
{
c
:=
NewClient
(
&
ClientConfig
{
Cmd
:
helperProcess
(
"post-processor"
)})
defer
c
.
Kill
()
_
,
err
:=
c
.
PostProcessor
()
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
}
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