diff --git a/builder/amazon/chroot/builder.go b/builder/amazon/chroot/builder.go index a7f46a5f4..642f4925d 100644 --- a/builder/amazon/chroot/builder.go +++ b/builder/amazon/chroot/builder.go @@ -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 { diff --git a/builder/amazon/chroot/communicator.go b/builder/amazon/chroot/communicator.go index 7f52d9fdb..92ed0d25a 100644 --- a/builder/amazon/chroot/communicator.go +++ b/builder/amazon/chroot/communicator.go @@ -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() } diff --git a/builder/amazon/chroot/step_chroot_provision.go b/builder/amazon/chroot/step_chroot_provision.go index 481f58671..f4612c807 100644 --- a/builder/amazon/chroot/step_chroot_provision.go +++ b/builder/amazon/chroot/step_chroot_provision.go @@ -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{ diff --git a/builder/amazon/chroot/step_copy_files.go b/builder/amazon/chroot/step_copy_files.go index e22301369..c7be3bb66 100644 --- a/builder/amazon/chroot/step_copy_files.go +++ b/builder/amazon/chroot/step_copy_files.go @@ -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) diff --git a/builder/amazon/chroot/step_mount_device.go b/builder/amazon/chroot/step_mount_device.go index e8a987d1d..f9a823623 100644 --- a/builder/amazon/chroot/step_mount_device.go +++ b/builder/amazon/chroot/step_mount_device.go @@ -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)