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