building but there's an exec error.

This commit is contained in:
Matthew Hooker 2013-09-27 20:47:44 +00:00
parent 40e15c84ef
commit 8857358830
7 changed files with 26 additions and 22 deletions

View File

@ -13,6 +13,7 @@ import (
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/packer"
"log"
"os/exec"
"runtime"
)
@ -160,12 +161,23 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
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
state := new(multistep.BasicStateBag)
state.Put("config", &b.config)
state.Put("ec2", ec2conn)
state.Put("hook", hook)
state.Put("ui", ui)
state.Put("wrappedCommand", Command(wrappedCommand))
// Build the steps
steps := []multistep.Step{

View File

@ -21,7 +21,7 @@ type Command func(string) *exec.Cmd
type Communicator struct {
Chroot string
ChrootCmd Command
wrappedCommand Command
WrappedCommand Command
}
func (c *Communicator) Start(cmd *packer.RemoteCmd) error {

View File

@ -13,6 +13,6 @@ func ChrootCommand(chroot string, command string) *exec.Cmd {
func ShellCommand(command string) *exec.Cmd {
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
}

View File

@ -1,6 +1,7 @@
package chroot
import (
"fmt"
"io/ioutil"
"os"
"testing"

View File

@ -4,7 +4,6 @@ import (
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"log"
"os/exec"
)
// StepChrootProvision provisions the instance within a chroot.
@ -19,29 +18,15 @@ type WrappedCommandTemplate struct {
func (s *StepChrootProvision) Run(state multistep.StateBag) multistep.StepAction {
hook := state.Get("hook").(packer.Hook)
mountPath := state.Get("mount_path").(string)
config := state.Get("config").(*Config)
ui := state.Get("ui").(packer.Ui)
chrootCmd := func(command string) *exec.Cmd {
return ChrootCommand(mountPath, 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)
wrappedCommand := state.Get("wrappedCommand").(Command)
chrootCmd := state.Get("chrootCmd").(Command)
// Create our communicator
comm := &Communicator{
Chroot: mountPath,
ChrootCmd: chrootCmd,
wrappedCommand: wrappedCommand,
WrappedCommand: wrappedCommand,
}
// Provision

View File

@ -7,6 +7,7 @@ import (
"github.com/mitchellh/packer/packer"
"log"
"os"
"os/exec"
"path/filepath"
)
@ -56,10 +57,15 @@ func (s *StepMountDevice) Run(state multistep.StateBag) multistep.StepAction {
return multistep.ActionHalt
}
chrootCmd := func(command string) *exec.Cmd {
return ChrootCommand(mountPath, command)
}
state.Put("chrootCmd", Command(chrootCmd))
ui.Say("Mounting the root device...")
stderr := new(bytes.Buffer)
mountCommand := fmt.Sprintf("mount %s %s", device, mountPath)
wrappedCommand := state.Get("wrappedCommand").(*Command)
wrappedCommand := state.Get("wrappedCommand").(Command)
cmd := wrappedCommand(mountCommand)
cmd.Stderr = stderr
if err := cmd.Run(); err != nil {

View File

@ -83,7 +83,7 @@ func (s *StepMountExtra) CleanupFunc(state multistep.StateBag) error {
var path string
lastIndex := len(s.mounts) - 1
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)
cmd := wrappedCommand(unmountCommand)