From e6dfe301acac599dadbe26bcad14c73cbcdabae2 Mon Sep 17 00:00:00 2001 From: Paul Meyer Date: Thu, 24 Oct 2019 03:57:17 +0000 Subject: [PATCH 1/2] Move CommandWrapper & ShellCommand to common --- builder/amazon/chroot/builder.go | 2 +- builder/amazon/chroot/communicator.go | 9 +++++---- builder/amazon/chroot/copy_files_test.go | 4 +++- builder/amazon/chroot/run_local_commands.go | 3 ++- builder/amazon/chroot/step_chroot_provision.go | 3 ++- builder/amazon/chroot/step_copy_files.go | 9 +++++---- builder/amazon/chroot/step_mount_device.go | 9 +++++---- builder/amazon/chroot/step_mount_extra.go | 11 ++++++----- .../amazon/chroot/step_post_mount_commands.go | 3 ++- .../amazon/chroot/step_pre_mount_commands.go | 3 ++- builder/azure/chroot/builder.go | 2 +- builder/azure/chroot/step_mount_device.go | 17 +++++++++-------- {builder/amazon/chroot => common}/command.go | 2 +- 13 files changed, 44 insertions(+), 33 deletions(-) rename {builder/amazon/chroot => common}/command.go (96%) diff --git a/builder/amazon/chroot/builder.go b/builder/amazon/chroot/builder.go index d1d3f37e4..ce5fa9d73 100644 --- a/builder/amazon/chroot/builder.go +++ b/builder/amazon/chroot/builder.go @@ -356,7 +356,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack state.Put("awsSession", session) state.Put("hook", hook) state.Put("ui", ui) - state.Put("wrappedCommand", CommandWrapper(wrappedCommand)) + state.Put("wrappedCommand", common.CommandWrapper(wrappedCommand)) // Build the steps steps := []multistep.Step{ diff --git a/builder/amazon/chroot/communicator.go b/builder/amazon/chroot/communicator.go index 400c12b53..a813baca8 100644 --- a/builder/amazon/chroot/communicator.go +++ b/builder/amazon/chroot/communicator.go @@ -13,6 +13,7 @@ import ( "strings" "syscall" + "github.com/hashicorp/packer/common" "github.com/hashicorp/packer/packer" "github.com/hashicorp/packer/packer/tmp" ) @@ -21,7 +22,7 @@ import ( // commands locally but within a chroot. type Communicator struct { Chroot string - CmdWrapper CommandWrapper + CmdWrapper common.CommandWrapper } func (c *Communicator) Start(ctx context.Context, cmd *packer.RemoteCmd) error { @@ -33,7 +34,7 @@ func (c *Communicator) Start(ctx context.Context, cmd *packer.RemoteCmd) error { return err } - localCmd := ShellCommand(command) + localCmd := common.ShellCommand(command) localCmd.Stdin = cmd.Stdin localCmd.Stdout = cmd.Stdout localCmd.Stderr = cmd.Stderr @@ -83,7 +84,7 @@ func (c *Communicator) Upload(dst string, r io.Reader, fi *os.FileInfo) error { return err } - return ShellCommand(cpCmd).Run() + return common.ShellCommand(cpCmd).Run() } func (c *Communicator) UploadDir(dst string, src string, exclude []string) error { @@ -105,7 +106,7 @@ func (c *Communicator) UploadDir(dst string, src string, exclude []string) error } var stderr bytes.Buffer - cmd := ShellCommand(cpCmd) + cmd := common.ShellCommand(cpCmd) cmd.Env = append(cmd.Env, "LANG=C") cmd.Env = append(cmd.Env, os.Environ()...) cmd.Stderr = &stderr diff --git a/builder/amazon/chroot/copy_files_test.go b/builder/amazon/chroot/copy_files_test.go index d84ee080f..409bbfb9b 100644 --- a/builder/amazon/chroot/copy_files_test.go +++ b/builder/amazon/chroot/copy_files_test.go @@ -6,6 +6,8 @@ import ( "os" "runtime" "testing" + + "github.com/hashicorp/packer/common" ) func TestCopyFile(t *testing.T) { @@ -26,7 +28,7 @@ func TestCopyFile(t *testing.T) { } first.Sync() - cmd := ShellCommand(fmt.Sprintf("cp %s %s", first.Name(), newName)) + cmd := common.ShellCommand(fmt.Sprintf("cp %s %s", first.Name(), newName)) if err := cmd.Run(); err != nil { t.Fatalf("Couldn't copy file") } diff --git a/builder/amazon/chroot/run_local_commands.go b/builder/amazon/chroot/run_local_commands.go index 9a93f8791..8141d09e5 100644 --- a/builder/amazon/chroot/run_local_commands.go +++ b/builder/amazon/chroot/run_local_commands.go @@ -4,12 +4,13 @@ import ( "context" "fmt" + "github.com/hashicorp/packer/common" sl "github.com/hashicorp/packer/common/shell-local" "github.com/hashicorp/packer/packer" "github.com/hashicorp/packer/template/interpolate" ) -func RunLocalCommands(commands []string, wrappedCommand CommandWrapper, ictx interpolate.Context, ui packer.Ui) error { +func RunLocalCommands(commands []string, wrappedCommand common.CommandWrapper, ictx interpolate.Context, ui packer.Ui) error { ctx := context.TODO() for _, rawCmd := range commands { intCmd, err := interpolate.Render(rawCmd, &ictx) diff --git a/builder/amazon/chroot/step_chroot_provision.go b/builder/amazon/chroot/step_chroot_provision.go index 4545105b0..a90c79767 100644 --- a/builder/amazon/chroot/step_chroot_provision.go +++ b/builder/amazon/chroot/step_chroot_provision.go @@ -4,6 +4,7 @@ import ( "context" "log" + "github.com/hashicorp/packer/common" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" ) @@ -16,7 +17,7 @@ func (s *StepChrootProvision) Run(ctx context.Context, state multistep.StateBag) hook := state.Get("hook").(packer.Hook) mountPath := state.Get("mount_path").(string) ui := state.Get("ui").(packer.Ui) - wrappedCommand := state.Get("wrappedCommand").(CommandWrapper) + wrappedCommand := state.Get("wrappedCommand").(common.CommandWrapper) // Create our communicator comm := &Communicator{ diff --git a/builder/amazon/chroot/step_copy_files.go b/builder/amazon/chroot/step_copy_files.go index af5766386..496578bfc 100644 --- a/builder/amazon/chroot/step_copy_files.go +++ b/builder/amazon/chroot/step_copy_files.go @@ -7,6 +7,7 @@ import ( "log" "path/filepath" + "github.com/hashicorp/packer/common" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" ) @@ -24,7 +25,7 @@ type StepCopyFiles struct { func (s *StepCopyFiles) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction { mountPath := state.Get("mount_path").(string) ui := state.Get("ui").(packer.Ui) - wrappedCommand := state.Get("wrappedCommand").(CommandWrapper) + wrappedCommand := state.Get("wrappedCommand").(common.CommandWrapper) stderr := new(bytes.Buffer) s.files = make([]string, 0, len(s.Files)) @@ -44,7 +45,7 @@ func (s *StepCopyFiles) Run(ctx context.Context, state multistep.StateBag) multi } stderr.Reset() - cmd := ShellCommand(cmdText) + cmd := common.ShellCommand(cmdText) cmd.Stderr = stderr if err := cmd.Run(); err != nil { err := fmt.Errorf( @@ -70,7 +71,7 @@ func (s *StepCopyFiles) Cleanup(state multistep.StateBag) { } func (s *StepCopyFiles) CleanupFunc(state multistep.StateBag) error { - wrappedCommand := state.Get("wrappedCommand").(CommandWrapper) + wrappedCommand := state.Get("wrappedCommand").(common.CommandWrapper) if s.files != nil { for _, file := range s.files { log.Printf("Removing: %s", file) @@ -79,7 +80,7 @@ func (s *StepCopyFiles) CleanupFunc(state multistep.StateBag) error { return err } - localCmd := ShellCommand(localCmdText) + localCmd := common.ShellCommand(localCmdText) if err := localCmd.Run(); err != nil { return err } diff --git a/builder/amazon/chroot/step_mount_device.go b/builder/amazon/chroot/step_mount_device.go index dd9a66873..052a2d90a 100644 --- a/builder/amazon/chroot/step_mount_device.go +++ b/builder/amazon/chroot/step_mount_device.go @@ -10,6 +10,7 @@ import ( "strings" "github.com/aws/aws-sdk-go/service/ec2" + "github.com/hashicorp/packer/common" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" "github.com/hashicorp/packer/template/interpolate" @@ -39,7 +40,7 @@ func (s *StepMountDevice) Run(ctx context.Context, state multistep.StateBag) mul // customizable device path for mounting NVME block devices on c5 and m5 HVM device = config.NVMEDevicePath } - wrappedCommand := state.Get("wrappedCommand").(CommandWrapper) + wrappedCommand := state.Get("wrappedCommand").(common.CommandWrapper) var virtualizationType string if config.FromScratch || config.AMIVirtType != "" { @@ -104,7 +105,7 @@ func (s *StepMountDevice) Run(ctx context.Context, state multistep.StateBag) mul return multistep.ActionHalt } log.Printf("[DEBUG] (step mount) mount command is %s", mountCommand) - cmd := ShellCommand(mountCommand) + cmd := common.ShellCommand(mountCommand) cmd.Stderr = stderr if err := cmd.Run(); err != nil { err := fmt.Errorf( @@ -135,7 +136,7 @@ func (s *StepMountDevice) CleanupFunc(state multistep.StateBag) error { } ui := state.Get("ui").(packer.Ui) - wrappedCommand := state.Get("wrappedCommand").(CommandWrapper) + wrappedCommand := state.Get("wrappedCommand").(common.CommandWrapper) ui.Say("Unmounting the root device...") unmountCommand, err := wrappedCommand(fmt.Sprintf("umount %s", s.mountPath)) @@ -143,7 +144,7 @@ func (s *StepMountDevice) CleanupFunc(state multistep.StateBag) error { return fmt.Errorf("Error creating unmount command: %s", err) } - cmd := ShellCommand(unmountCommand) + cmd := common.ShellCommand(unmountCommand) if err := cmd.Run(); err != nil { return fmt.Errorf("Error unmounting root device: %s", err) } diff --git a/builder/amazon/chroot/step_mount_extra.go b/builder/amazon/chroot/step_mount_extra.go index e1b03abbb..a8a9f3ffb 100644 --- a/builder/amazon/chroot/step_mount_extra.go +++ b/builder/amazon/chroot/step_mount_extra.go @@ -8,6 +8,7 @@ import ( "os/exec" "syscall" + "github.com/hashicorp/packer/common" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" ) @@ -24,7 +25,7 @@ type StepMountExtra struct { func (s *StepMountExtra) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction { mountPath := state.Get("mount_path").(string) ui := state.Get("ui").(packer.Ui) - wrappedCommand := state.Get("wrappedCommand").(CommandWrapper) + wrappedCommand := state.Get("wrappedCommand").(common.CommandWrapper) s.mounts = make([]string, 0, len(s.ChrootMounts)) @@ -58,7 +59,7 @@ func (s *StepMountExtra) Run(ctx context.Context, state multistep.StateBag) mult return multistep.ActionHalt } - cmd := ShellCommand(mountCommand) + cmd := common.ShellCommand(mountCommand) cmd.Stderr = stderr if err := cmd.Run(); err != nil { err := fmt.Errorf( @@ -89,7 +90,7 @@ func (s *StepMountExtra) CleanupFunc(state multistep.StateBag) error { return nil } - wrappedCommand := state.Get("wrappedCommand").(CommandWrapper) + wrappedCommand := state.Get("wrappedCommand").(common.CommandWrapper) for len(s.mounts) > 0 { var path string lastIndex := len(s.mounts) - 1 @@ -103,7 +104,7 @@ func (s *StepMountExtra) CleanupFunc(state multistep.StateBag) error { // Before attempting to unmount, // check to see if path is already unmounted stderr := new(bytes.Buffer) - cmd := ShellCommand(grepCommand) + cmd := common.ShellCommand(grepCommand) cmd.Stderr = stderr if err := cmd.Run(); err != nil { if exitError, ok := err.(*exec.ExitError); ok { @@ -124,7 +125,7 @@ func (s *StepMountExtra) CleanupFunc(state multistep.StateBag) error { } stderr = new(bytes.Buffer) - cmd = ShellCommand(unmountCommand) + cmd = common.ShellCommand(unmountCommand) cmd.Stderr = stderr if err := cmd.Run(); err != nil { return fmt.Errorf( diff --git a/builder/amazon/chroot/step_post_mount_commands.go b/builder/amazon/chroot/step_post_mount_commands.go index c152d409f..77f0cfc72 100644 --- a/builder/amazon/chroot/step_post_mount_commands.go +++ b/builder/amazon/chroot/step_post_mount_commands.go @@ -3,6 +3,7 @@ package chroot import ( "context" + "github.com/hashicorp/packer/common" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" ) @@ -23,7 +24,7 @@ func (s *StepPostMountCommands) Run(ctx context.Context, state multistep.StateBa device := state.Get("device").(string) mountPath := state.Get("mount_path").(string) ui := state.Get("ui").(packer.Ui) - wrappedCommand := state.Get("wrappedCommand").(CommandWrapper) + wrappedCommand := state.Get("wrappedCommand").(common.CommandWrapper) if len(s.Commands) == 0 { return multistep.ActionContinue diff --git a/builder/amazon/chroot/step_pre_mount_commands.go b/builder/amazon/chroot/step_pre_mount_commands.go index 635ee84d0..8ff829917 100644 --- a/builder/amazon/chroot/step_pre_mount_commands.go +++ b/builder/amazon/chroot/step_pre_mount_commands.go @@ -3,6 +3,7 @@ package chroot import ( "context" + "github.com/hashicorp/packer/common" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" ) @@ -20,7 +21,7 @@ func (s *StepPreMountCommands) Run(ctx context.Context, state multistep.StateBag config := state.Get("config").(interpolateContextProvider) device := state.Get("device").(string) ui := state.Get("ui").(packer.Ui) - wrappedCommand := state.Get("wrappedCommand").(CommandWrapper) + wrappedCommand := state.Get("wrappedCommand").(common.CommandWrapper) if len(s.Commands) == 0 { return multistep.ActionContinue diff --git a/builder/azure/chroot/builder.go b/builder/azure/chroot/builder.go index ee2dbe08f..726610afc 100644 --- a/builder/azure/chroot/builder.go +++ b/builder/azure/chroot/builder.go @@ -317,7 +317,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack state.Put("hook", hook) state.Put("ui", ui) state.Put("azureclient", azcli) - state.Put("wrappedCommand", chroot.CommandWrapper(wrappedCommand)) + state.Put("wrappedCommand", common.CommandWrapper(wrappedCommand)) info, err := azcli.MetadataClient().GetComputeInfo() if err != nil { diff --git a/builder/azure/chroot/step_mount_device.go b/builder/azure/chroot/step_mount_device.go index 7c197fbea..e4fc02595 100644 --- a/builder/azure/chroot/step_mount_device.go +++ b/builder/azure/chroot/step_mount_device.go @@ -6,14 +6,15 @@ import ( "bytes" "context" "fmt" - "github.com/hashicorp/packer/builder/amazon/chroot" - "github.com/hashicorp/packer/helper/multistep" - "github.com/hashicorp/packer/packer" - "github.com/hashicorp/packer/template/interpolate" "log" "os" "path/filepath" "strings" + + "github.com/hashicorp/packer/common" + "github.com/hashicorp/packer/helper/multistep" + "github.com/hashicorp/packer/packer" + "github.com/hashicorp/packer/template/interpolate" ) var _ multistep.Step = &StepMountDevice{} @@ -30,7 +31,7 @@ func (s *StepMountDevice) Run(ctx context.Context, state multistep.StateBag) mul ui := state.Get("ui").(packer.Ui) device := state.Get("device").(string) config := state.Get("config").(*Config) - wrappedCommand := state.Get("wrappedCommand").(chroot.CommandWrapper) + wrappedCommand := state.Get("wrappedCommand").(common.CommandWrapper) ictx := config.ctx @@ -83,7 +84,7 @@ func (s *StepMountDevice) Run(ctx context.Context, state multistep.StateBag) mul return multistep.ActionHalt } log.Printf("[DEBUG] (step mount) mount command is %s", mountCommand) - cmd := chroot.ShellCommand(mountCommand) + cmd := common.ShellCommand(mountCommand) cmd.Stderr = stderr if err := cmd.Run(); err != nil { err := fmt.Errorf( @@ -114,7 +115,7 @@ func (s *StepMountDevice) CleanupFunc(state multistep.StateBag) error { } ui := state.Get("ui").(packer.Ui) - wrappedCommand := state.Get("wrappedCommand").(chroot.CommandWrapper) + wrappedCommand := state.Get("wrappedCommand").(common.CommandWrapper) ui.Say("Unmounting the root device...") unmountCommand, err := wrappedCommand(fmt.Sprintf("umount %s", s.mountPath)) @@ -122,7 +123,7 @@ func (s *StepMountDevice) CleanupFunc(state multistep.StateBag) error { return fmt.Errorf("error creating unmount command: %s", err) } - cmd := chroot.ShellCommand(unmountCommand) + cmd := common.ShellCommand(unmountCommand) if err := cmd.Run(); err != nil { return fmt.Errorf("error unmounting root device: %s", err) } diff --git a/builder/amazon/chroot/command.go b/common/command.go similarity index 96% rename from builder/amazon/chroot/command.go rename to common/command.go index 0ca55be67..eaceb75a2 100644 --- a/builder/amazon/chroot/command.go +++ b/common/command.go @@ -1,4 +1,4 @@ -package chroot +package common import ( "os/exec" From 3be7d81ce22c936a774e086c622a04058bf45543 Mon Sep 17 00:00:00 2001 From: Paul Meyer Date: Thu, 24 Oct 2019 04:21:08 +0000 Subject: [PATCH 2/2] Move common steps together --- builder/amazon/chroot/builder.go | 17 +++++++---------- .../amazon/chroot/step_attach_volume_test.go | 8 ++++++-- builder/amazon/chroot/step_early_unflock.go | 3 ++- builder/amazon/chroot/step_flock_test.go | 8 ++++++-- builder/amazon/chroot/step_mount_device_test.go | 8 ++++++-- builder/azure/chroot/builder.go | 2 +- {builder/amazon => common}/chroot/cleanup.go | 0 .../amazon => common}/chroot/communicator.go | 0 .../chroot/communicator_test.go | 0 common/chroot/interpolate_context_provider.go | 7 +++++++ .../chroot/run_local_commands.go | 0 .../chroot/step_chroot_provision.go | 0 .../amazon => common}/chroot/step_copy_files.go | 0 .../chroot/step_copy_files_test.go | 0 .../chroot/step_early_cleanup.go | 0 .../chroot/step_mount_extra.go | 0 .../chroot/step_mount_extra_test.go | 0 .../chroot/step_post_mount_commands.go | 0 .../chroot/step_pre_mount_commands.go | 0 19 files changed, 35 insertions(+), 18 deletions(-) rename {builder/amazon => common}/chroot/cleanup.go (100%) rename {builder/amazon => common}/chroot/communicator.go (100%) rename {builder/amazon => common}/chroot/communicator_test.go (100%) create mode 100644 common/chroot/interpolate_context_provider.go rename {builder/amazon => common}/chroot/run_local_commands.go (100%) rename {builder/amazon => common}/chroot/step_chroot_provision.go (100%) rename {builder/amazon => common}/chroot/step_copy_files.go (100%) rename {builder/amazon => common}/chroot/step_copy_files_test.go (100%) rename {builder/amazon => common}/chroot/step_early_cleanup.go (100%) rename {builder/amazon => common}/chroot/step_mount_extra.go (100%) rename {builder/amazon => common}/chroot/step_mount_extra_test.go (100%) rename {builder/amazon => common}/chroot/step_post_mount_commands.go (100%) rename {builder/amazon => common}/chroot/step_pre_mount_commands.go (100%) diff --git a/builder/amazon/chroot/builder.go b/builder/amazon/chroot/builder.go index ce5fa9d73..ba065dc87 100644 --- a/builder/amazon/chroot/builder.go +++ b/builder/amazon/chroot/builder.go @@ -15,6 +15,7 @@ import ( "github.com/aws/aws-sdk-go/service/ec2" awscommon "github.com/hashicorp/packer/builder/amazon/common" "github.com/hashicorp/packer/common" + "github.com/hashicorp/packer/common/chroot" "github.com/hashicorp/packer/helper/config" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" @@ -173,10 +174,6 @@ func (c *Config) GetContext() interpolate.Context { return c.ctx } -type interpolateContextProvider interface { - GetContext() interpolate.Context -} - type wrappedCommandTemplate struct { Command string } @@ -391,24 +388,24 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack }, &StepAttachVolume{}, &StepEarlyUnflock{}, - &StepPreMountCommands{ + &chroot.StepPreMountCommands{ Commands: b.config.PreMountCommands, }, &StepMountDevice{ MountOptions: b.config.MountOptions, MountPartition: b.config.MountPartition, }, - &StepPostMountCommands{ + &chroot.StepPostMountCommands{ Commands: b.config.PostMountCommands, }, - &StepMountExtra{ + &chroot.StepMountExtra{ ChrootMounts: b.config.ChrootMounts, }, - &StepCopyFiles{ + &chroot.StepCopyFiles{ Files: b.config.CopyFiles, }, - &StepChrootProvision{}, - &StepEarlyCleanup{}, + &chroot.StepChrootProvision{}, + &chroot.StepEarlyCleanup{}, &StepSnapshot{}, &awscommon.StepDeregisterAMI{ AccessConfig: &b.config.AccessConfig, diff --git a/builder/amazon/chroot/step_attach_volume_test.go b/builder/amazon/chroot/step_attach_volume_test.go index 63f629b77..3d3cc135e 100644 --- a/builder/amazon/chroot/step_attach_volume_test.go +++ b/builder/amazon/chroot/step_attach_volume_test.go @@ -1,11 +1,15 @@ package chroot -import "testing" +import ( + "testing" + + "github.com/hashicorp/packer/common/chroot" +) func TestAttachVolumeCleanupFunc_ImplementsCleanupFunc(t *testing.T) { var raw interface{} raw = new(StepAttachVolume) - if _, ok := raw.(Cleanup); !ok { + if _, ok := raw.(chroot.Cleanup); !ok { t.Fatalf("cleanup func should be a CleanupFunc") } } diff --git a/builder/amazon/chroot/step_early_unflock.go b/builder/amazon/chroot/step_early_unflock.go index b16becc61..bae757f8a 100644 --- a/builder/amazon/chroot/step_early_unflock.go +++ b/builder/amazon/chroot/step_early_unflock.go @@ -5,6 +5,7 @@ import ( "fmt" "log" + "github.com/hashicorp/packer/common/chroot" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" ) @@ -13,7 +14,7 @@ import ( type StepEarlyUnflock struct{} func (s *StepEarlyUnflock) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction { - cleanup := state.Get("flock_cleanup").(Cleanup) + cleanup := state.Get("flock_cleanup").(chroot.Cleanup) ui := state.Get("ui").(packer.Ui) log.Println("Unlocking file lock...") diff --git a/builder/amazon/chroot/step_flock_test.go b/builder/amazon/chroot/step_flock_test.go index a50cbd93d..698a4906d 100644 --- a/builder/amazon/chroot/step_flock_test.go +++ b/builder/amazon/chroot/step_flock_test.go @@ -1,11 +1,15 @@ package chroot -import "testing" +import ( + "testing" + + "github.com/hashicorp/packer/common/chroot" +) func TestFlockCleanupFunc_ImplementsCleanupFunc(t *testing.T) { var raw interface{} raw = new(StepFlock) - if _, ok := raw.(Cleanup); !ok { + if _, ok := raw.(chroot.Cleanup); !ok { t.Fatalf("cleanup func should be a CleanupFunc") } } diff --git a/builder/amazon/chroot/step_mount_device_test.go b/builder/amazon/chroot/step_mount_device_test.go index 2eeb850eb..88418451b 100644 --- a/builder/amazon/chroot/step_mount_device_test.go +++ b/builder/amazon/chroot/step_mount_device_test.go @@ -1,11 +1,15 @@ package chroot -import "testing" +import ( + "testing" + + "github.com/hashicorp/packer/common/chroot" +) func TestMountDeviceCleanupFunc_ImplementsCleanupFunc(t *testing.T) { var raw interface{} raw = new(StepMountDevice) - if _, ok := raw.(Cleanup); !ok { + if _, ok := raw.(chroot.Cleanup); !ok { t.Fatalf("cleanup func should be a CleanupFunc") } } diff --git a/builder/azure/chroot/builder.go b/builder/azure/chroot/builder.go index 726610afc..91ceca991 100644 --- a/builder/azure/chroot/builder.go +++ b/builder/azure/chroot/builder.go @@ -14,10 +14,10 @@ import ( "runtime" "strings" - "github.com/hashicorp/packer/builder/amazon/chroot" azcommon "github.com/hashicorp/packer/builder/azure/common" "github.com/hashicorp/packer/builder/azure/common/client" "github.com/hashicorp/packer/common" + "github.com/hashicorp/packer/common/chroot" "github.com/hashicorp/packer/helper/config" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" diff --git a/builder/amazon/chroot/cleanup.go b/common/chroot/cleanup.go similarity index 100% rename from builder/amazon/chroot/cleanup.go rename to common/chroot/cleanup.go diff --git a/builder/amazon/chroot/communicator.go b/common/chroot/communicator.go similarity index 100% rename from builder/amazon/chroot/communicator.go rename to common/chroot/communicator.go diff --git a/builder/amazon/chroot/communicator_test.go b/common/chroot/communicator_test.go similarity index 100% rename from builder/amazon/chroot/communicator_test.go rename to common/chroot/communicator_test.go diff --git a/common/chroot/interpolate_context_provider.go b/common/chroot/interpolate_context_provider.go new file mode 100644 index 000000000..ee19a19de --- /dev/null +++ b/common/chroot/interpolate_context_provider.go @@ -0,0 +1,7 @@ +package chroot + +import "github.com/hashicorp/packer/template/interpolate" + +type interpolateContextProvider interface { + GetContext() interpolate.Context +} diff --git a/builder/amazon/chroot/run_local_commands.go b/common/chroot/run_local_commands.go similarity index 100% rename from builder/amazon/chroot/run_local_commands.go rename to common/chroot/run_local_commands.go diff --git a/builder/amazon/chroot/step_chroot_provision.go b/common/chroot/step_chroot_provision.go similarity index 100% rename from builder/amazon/chroot/step_chroot_provision.go rename to common/chroot/step_chroot_provision.go diff --git a/builder/amazon/chroot/step_copy_files.go b/common/chroot/step_copy_files.go similarity index 100% rename from builder/amazon/chroot/step_copy_files.go rename to common/chroot/step_copy_files.go diff --git a/builder/amazon/chroot/step_copy_files_test.go b/common/chroot/step_copy_files_test.go similarity index 100% rename from builder/amazon/chroot/step_copy_files_test.go rename to common/chroot/step_copy_files_test.go diff --git a/builder/amazon/chroot/step_early_cleanup.go b/common/chroot/step_early_cleanup.go similarity index 100% rename from builder/amazon/chroot/step_early_cleanup.go rename to common/chroot/step_early_cleanup.go diff --git a/builder/amazon/chroot/step_mount_extra.go b/common/chroot/step_mount_extra.go similarity index 100% rename from builder/amazon/chroot/step_mount_extra.go rename to common/chroot/step_mount_extra.go diff --git a/builder/amazon/chroot/step_mount_extra_test.go b/common/chroot/step_mount_extra_test.go similarity index 100% rename from builder/amazon/chroot/step_mount_extra_test.go rename to common/chroot/step_mount_extra_test.go diff --git a/builder/amazon/chroot/step_post_mount_commands.go b/common/chroot/step_post_mount_commands.go similarity index 100% rename from builder/amazon/chroot/step_post_mount_commands.go rename to common/chroot/step_post_mount_commands.go diff --git a/builder/amazon/chroot/step_pre_mount_commands.go b/common/chroot/step_pre_mount_commands.go similarity index 100% rename from builder/amazon/chroot/step_pre_mount_commands.go rename to common/chroot/step_pre_mount_commands.go