Merge pull request #122 from smerrill/compaction-option

builder/vmware: Add a 'skip_compaction' configuration option
This commit is contained in:
Mitchell Hashimoto 2013-07-02 21:27:20 -07:00
commit 6f4e08944b
3 changed files with 16 additions and 1 deletions

View File

@ -39,6 +39,7 @@ type config struct {
HTTPPortMax uint `mapstructure:"http_port_max"` HTTPPortMax uint `mapstructure:"http_port_max"`
BootCommand []string `mapstructure:"boot_command"` BootCommand []string `mapstructure:"boot_command"`
BootWait time.Duration `` BootWait time.Duration ``
SkipCompaction bool `mapstructure:"skip_compaction"`
ShutdownCommand string `mapstructure:"shutdown_command"` ShutdownCommand string `mapstructure:"shutdown_command"`
ShutdownTimeout time.Duration `` ShutdownTimeout time.Duration ``
SSHUser string `mapstructure:"ssh_username"` SSHUser string `mapstructure:"ssh_username"`

View File

@ -4,11 +4,14 @@ import (
"fmt" "fmt"
"github.com/mitchellh/multistep" "github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
"log"
) )
// This step compacts the virtual disk for the VM. // This step compacts the virtual disk for the VM unless the "skip_compaction"
// boolean is true.
// //
// Uses: // Uses:
// config *config
// driver Driver // driver Driver
// full_disk_path string // full_disk_path string
// ui packer.Ui // ui packer.Ui
@ -18,10 +21,16 @@ import (
type stepCompactDisk struct{} type stepCompactDisk struct{}
func (stepCompactDisk) Run(state map[string]interface{}) multistep.StepAction { func (stepCompactDisk) Run(state map[string]interface{}) multistep.StepAction {
config := state["config"].(*config)
driver := state["driver"].(Driver) driver := state["driver"].(Driver)
ui := state["ui"].(packer.Ui) ui := state["ui"].(packer.Ui)
full_disk_path := state["full_disk_path"].(string) full_disk_path := state["full_disk_path"].(string)
if config.SkipCompaction == true {
log.Println("Skipping disk compaction step...")
return multistep.ActionContinue
}
ui.Say("Compacting the disk image") ui.Say("Compacting the disk image")
if err := driver.CompactDisk(full_disk_path); err != nil { if err := driver.CompactDisk(full_disk_path); err != nil {
state["error"] = fmt.Errorf("Error compacting disk: %s", err) state["error"] = fmt.Errorf("Error compacting disk: %s", err)

View File

@ -106,6 +106,11 @@ Optional:
By default this is "output-BUILDNAME" where "BUILDNAME" is the name By default this is "output-BUILDNAME" where "BUILDNAME" is the name
of the build. of the build.
* `skip_compaction` (bool) - As of Packer 0.1.4, VMware-created disks are defragmented
and compacted at the end of the build process. If you are doing your own zeroing out
of the disks you may find that the compaction step results in slightly larger boxes.
Compaction will run unless you set this value to true.
* `shutdown_command` (string) - The command to use to gracefully shut down * `shutdown_command` (string) - The command to use to gracefully shut down
the machine once all the provisioning is done. By default this is an empty the machine once all the provisioning is done. By default this is an empty
string, which tells Packer to just forcefully shut down the machine. string, which tells Packer to just forcefully shut down the machine.