Commit 39c3051a authored by Matthew Hooker's avatar Matthew Hooker

building but there's an exec error.

parent d2f9ba0d
...@@ -13,6 +13,7 @@ import ( ...@@ -13,6 +13,7 @@ import (
"github.com/mitchellh/packer/common" "github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
"log" "log"
"os/exec"
"runtime" "runtime"
) )
...@@ -160,12 +161,23 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe ...@@ -160,12 +161,23 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
ec2conn := ec2.New(auth, region) ec2conn := ec2.New(auth, region)
wrappedCommand := func(command string) *exec.Cmd {
wrapped, err := b.config.tpl.Process(b.config.CommandWrapper, &WrappedCommandTemplate{
Command: command,
})
if err != nil {
ui.Error(err.Error())
}
return ShellCommand(wrapped)
}
// Setup the state bag and initial state for the steps // Setup the state bag and initial state for the steps
state := new(multistep.BasicStateBag) state := new(multistep.BasicStateBag)
state.Put("config", &b.config) state.Put("config", &b.config)
state.Put("ec2", ec2conn) state.Put("ec2", ec2conn)
state.Put("hook", hook) state.Put("hook", hook)
state.Put("ui", ui) state.Put("ui", ui)
state.Put("wrappedCommand", Command(wrappedCommand))
// Build the steps // Build the steps
steps := []multistep.Step{ steps := []multistep.Step{
......
...@@ -21,7 +21,7 @@ type Command func(string) *exec.Cmd ...@@ -21,7 +21,7 @@ type Command func(string) *exec.Cmd
type Communicator struct { type Communicator struct {
Chroot string Chroot string
ChrootCmd Command ChrootCmd Command
wrappedCommand Command WrappedCommand Command
} }
func (c *Communicator) Start(cmd *packer.RemoteCmd) error { func (c *Communicator) Start(cmd *packer.RemoteCmd) error {
......
...@@ -13,6 +13,6 @@ func ChrootCommand(chroot string, command string) *exec.Cmd { ...@@ -13,6 +13,6 @@ func ChrootCommand(chroot string, command string) *exec.Cmd {
func ShellCommand(command string) *exec.Cmd { func ShellCommand(command string) *exec.Cmd {
cmd := exec.Command("/bin/sh", "-c", command) cmd := exec.Command("/bin/sh", "-c", command)
log.Printf("WrappedCommand(%s) -> #%v", command, cmd.Args) log.Printf("ShellCommand(%s) -> #%v", command, cmd.Args)
return cmd return cmd
} }
package chroot package chroot
import ( import (
"fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"testing" "testing"
......
...@@ -4,7 +4,6 @@ import ( ...@@ -4,7 +4,6 @@ import (
"github.com/mitchellh/multistep" "github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
"log" "log"
"os/exec"
) )
// StepChrootProvision provisions the instance within a chroot. // StepChrootProvision provisions the instance within a chroot.
...@@ -19,29 +18,15 @@ type WrappedCommandTemplate struct { ...@@ -19,29 +18,15 @@ type WrappedCommandTemplate struct {
func (s *StepChrootProvision) Run(state multistep.StateBag) multistep.StepAction { func (s *StepChrootProvision) Run(state multistep.StateBag) multistep.StepAction {
hook := state.Get("hook").(packer.Hook) hook := state.Get("hook").(packer.Hook)
mountPath := state.Get("mount_path").(string) mountPath := state.Get("mount_path").(string)
config := state.Get("config").(*Config)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
chrootCmd := func(command string) *exec.Cmd { wrappedCommand := state.Get("wrappedCommand").(Command)
return ChrootCommand(mountPath, command) chrootCmd := state.Get("chrootCmd").(Command)
}
wrappedCommand := func(command string) *exec.Cmd {
wrapped, err := config.tpl.Process(config.CommandWrapper, &WrappedCommandTemplate{
Command: command,
})
if err != nil {
ui.Error(err.Error())
}
return ShellCommand(wrapped)
}
state.Put("chrootCmd", chrootCmd)
state.Put("wrappedCommand", wrappedCommand)
// Create our communicator // Create our communicator
comm := &Communicator{ comm := &Communicator{
Chroot: mountPath, Chroot: mountPath,
ChrootCmd: chrootCmd, ChrootCmd: chrootCmd,
wrappedCommand: wrappedCommand, WrappedCommand: wrappedCommand,
} }
// Provision // Provision
......
...@@ -7,6 +7,7 @@ import ( ...@@ -7,6 +7,7 @@ import (
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
"log" "log"
"os" "os"
"os/exec"
"path/filepath" "path/filepath"
) )
...@@ -56,10 +57,15 @@ func (s *StepMountDevice) Run(state multistep.StateBag) multistep.StepAction { ...@@ -56,10 +57,15 @@ func (s *StepMountDevice) Run(state multistep.StateBag) multistep.StepAction {
return multistep.ActionHalt return multistep.ActionHalt
} }
chrootCmd := func(command string) *exec.Cmd {
return ChrootCommand(mountPath, command)
}
state.Put("chrootCmd", Command(chrootCmd))
ui.Say("Mounting the root device...") ui.Say("Mounting the root device...")
stderr := new(bytes.Buffer) stderr := new(bytes.Buffer)
mountCommand := fmt.Sprintf("mount %s %s", device, mountPath) mountCommand := fmt.Sprintf("mount %s %s", device, mountPath)
wrappedCommand := state.Get("wrappedCommand").(*Command) wrappedCommand := state.Get("wrappedCommand").(Command)
cmd := wrappedCommand(mountCommand) cmd := wrappedCommand(mountCommand)
cmd.Stderr = stderr cmd.Stderr = stderr
if err := cmd.Run(); err != nil { if err := cmd.Run(); err != nil {
......
...@@ -83,7 +83,7 @@ func (s *StepMountExtra) CleanupFunc(state multistep.StateBag) error { ...@@ -83,7 +83,7 @@ func (s *StepMountExtra) CleanupFunc(state multistep.StateBag) error {
var path string var path string
lastIndex := len(s.mounts) - 1 lastIndex := len(s.mounts) - 1
path, s.mounts = s.mounts[lastIndex], s.mounts[:lastIndex] path, s.mounts = s.mounts[lastIndex], s.mounts[:lastIndex]
unmountCommand := fmt.Sprintf("unmount %s", path) unmountCommand := fmt.Sprintf("umount %s", path)
stderr := new(bytes.Buffer) stderr := new(bytes.Buffer)
cmd := wrappedCommand(unmountCommand) cmd := wrappedCommand(unmountCommand)
......
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