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
37372bac
Commit
37372bac
authored
May 23, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer/plugin: Support provisioners
parent
1b78fc88
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
117 additions
and
0 deletions
+117
-0
packer/plugin/plugin.go
packer/plugin/plugin.go
+12
-0
packer/plugin/plugin_test.go
packer/plugin/plugin_test.go
+2
-0
packer/plugin/provisioner.go
packer/plugin/provisioner.go
+75
-0
packer/plugin/provisioner_test.go
packer/plugin/provisioner_test.go
+28
-0
No files found.
packer/plugin/plugin.go
View file @
37372bac
...
...
@@ -110,3 +110,15 @@ func ServeHook(hook packer.Hook) {
log
.
Panic
(
err
)
}
}
// Serves a provisioner from a plugin.
func
ServeProvisioner
(
p
packer
.
Provisioner
)
{
log
.
Println
(
"Preparing to serve a provisioner plugin..."
)
server
:=
rpc
.
NewServer
()
packrpc
.
RegisterProvisioner
(
server
,
p
)
if
err
:=
serve
(
server
);
err
!=
nil
{
log
.
Panic
(
err
)
}
}
packer/plugin/plugin_test.go
View file @
37372bac
...
...
@@ -56,6 +56,8 @@ func TestHelperProcess(*testing.T) {
ServeHook
(
new
(
helperHook
))
case
"invalid-rpc-address"
:
fmt
.
Println
(
"lolinvalid"
)
case
"provisioner"
:
ServeProvisioner
(
new
(
helperProvisioner
))
case
"start-timeout"
:
time
.
Sleep
(
1
*
time
.
Minute
)
os
.
Exit
(
1
)
...
...
packer/plugin/provisioner.go
0 → 100644
View file @
37372bac
package
plugin
import
(
"github.com/mitchellh/packer/packer"
packrpc
"github.com/mitchellh/packer/packer/rpc"
"log"
"net/rpc"
"os/exec"
)
type
cmdProvisioner
struct
{
p
packer
.
Provisioner
client
*
client
}
func
(
c
*
cmdProvisioner
)
Prepare
(
config
interface
{},
ui
packer
.
Ui
)
{
defer
func
()
{
r
:=
recover
()
c
.
checkExit
(
r
,
nil
)
}()
c
.
p
.
Prepare
(
config
,
ui
)
}
func
(
c
*
cmdProvisioner
)
Provision
(
ui
packer
.
Ui
,
comm
packer
.
Communicator
)
{
defer
func
()
{
r
:=
recover
()
c
.
checkExit
(
r
,
nil
)
}()
c
.
p
.
Provision
(
ui
,
comm
)
}
func
(
c
*
cmdProvisioner
)
checkExit
(
p
interface
{},
cb
func
())
{
if
c
.
client
.
Exited
()
{
cb
()
}
else
if
p
!=
nil
{
log
.
Panic
(
p
)
}
}
// Returns a valid packer.Provisioner where the hook is executed via RPC
// to a plugin that is within a subprocess.
//
// This method will start the given exec.Cmd, which should point to
// the plugin binary to execute. Some configuration will be done to
// the command, such as overriding Stdout and some environmental variables.
//
// This function guarantees the subprocess will end in a timely manner.
func
Provisioner
(
cmd
*
exec
.
Cmd
)
(
result
packer
.
Provisioner
,
err
error
)
{
cmdClient
:=
NewManagedClient
(
cmd
)
address
,
err
:=
cmdClient
.
Start
()
if
err
!=
nil
{
return
}
defer
func
()
{
// Make sure the command is properly killed in the case of an error
if
err
!=
nil
{
cmdClient
.
Kill
()
}
}()
client
,
err
:=
rpc
.
Dial
(
"tcp"
,
address
)
if
err
!=
nil
{
return
}
result
=
&
cmdProvisioner
{
packrpc
.
Provisioner
(
client
),
cmdClient
,
}
return
}
packer/plugin/provisioner_test.go
0 → 100644
View file @
37372bac
package
plugin
import
(
"cgl.tideland.biz/asserts"
"github.com/mitchellh/packer/packer"
"os/exec"
"testing"
)
type
helperProvisioner
byte
func
(
helperProvisioner
)
Prepare
(
interface
{},
packer
.
Ui
)
{}
func
(
helperProvisioner
)
Provision
(
packer
.
Ui
,
packer
.
Communicator
)
{}
func
TestProvisioner_NoExist
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
_
,
err
:=
Provisioner
(
exec
.
Command
(
"i-should-never-ever-ever-exist"
))
assert
.
NotNil
(
err
,
"should have an error"
)
}
func
TestProvisioner_Good
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
_
,
err
:=
Provisioner
(
helperProcess
(
"provisioner"
))
assert
.
Nil
(
err
,
"should start provisioner properly"
)
}
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