builder/amazon/chroot: use mountcommand configs
This commit is contained in:
parent
1c34e35574
commit
54d020b8c3
|
@ -24,10 +24,13 @@ type Config struct {
|
||||||
common.PackerConfig `mapstructure:",squash"`
|
common.PackerConfig `mapstructure:",squash"`
|
||||||
awscommon.AccessConfig `mapstructure:",squash"`
|
awscommon.AccessConfig `mapstructure:",squash"`
|
||||||
|
|
||||||
SourceAmi string `mapstructure:"source_ami"`
|
AttachedDevicePath string `mapstructure:"attached_device_path"`
|
||||||
AttachedDevicePath string `mapstructure:"attached_device_path"`
|
ChrootMounts []string `mapstructure:"chroot_mounts"`
|
||||||
DevicePath string `mapstructure:"device_path"`
|
DevicePath string `mapstructure:"device_path"`
|
||||||
MountPath string `mapstructure:"mount_path"`
|
MountCommand string `mapstructure:"mount_command"`
|
||||||
|
MountPath string `mapstructure:"mount_path"`
|
||||||
|
SourceAmi string `mapstructure:"source_ami"`
|
||||||
|
UnmountCommand string `mapstructure:"unmount_command"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Builder struct {
|
type Builder struct {
|
||||||
|
@ -42,14 +45,36 @@ func (b *Builder) Prepare(raws ...interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Defaults
|
// Defaults
|
||||||
|
if b.config.ChrootMounts == nil {
|
||||||
|
b.config.ChrootMounts = make([]string, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(b.config.ChrootMounts) == 0 {
|
||||||
|
b.config.ChrootMounts = []string{
|
||||||
|
"{{.MountCommand}} -t proc proc {{.MountPath}}/proc",
|
||||||
|
"{{.MountCommand}} -t sysfs sysfs {{.MountPath}}/sys",
|
||||||
|
"{{.MountCommand}} -t bind /dev {{.MountPath}}/dev",
|
||||||
|
"{{.MountCommand}} -t devpts devpts {{.MountPath}}/dev/pts",
|
||||||
|
"{{.MountCommand}} -t binfmt_misc binfmt_misc {{.MountPath}}/proc/sys/fs/binfmt_misc",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if b.config.DevicePath == "" {
|
if b.config.DevicePath == "" {
|
||||||
b.config.DevicePath = "/dev/sdh"
|
b.config.DevicePath = "/dev/sdh"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if b.config.MountCommand == "" {
|
||||||
|
b.config.MountCommand = "mount"
|
||||||
|
}
|
||||||
|
|
||||||
if b.config.MountPath == "" {
|
if b.config.MountPath == "" {
|
||||||
b.config.MountPath = "/var/packer-amazon-chroot/volumes/{{.Device}}"
|
b.config.MountPath = "/var/packer-amazon-chroot/volumes/{{.Device}}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if b.config.UnmountCommand == "" {
|
||||||
|
b.config.UnmountCommand = "umount"
|
||||||
|
}
|
||||||
|
|
||||||
// Accumulate any errors
|
// Accumulate any errors
|
||||||
errs := common.CheckUnusedConfig(md)
|
errs := common.CheckUnusedConfig(md)
|
||||||
errs = packer.MultiErrorAppend(errs, b.config.AccessConfig.Prepare()...)
|
errs = packer.MultiErrorAppend(errs, b.config.AccessConfig.Prepare()...)
|
||||||
|
|
|
@ -35,7 +35,8 @@ func (s *StepMountDevice) Run(state map[string]interface{}) multistep.StepAction
|
||||||
|
|
||||||
ui.Say("Mounting the root device...")
|
ui.Say("Mounting the root device...")
|
||||||
stderr := new(bytes.Buffer)
|
stderr := new(bytes.Buffer)
|
||||||
cmd := exec.Command("mount", device, mountPath)
|
mountCommand := fmt.Sprintf("%s %s %s", config.MountCommand, device, mountPath)
|
||||||
|
cmd := exec.Command("/bin/sh", "-c", mountCommand)
|
||||||
cmd.Stderr = stderr
|
cmd.Stderr = stderr
|
||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
err := fmt.Errorf(
|
err := fmt.Errorf(
|
||||||
|
@ -53,16 +54,12 @@ func (s *StepMountDevice) Cleanup(state map[string]interface{}) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
config := state["config"].(*Config)
|
||||||
ui := state["ui"].(packer.Ui)
|
ui := state["ui"].(packer.Ui)
|
||||||
ui.Say("Unmounting the root device...")
|
ui.Say("Unmounting the root device...")
|
||||||
|
|
||||||
path, err := exec.LookPath("umount")
|
unmountCommand := fmt.Sprintf("%s %s", config.UnmountCommand, s.mountPath)
|
||||||
if err != nil {
|
cmd := exec.Command("bin/sh", "-c", unmountCommand)
|
||||||
ui.Error(fmt.Sprintf("Error umounting root device: %s", err))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd := exec.Command(path, s.mountPath)
|
|
||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
ui.Error(fmt.Sprintf(
|
ui.Error(fmt.Sprintf(
|
||||||
"Error unmounting root device: %s", err))
|
"Error unmounting root device: %s", err))
|
||||||
|
|
Loading…
Reference in New Issue