packer-cn/builder/hyperone/step_mount_extra.go

46 lines
1.1 KiB
Go
Raw Normal View History

2019-01-28 06:30:15 -05:00
package hyperone
import (
"context"
"fmt"
2020-11-17 19:31:03 -05:00
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
2019-01-28 06:30:15 -05:00
)
type stepMountExtra struct{}
func (s *stepMountExtra) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
2019-01-28 06:30:15 -05:00
config := state.Get("config").(*Config)
mountPath := state.Get("mount_path").(string)
ui := state.Get("ui").(packersdk.Ui)
2019-01-28 06:30:15 -05:00
ui.Say("Mounting additional paths within the chroot...")
for _, mountInfo := range config.ChrootMounts {
innerPath := mountPath + mountInfo[2]
flags := "-t " + mountInfo[0]
if mountInfo[0] == "bind" {
flags = "--bind"
}
ui.Message(fmt.Sprintf("Mounting: %s", mountInfo[2]))
commands := []string{
fmt.Sprintf("mkdir -m 755 -p %s", innerPath),
fmt.Sprintf("mount %s %s %s", flags, mountInfo[1], innerPath),
}
err := runCommands(commands, config.ctx, state)
if err != nil {
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
}
return multistep.ActionContinue
}
func (s *stepMountExtra) Cleanup(state multistep.StateBag) {}