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
cce59af2
Commit
cce59af2
authored
May 08, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support builders in config, packer/rpc, packer/plugin
parent
32ec0adb
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
96 additions
and
4 deletions
+96
-4
config.go
config.go
+11
-0
packer.go
packer.go
+1
-0
packer/plugin/builder.go
packer/plugin/builder.go
+76
-0
packer/rpc/builder.go
packer/rpc/builder.go
+7
-3
packer/rpc/environment.go
packer/rpc/environment.go
+1
-1
No files found.
config.go
View file @
cce59af2
...
...
@@ -64,6 +64,17 @@ func (c *config) CommandNames() (result []string) {
return
}
func
(
c
*
config
)
LoadBuilder
(
name
string
)
(
packer
.
Builder
,
error
)
{
log
.
Printf
(
"Loading builder: %s
\n
"
,
name
)
bin
,
ok
:=
c
.
Builders
[
name
]
if
!
ok
{
log
.
Printf
(
"Builder not found: %s
\n
"
,
name
)
return
nil
,
nil
}
return
plugin
.
Builder
(
exec
.
Command
(
bin
))
}
// This is a proper packer.CommandFunc that can be used to load packer.Command
// implementations from the defined plugins.
func
(
c
*
config
)
LoadCommand
(
name
string
)
(
packer
.
Command
,
error
)
{
...
...
packer.go
View file @
cce59af2
...
...
@@ -84,6 +84,7 @@ func main() {
}
envConfig
:=
packer
.
DefaultEnvironmentConfig
()
envConfig
.
BuilderFunc
=
config
.
LoadBuilder
envConfig
.
Commands
=
config
.
CommandNames
()
envConfig
.
CommandFunc
=
config
.
LoadCommand
...
...
packer/plugin/builder.go
0 → 100644
View file @
cce59af2
package
plugin
import
(
"github.com/mitchellh/packer/packer"
"log"
"net/rpc"
"os/exec"
packrpc
"github.com/mitchellh/packer/packer/rpc"
)
type
cmdBuilder
struct
{
builder
packer
.
Builder
client
*
client
}
func
(
b
*
cmdBuilder
)
Prepare
(
config
interface
{})
{
defer
func
()
{
r
:=
recover
()
b
.
checkExit
(
r
,
nil
)
}()
b
.
builder
.
Prepare
(
config
)
}
func
(
b
*
cmdBuilder
)
Run
(
build
packer
.
Build
,
ui
packer
.
Ui
)
{
defer
func
()
{
r
:=
recover
()
b
.
checkExit
(
r
,
nil
)
}()
b
.
builder
.
Run
(
build
,
ui
)
}
func
(
c
*
cmdBuilder
)
checkExit
(
p
interface
{},
cb
func
())
{
if
c
.
client
.
Exited
()
&&
cb
!=
nil
{
cb
()
}
else
if
p
!=
nil
{
log
.
Panic
(
p
)
}
}
// Returns a valid packer.Builder where the builder 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
Builder
(
cmd
*
exec
.
Cmd
)
(
result
packer
.
Builder
,
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
=
&
cmdBuilder
{
packrpc
.
Builder
(
client
),
cmdClient
,
}
return
}
packer/rpc/builder.go
View file @
cce59af2
...
...
@@ -7,7 +7,7 @@ import (
// An implementation of packer.Builder where the builder is actually executed
// over an RPC connection.
type
B
uilder
struct
{
type
b
uilder
struct
{
client
*
rpc
.
Client
}
...
...
@@ -25,11 +25,15 @@ type BuilderRunArgs struct {
RPCAddress
string
}
func
(
b
*
Builder
)
Prepare
(
config
interface
{})
{
func
Builder
(
client
*
rpc
.
Client
)
*
builder
{
return
&
builder
{
client
}
}
func
(
b
*
builder
)
Prepare
(
config
interface
{})
{
b
.
client
.
Call
(
"Builder.Prepare"
,
&
BuilderPrepareArgs
{
config
},
new
(
interface
{}))
}
func
(
b
*
B
uilder
)
Run
(
build
packer
.
Build
,
ui
packer
.
Ui
)
{
func
(
b
*
b
uilder
)
Run
(
build
packer
.
Build
,
ui
packer
.
Ui
)
{
// Create and start the server for the Build and UI
// TODO: Error handling
server
:=
rpc
.
NewServer
()
...
...
packer/rpc/environment.go
View file @
cce59af2
...
...
@@ -33,7 +33,7 @@ func (e *Environment) Builder(name string) (b packer.Builder, err error) {
return
}
b
=
&
Builder
{
client
}
b
=
Builder
(
client
)
return
}
...
...
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