Add StepMountExtra

This commit is contained in:
Paul Meyer 2019-05-31 18:49:35 +00:00
parent addbdedea9
commit 9a3e6661b1
3 changed files with 26 additions and 15 deletions

View File

@ -400,7 +400,9 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
&StepPostMountCommands{ &StepPostMountCommands{
Commands: b.config.PostMountCommands, Commands: b.config.PostMountCommands,
}, },
&StepMountExtra{}, &StepMountExtra{
ChrootMounts: b.config.ChrootMounts,
},
&StepCopyFiles{}, &StepCopyFiles{},
&StepChrootProvision{}, &StepChrootProvision{},
&StepEarlyCleanup{}, &StepEarlyCleanup{},

View File

@ -17,19 +17,19 @@ import (
// Produces: // Produces:
// mount_extra_cleanup CleanupFunc - To perform early cleanup // mount_extra_cleanup CleanupFunc - To perform early cleanup
type StepMountExtra struct { type StepMountExtra struct {
mounts []string ChrootMounts [][]string
mounts []string
} }
func (s *StepMountExtra) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction { func (s *StepMountExtra) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
config := state.Get("config").(*Config)
mountPath := state.Get("mount_path").(string) mountPath := state.Get("mount_path").(string)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
wrappedCommand := state.Get("wrappedCommand").(CommandWrapper) wrappedCommand := state.Get("wrappedCommand").(CommandWrapper)
s.mounts = make([]string, 0, len(config.ChrootMounts)) s.mounts = make([]string, 0, len(s.ChrootMounts))
ui.Say("Mounting additional paths within the chroot...") ui.Say("Mounting additional paths within the chroot...")
for _, mountInfo := range config.ChrootMounts { for _, mountInfo := range s.ChrootMounts {
innerPath := mountPath + mountInfo[2] innerPath := mountPath + mountInfo[2]
if err := os.MkdirAll(innerPath, 0755); err != nil { if err := os.MkdirAll(innerPath, 0755); err != nil {

View File

@ -23,12 +23,13 @@ type Config struct {
FromScratch bool `mapstructure:"from_scratch"` FromScratch bool `mapstructure:"from_scratch"`
CommandWrapper string `mapstructure:"command_wrapper"` CommandWrapper string `mapstructure:"command_wrapper"`
MountOptions []string `mapstructure:"mount_options"` PreMountCommands []string `mapstructure:"pre_mount_commands"`
MountPartition string `mapstructure:"mount_partition"` MountOptions []string `mapstructure:"mount_options"`
MountPath string `mapstructure:"mount_path"` MountPartition string `mapstructure:"mount_partition"`
PreMountCommands []string `mapstructure:"pre_mount_commands"` MountPath string `mapstructure:"mount_path"`
PostMountCommands []string `mapstructure:"post_mount_commands"` PostMountCommands []string `mapstructure:"post_mount_commands"`
ChrootMounts [][]string `mapstructure:"chroot_mounts"`
OSDiskSizeGB int32 `mapstructure:"osdisk_size_gb"` OSDiskSizeGB int32 `mapstructure:"osdisk_size_gb"`
OSDiskStorageAccountType string `mapstructure:"osdisk_storageaccounttype"` OSDiskStorageAccountType string `mapstructure:"osdisk_storageaccounttype"`
@ -48,7 +49,12 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
InterpolateContext: &b.config.ctx, InterpolateContext: &b.config.ctx,
InterpolateFilter: &interpolate.RenderFilter{ InterpolateFilter: &interpolate.RenderFilter{
Exclude: []string{ Exclude: []string{
// fields to exclude from interpolation // these fields are interpolated in the steps,
// when more information is available
"command_wrapper",
"post_mount_commands",
"pre_mount_commands",
"mount_path",
}, },
}, },
}, raws...) }, raws...)
@ -65,11 +71,11 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
if b.config.FromScratch { if b.config.FromScratch {
if b.config.OSDiskSizeGB == 0 { if b.config.OSDiskSizeGB == 0 {
errs = packer.MultiErrorAppend( errs = packer.MultiErrorAppend(
errs, errors.New("osdisk_size_gb is required with from_scratch.")) errs, errors.New("osdisk_size_gb is required with from_scratch"))
} }
if len(b.config.PreMountCommands) == 0 { if len(b.config.PreMountCommands) == 0 {
errs = packer.MultiErrorAppend( errs = packer.MultiErrorAppend(
errs, errors.New("pre_mount_commands is required with from_scratch.")) errs, errors.New("pre_mount_commands is required with from_scratch"))
} }
} }
@ -81,7 +87,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) { func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
if runtime.GOOS != "linux" { if runtime.GOOS != "linux" {
return nil, errors.New("The azure-chroot builder only works on Linux environments.") return nil, errors.New("the azure-chroot builder only works on Linux environments")
} }
var azcli client.AzureClientSet var azcli client.AzureClientSet
@ -151,6 +157,9 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
&chroot.StepPostMountCommands{ &chroot.StepPostMountCommands{
Commands: b.config.PostMountCommands, Commands: b.config.PostMountCommands,
}, },
&chroot.StepMountExtra{
ChrootMounts: b.config.ChrootMounts,
},
) )
// Run! // Run!