From 9a3e6661b10d0af6176ac97723360cf35f3d448b Mon Sep 17 00:00:00 2001 From: Paul Meyer Date: Fri, 31 May 2019 18:49:35 +0000 Subject: [PATCH] Add StepMountExtra --- builder/amazon/chroot/builder.go | 4 +++- builder/amazon/chroot/step_mount_extra.go | 8 +++---- builder/azure/chroot/builder.go | 29 +++++++++++++++-------- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/builder/amazon/chroot/builder.go b/builder/amazon/chroot/builder.go index 21eeefc13..0b336c64e 100644 --- a/builder/amazon/chroot/builder.go +++ b/builder/amazon/chroot/builder.go @@ -400,7 +400,9 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack &StepPostMountCommands{ Commands: b.config.PostMountCommands, }, - &StepMountExtra{}, + &StepMountExtra{ + ChrootMounts: b.config.ChrootMounts, + }, &StepCopyFiles{}, &StepChrootProvision{}, &StepEarlyCleanup{}, diff --git a/builder/amazon/chroot/step_mount_extra.go b/builder/amazon/chroot/step_mount_extra.go index 089bf7e75..e1b03abbb 100644 --- a/builder/amazon/chroot/step_mount_extra.go +++ b/builder/amazon/chroot/step_mount_extra.go @@ -17,19 +17,19 @@ import ( // Produces: // mount_extra_cleanup CleanupFunc - To perform early cleanup type StepMountExtra struct { - mounts []string + ChrootMounts [][]string + mounts []string } func (s *StepMountExtra) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction { - config := state.Get("config").(*Config) mountPath := state.Get("mount_path").(string) ui := state.Get("ui").(packer.Ui) 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...") - for _, mountInfo := range config.ChrootMounts { + for _, mountInfo := range s.ChrootMounts { innerPath := mountPath + mountInfo[2] if err := os.MkdirAll(innerPath, 0755); err != nil { diff --git a/builder/azure/chroot/builder.go b/builder/azure/chroot/builder.go index d1ca610c8..24a128ce2 100644 --- a/builder/azure/chroot/builder.go +++ b/builder/azure/chroot/builder.go @@ -23,12 +23,13 @@ type Config struct { FromScratch bool `mapstructure:"from_scratch"` - CommandWrapper string `mapstructure:"command_wrapper"` - MountOptions []string `mapstructure:"mount_options"` - MountPartition string `mapstructure:"mount_partition"` - MountPath string `mapstructure:"mount_path"` - PreMountCommands []string `mapstructure:"pre_mount_commands"` - PostMountCommands []string `mapstructure:"post_mount_commands"` + CommandWrapper string `mapstructure:"command_wrapper"` + PreMountCommands []string `mapstructure:"pre_mount_commands"` + MountOptions []string `mapstructure:"mount_options"` + MountPartition string `mapstructure:"mount_partition"` + MountPath string `mapstructure:"mount_path"` + PostMountCommands []string `mapstructure:"post_mount_commands"` + ChrootMounts [][]string `mapstructure:"chroot_mounts"` OSDiskSizeGB int32 `mapstructure:"osdisk_size_gb"` OSDiskStorageAccountType string `mapstructure:"osdisk_storageaccounttype"` @@ -48,7 +49,12 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { InterpolateContext: &b.config.ctx, InterpolateFilter: &interpolate.RenderFilter{ 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...) @@ -65,11 +71,11 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { if b.config.FromScratch { if b.config.OSDiskSizeGB == 0 { 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 { 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) { 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 @@ -151,6 +157,9 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack &chroot.StepPostMountCommands{ Commands: b.config.PostMountCommands, }, + &chroot.StepMountExtra{ + ChrootMounts: b.config.ChrootMounts, + }, ) // Run!