Allow user to override chroot command.
This commit is contained in:
parent
692278965f
commit
1befba24ed
|
@ -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,
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue