Allow user to override chroot command.

This commit is contained in:
Matthew Hooker 2013-09-17 05:58:16 -07:00
parent 692278965f
commit 1befba24ed
3 changed files with 10 additions and 5 deletions

View File

@ -30,6 +30,7 @@ type Config struct {
CopyFiles []string `mapstructure:"copy_files"`
DevicePath string `mapstructure:"device_path"`
MountCommand string `mapstructure:"mount_command"`
ChrootCommand string `mapstructure:"chroot_command"`
MountPath string `mapstructure:"mount_path"`
SourceAmi string `mapstructure:"source_ami"`
UnmountCommand string `mapstructure:"unmount_command"`
@ -82,6 +83,10 @@ func (b *Builder) Prepare(raws ...interface{}) error {
b.config.MountCommand = "mount"
}
if b.config.ChrootCommand == "" {
b.config.ChrootCommand = "chroot"
}
if b.config.MountPath == "" {
b.config.MountPath = "packer-amazon-chroot-volumes/{{.Device}}"
}
@ -129,6 +134,7 @@ func (b *Builder) Prepare(raws ...interface{}) error {
templates := map[string]*string{
"device_path": &b.config.DevicePath,
"mount_command": &b.config.MountCommand,
"chroot_command": &b.config.ChrootCommand,
"source_ami": &b.config.SourceAmi,
"unmount_command": &b.config.UnmountCommand,
}

View File

@ -14,15 +14,12 @@ import (
// commands locally but within a chroot.
type Communicator struct {
Chroot string
ChrootCommand string
}
func (c *Communicator) Start(cmd *packer.RemoteCmd) error {
chrootCmdPath, err := exec.LookPath("chroot")
if err != nil {
return err
}
localCmd := exec.Command(chrootCmdPath, c.Chroot, "/bin/sh", "-c", cmd.Command)
localCmd := exec.Command(c.ChrootCommand, c.Chroot, "/bin/sh", "-c", cmd.Command)
localCmd.Stdin = cmd.Stdin
localCmd.Stdout = cmd.Stdout
localCmd.Stderr = cmd.Stderr

View File

@ -14,11 +14,13 @@ type StepChrootProvision struct {
func (s *StepChrootProvision) Run(state multistep.StateBag) multistep.StepAction {
hook := state.Get("hook").(packer.Hook)
mountPath := state.Get("mount_path").(string)
chrootCommand := state.Get("chroot_command").(string)
ui := state.Get("ui").(packer.Ui)
// Create our communicator
comm := &Communicator{
Chroot: mountPath,
ChrootCommand: chrootCommand,
}
// Provision