packer: Make builder type available in configs [GH-154]

This commit is contained in:
Mitchell Hashimoto 2013-07-15 09:58:32 +09:00
parent f621f88913
commit 9387ba0fd4
5 changed files with 49 additions and 40 deletions

View File

@ -26,30 +26,30 @@ type Builder struct {
} }
type config struct { type config struct {
BootCommand []string `mapstructure:"boot_command"` BootCommand []string `mapstructure:"boot_command"`
DiskSize uint `mapstructure:"disk_size"` DiskSize uint `mapstructure:"disk_size"`
FloppyFiles []string `mapstructure:"floppy_files"` FloppyFiles []string `mapstructure:"floppy_files"`
GuestAdditionsPath string `mapstructure:"guest_additions_path"` GuestAdditionsPath string `mapstructure:"guest_additions_path"`
GuestAdditionsURL string `mapstructure:"guest_additions_url"` GuestAdditionsURL string `mapstructure:"guest_additions_url"`
GuestAdditionsSHA256 string `mapstructure:"guest_additions_sha256"` GuestAdditionsSHA256 string `mapstructure:"guest_additions_sha256"`
GuestOSType string `mapstructure:"guest_os_type"` GuestOSType string `mapstructure:"guest_os_type"`
Headless bool `mapstructure:"headless"` Headless bool `mapstructure:"headless"`
HTTPDir string `mapstructure:"http_directory"` HTTPDir string `mapstructure:"http_directory"`
HTTPPortMin uint `mapstructure:"http_port_min"` HTTPPortMin uint `mapstructure:"http_port_min"`
HTTPPortMax uint `mapstructure:"http_port_max"` HTTPPortMax uint `mapstructure:"http_port_max"`
ISOChecksum string `mapstructure:"iso_checksum"` ISOChecksum string `mapstructure:"iso_checksum"`
ISOChecksumType string `mapstructure:"iso_checksum_type"` ISOChecksumType string `mapstructure:"iso_checksum_type"`
ISOUrl string `mapstructure:"iso_url"` ISOUrl string `mapstructure:"iso_url"`
OutputDir string `mapstructure:"output_directory"` OutputDir string `mapstructure:"output_directory"`
ShutdownCommand string `mapstructure:"shutdown_command"` ShutdownCommand string `mapstructure:"shutdown_command"`
SSHHostPortMin uint `mapstructure:"ssh_host_port_min"` SSHHostPortMin uint `mapstructure:"ssh_host_port_min"`
SSHHostPortMax uint `mapstructure:"ssh_host_port_max"` SSHHostPortMax uint `mapstructure:"ssh_host_port_max"`
SSHPassword string `mapstructure:"ssh_password"` SSHPassword string `mapstructure:"ssh_password"`
SSHPort uint `mapstructure:"ssh_port"` SSHPort uint `mapstructure:"ssh_port"`
SSHUser string `mapstructure:"ssh_username"` SSHUser string `mapstructure:"ssh_username"`
VBoxVersionFile string `mapstructure:"virtualbox_version_file"` VBoxVersionFile string `mapstructure:"virtualbox_version_file"`
VBoxManage [][]string `mapstructure:"vboxmanage"` VBoxManage [][]string `mapstructure:"vboxmanage"`
VMName string `mapstructure:"vm_name"` VMName string `mapstructure:"vm_name"`
PackerBuildName string `mapstructure:"packer_build_name"` PackerBuildName string `mapstructure:"packer_build_name"`
PackerDebug bool `mapstructure:"packer_debug"` PackerDebug bool `mapstructure:"packer_debug"`
@ -59,9 +59,9 @@ type config struct {
RawShutdownTimeout string `mapstructure:"shutdown_timeout"` RawShutdownTimeout string `mapstructure:"shutdown_timeout"`
RawSSHWaitTimeout string `mapstructure:"ssh_wait_timeout"` RawSSHWaitTimeout string `mapstructure:"ssh_wait_timeout"`
bootWait time.Duration `` bootWait time.Duration ``
shutdownTimeout time.Duration `` shutdownTimeout time.Duration ``
sshWaitTimeout time.Duration `` sshWaitTimeout time.Duration ``
} }
func (b *Builder) Prepare(raws ...interface{}) error { func (b *Builder) Prepare(raws ...interface{}) error {

View File

@ -60,9 +60,9 @@ type config struct {
RawShutdownTimeout string `mapstructure:"shutdown_timeout"` RawShutdownTimeout string `mapstructure:"shutdown_timeout"`
RawSSHWaitTimeout string `mapstructure:"ssh_wait_timeout"` RawSSHWaitTimeout string `mapstructure:"ssh_wait_timeout"`
bootWait time.Duration `` bootWait time.Duration ``
shutdownTimeout time.Duration `` shutdownTimeout time.Duration ``
sshWaitTimeout time.Duration `` sshWaitTimeout time.Duration ``
} }
func (b *Builder) Prepare(raws ...interface{}) error { func (b *Builder) Prepare(raws ...interface{}) error {

View File

@ -11,6 +11,11 @@ const (
// build. // build.
BuildNameConfigKey = "packer_build_name" 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 // This is the key in configurations that is set to "true" when Packer
// debugging is enabled. // debugging is enabled.
DebugConfigKey = "packer_debug" DebugConfigKey = "packer_debug"
@ -109,9 +114,10 @@ func (b *coreBuild) Prepare() (err error) {
b.prepareCalled = true b.prepareCalled = true
packerConfig := map[string]interface{}{ packerConfig := map[string]interface{}{
BuildNameConfigKey: b.name, BuildNameConfigKey: b.name,
DebugConfigKey: b.debug, BuilderTypeConfigKey: b.builderType,
ForceConfigKey: b.force, DebugConfigKey: b.debug,
ForceConfigKey: b.force,
} }
// Prepare the builder // Prepare the builder

View File

@ -11,6 +11,7 @@ func testBuild() *coreBuild {
name: "test", name: "test",
builder: &TestBuilder{artifactId: "b"}, builder: &TestBuilder{artifactId: "b"},
builderConfig: 42, builderConfig: 42,
builderType: "foo",
hooks: map[string][]Hook{ hooks: map[string][]Hook{
"foo": []Hook{&TestHook{}}, "foo": []Hook{&TestHook{}},
}, },
@ -40,9 +41,10 @@ func TestBuild_Prepare(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true) assert := asserts.NewTestingAsserts(t, true)
packerConfig := map[string]interface{}{ packerConfig := map[string]interface{}{
BuildNameConfigKey: "test", BuildNameConfigKey: "test",
DebugConfigKey: false, BuilderTypeConfigKey: "foo",
ForceConfigKey: false, DebugConfigKey: false,
ForceConfigKey: false,
} }
build := testBuild() build := testBuild()
@ -87,9 +89,10 @@ func TestBuild_Prepare_Debug(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true) assert := asserts.NewTestingAsserts(t, true)
packerConfig := map[string]interface{}{ packerConfig := map[string]interface{}{
BuildNameConfigKey: "test", BuildNameConfigKey: "test",
DebugConfigKey: true, BuilderTypeConfigKey: "foo",
ForceConfigKey: false, DebugConfigKey: true,
ForceConfigKey: false,
} }
build := testBuild() build := testBuild()

View File

@ -2,8 +2,8 @@ package packer
import ( import (
"cgl.tideland.biz/asserts" "cgl.tideland.biz/asserts"
"sort"
"reflect" "reflect"
"sort"
"testing" "testing"
) )