From 9387ba0fd45029f7291703091010d0ddde739768 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 15 Jul 2013 09:58:32 +0900 Subject: [PATCH] packer: Make builder type available in configs [GH-154] --- builder/virtualbox/builder.go | 54 +++++++++++++++++------------------ builder/vmware/builder.go | 6 ++-- packer/build.go | 12 ++++++-- packer/build_test.go | 15 ++++++---- packer/template_test.go | 2 +- 5 files changed, 49 insertions(+), 40 deletions(-) diff --git a/builder/virtualbox/builder.go b/builder/virtualbox/builder.go index da716d30c..a925f4a65 100644 --- a/builder/virtualbox/builder.go +++ b/builder/virtualbox/builder.go @@ -26,30 +26,30 @@ type Builder struct { } type config struct { - BootCommand []string `mapstructure:"boot_command"` - DiskSize uint `mapstructure:"disk_size"` - FloppyFiles []string `mapstructure:"floppy_files"` - GuestAdditionsPath string `mapstructure:"guest_additions_path"` - GuestAdditionsURL string `mapstructure:"guest_additions_url"` - GuestAdditionsSHA256 string `mapstructure:"guest_additions_sha256"` - GuestOSType string `mapstructure:"guest_os_type"` - Headless bool `mapstructure:"headless"` - HTTPDir string `mapstructure:"http_directory"` - HTTPPortMin uint `mapstructure:"http_port_min"` - HTTPPortMax uint `mapstructure:"http_port_max"` - ISOChecksum string `mapstructure:"iso_checksum"` - ISOChecksumType string `mapstructure:"iso_checksum_type"` - ISOUrl string `mapstructure:"iso_url"` - OutputDir string `mapstructure:"output_directory"` - ShutdownCommand string `mapstructure:"shutdown_command"` - SSHHostPortMin uint `mapstructure:"ssh_host_port_min"` - SSHHostPortMax uint `mapstructure:"ssh_host_port_max"` - SSHPassword string `mapstructure:"ssh_password"` - SSHPort uint `mapstructure:"ssh_port"` - SSHUser string `mapstructure:"ssh_username"` - VBoxVersionFile string `mapstructure:"virtualbox_version_file"` - VBoxManage [][]string `mapstructure:"vboxmanage"` - VMName string `mapstructure:"vm_name"` + BootCommand []string `mapstructure:"boot_command"` + DiskSize uint `mapstructure:"disk_size"` + FloppyFiles []string `mapstructure:"floppy_files"` + GuestAdditionsPath string `mapstructure:"guest_additions_path"` + GuestAdditionsURL string `mapstructure:"guest_additions_url"` + GuestAdditionsSHA256 string `mapstructure:"guest_additions_sha256"` + GuestOSType string `mapstructure:"guest_os_type"` + Headless bool `mapstructure:"headless"` + HTTPDir string `mapstructure:"http_directory"` + HTTPPortMin uint `mapstructure:"http_port_min"` + HTTPPortMax uint `mapstructure:"http_port_max"` + ISOChecksum string `mapstructure:"iso_checksum"` + ISOChecksumType string `mapstructure:"iso_checksum_type"` + ISOUrl string `mapstructure:"iso_url"` + OutputDir string `mapstructure:"output_directory"` + ShutdownCommand string `mapstructure:"shutdown_command"` + SSHHostPortMin uint `mapstructure:"ssh_host_port_min"` + SSHHostPortMax uint `mapstructure:"ssh_host_port_max"` + SSHPassword string `mapstructure:"ssh_password"` + SSHPort uint `mapstructure:"ssh_port"` + SSHUser string `mapstructure:"ssh_username"` + VBoxVersionFile string `mapstructure:"virtualbox_version_file"` + VBoxManage [][]string `mapstructure:"vboxmanage"` + VMName string `mapstructure:"vm_name"` PackerBuildName string `mapstructure:"packer_build_name"` PackerDebug bool `mapstructure:"packer_debug"` @@ -59,9 +59,9 @@ type config struct { RawShutdownTimeout string `mapstructure:"shutdown_timeout"` RawSSHWaitTimeout string `mapstructure:"ssh_wait_timeout"` - bootWait time.Duration `` - shutdownTimeout time.Duration `` - sshWaitTimeout time.Duration `` + bootWait time.Duration `` + shutdownTimeout time.Duration `` + sshWaitTimeout time.Duration `` } func (b *Builder) Prepare(raws ...interface{}) error { diff --git a/builder/vmware/builder.go b/builder/vmware/builder.go index 832cbd8c3..ae44fb215 100644 --- a/builder/vmware/builder.go +++ b/builder/vmware/builder.go @@ -60,9 +60,9 @@ type config struct { RawShutdownTimeout string `mapstructure:"shutdown_timeout"` RawSSHWaitTimeout string `mapstructure:"ssh_wait_timeout"` - bootWait time.Duration `` - shutdownTimeout time.Duration `` - sshWaitTimeout time.Duration `` + bootWait time.Duration `` + shutdownTimeout time.Duration `` + sshWaitTimeout time.Duration `` } func (b *Builder) Prepare(raws ...interface{}) error { diff --git a/packer/build.go b/packer/build.go index c24c2291e..475f34718 100644 --- a/packer/build.go +++ b/packer/build.go @@ -11,6 +11,11 @@ const ( // build. BuildNameConfigKey = "packer_build_name" + // This is the key in the configuration that is set to the type + // of the builder that is run. This is useful for provisioners and + // such who want to make use of this. + BuilderTypeConfigKey = "packer_builder_type" + // This is the key in configurations that is set to "true" when Packer // debugging is enabled. DebugConfigKey = "packer_debug" @@ -109,9 +114,10 @@ func (b *coreBuild) Prepare() (err error) { b.prepareCalled = true packerConfig := map[string]interface{}{ - BuildNameConfigKey: b.name, - DebugConfigKey: b.debug, - ForceConfigKey: b.force, + BuildNameConfigKey: b.name, + BuilderTypeConfigKey: b.builderType, + DebugConfigKey: b.debug, + ForceConfigKey: b.force, } // Prepare the builder diff --git a/packer/build_test.go b/packer/build_test.go index f792391ca..ac4df90b5 100644 --- a/packer/build_test.go +++ b/packer/build_test.go @@ -11,6 +11,7 @@ func testBuild() *coreBuild { name: "test", builder: &TestBuilder{artifactId: "b"}, builderConfig: 42, + builderType: "foo", hooks: map[string][]Hook{ "foo": []Hook{&TestHook{}}, }, @@ -40,9 +41,10 @@ func TestBuild_Prepare(t *testing.T) { assert := asserts.NewTestingAsserts(t, true) packerConfig := map[string]interface{}{ - BuildNameConfigKey: "test", - DebugConfigKey: false, - ForceConfigKey: false, + BuildNameConfigKey: "test", + BuilderTypeConfigKey: "foo", + DebugConfigKey: false, + ForceConfigKey: false, } build := testBuild() @@ -87,9 +89,10 @@ func TestBuild_Prepare_Debug(t *testing.T) { assert := asserts.NewTestingAsserts(t, true) packerConfig := map[string]interface{}{ - BuildNameConfigKey: "test", - DebugConfigKey: true, - ForceConfigKey: false, + BuildNameConfigKey: "test", + BuilderTypeConfigKey: "foo", + DebugConfigKey: true, + ForceConfigKey: false, } build := testBuild() diff --git a/packer/template_test.go b/packer/template_test.go index 0e65d6af0..af7e3e402 100644 --- a/packer/template_test.go +++ b/packer/template_test.go @@ -2,8 +2,8 @@ package packer import ( "cgl.tideland.biz/asserts" - "sort" "reflect" + "sort" "testing" )