move wrapper definitions around.

This commit is contained in:
Matthew Hooker 2013-09-27 22:08:15 +00:00
parent 39c3051a95
commit 831d5caa50
5 changed files with 12 additions and 15 deletions

View File

@ -37,6 +37,10 @@ type Config struct {
tpl *packer.ConfigTemplate
}
type wrappedCommandTemplate struct {
Command string
}
type Builder struct {
config Config
runner multistep.Runner
@ -162,7 +166,7 @@ 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{
wrapped, err := b.config.tpl.Process(b.config.CommandWrapper, &wrappedCommandTemplate{
Command: command,
})
if err != nil {

View File

@ -66,7 +66,7 @@ func (c *Communicator) Upload(dst string, r io.Reader) error {
}
defer os.Remove(tf.Name())
io.Copy(tf, r)
cpCmd := fmt.Sprintf("cp %s %s", dst, tf.Name())
cpCmd := fmt.Sprintf("cp %s %s", tf.Name(), dst)
return (*c.ChrootCmd(cpCmd)).Run()
}
@ -90,7 +90,7 @@ func (c *Communicator) UploadDir(dst string, src string, exclude []string) error
chrootDest := filepath.Join(c.Chroot, dst, path)
log.Printf("Uploading to chroot dir: %s", dst)
cpCmd := fmt.Sprintf("cp %s %s", chrootDest, fullPath)
cpCmd := fmt.Sprintf("cp %s %s", fullPath, chrootDest)
return c.ChrootCmd(cpCmd).Run()
}

View File

@ -4,6 +4,7 @@ import (
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"log"
"os/exec"
)
// StepChrootProvision provisions the instance within a chroot.
@ -11,16 +12,14 @@ type StepChrootProvision struct {
mounts []string
}
type WrappedCommandTemplate struct {
Command string
}
func (s *StepChrootProvision) Run(state multistep.StateBag) multistep.StepAction {
hook := state.Get("hook").(packer.Hook)
mountPath := state.Get("mount_path").(string)
ui := state.Get("ui").(packer.Ui)
wrappedCommand := state.Get("wrappedCommand").(Command)
chrootCmd := state.Get("chrootCmd").(Command)
chrootCmd := func(command string) *exec.Cmd {
return ChrootCommand(mountPath, command)
}
// Create our communicator
comm := &Communicator{

View File

@ -31,7 +31,7 @@ func (s *StepCopyFiles) Run(state multistep.StateBag) multistep.StepAction {
chrootPath := filepath.Join(mountPath, path)
log.Printf("Copying '%s' to '%s'", path, chrootPath)
cmd := fmt.Sprintf("cp %s %s", chrootPath, path)
cmd := fmt.Sprintf("cp %s %s", path, chrootPath)
if err := wrappedCommand(cmd); err != nil {
err := fmt.Errorf("Error copying file: %s", err)
state.Put("error", err)

View File

@ -7,7 +7,6 @@ import (
"github.com/mitchellh/packer/packer"
"log"
"os"
"os/exec"
"path/filepath"
)
@ -57,11 +56,6 @@ 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)