Commit a2bf964f authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer/rpc: Properly support hooks

parent cb1e0cba
...@@ -60,6 +60,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook) { ...@@ -60,6 +60,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook) {
MaxCount: 0, MaxCount: 0,
} }
hook.Run(HookPreLaunch, nil, ui)
return
ui.Say("Launching a source AWS instance...\n") ui.Say("Launching a source AWS instance...\n")
runResp, err := ec2conn.RunInstances(runOpts) runResp, err := ec2conn.RunInstances(runOpts)
if err != nil { if err != nil {
......
package amazonebs
// This hook is fired prior to launching the EC2 instance.
const HookPreLaunch = "amazonebs_pre_launch"
...@@ -90,3 +90,8 @@ func (c *config) LoadCommand(name string) (packer.Command, error) { ...@@ -90,3 +90,8 @@ func (c *config) LoadCommand(name string) (packer.Command, error) {
return plugin.Command(exec.Command(commandBin)) return plugin.Command(exec.Command(commandBin))
} }
func (c *config) LoadHook(name string) (packer.Hook, error) {
log.Printf("Loading hook: %s\n", name)
return plugin.Hook(exec.Command(name))
}
...@@ -87,6 +87,7 @@ func main() { ...@@ -87,6 +87,7 @@ func main() {
envConfig.Commands = config.CommandNames() envConfig.Commands = config.CommandNames()
envConfig.Components.Builder = config.LoadBuilder envConfig.Components.Builder = config.LoadBuilder
envConfig.Components.Command = config.LoadCommand envConfig.Components.Command = config.LoadCommand
envConfig.Components.Hook = config.LoadHook
env, err := packer.NewEnvironment(envConfig) env, err := packer.NewEnvironment(envConfig)
if err != nil { if err != nil {
......
...@@ -50,13 +50,12 @@ func (e *Environment) Hook(name string) (h packer.Hook, err error) { ...@@ -50,13 +50,12 @@ func (e *Environment) Hook(name string) (h packer.Hook, err error) {
return return
} }
_, err = rpc.Dial("tcp", reply) client, err := rpc.Dial("tcp", reply)
if err != nil { if err != nil {
return return
} }
// TODO: Hook h = Hook(client)
h = nil
return return
} }
...@@ -89,14 +88,14 @@ func (e *EnvironmentServer) Cli(args *EnvironmentCliArgs, reply *int) (err error ...@@ -89,14 +88,14 @@ func (e *EnvironmentServer) Cli(args *EnvironmentCliArgs, reply *int) (err error
} }
func (e *EnvironmentServer) Hook(name *string, reply *string) error { func (e *EnvironmentServer) Hook(name *string, reply *string) error {
_, err := e.env.Hook(*name) hook, err := e.env.Hook(*name)
if err != nil { if err != nil {
return err return err
} }
// Wrap it // Wrap it
// TODO: Register hook
server := rpc.NewServer() server := rpc.NewServer()
RegisterHook(server, hook)
*reply = serveSingleConn(server) *reply = serveSingleConn(server)
return nil return nil
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment