2019-05-31 08:27:41 -04:00
|
|
|
//go:generate struct-markdown
|
2019-10-14 10:43:59 -04:00
|
|
|
//go:generate mapstructure-to-hcl2 -type Config
|
2019-05-31 08:27:41 -04:00
|
|
|
|
2013-12-21 17:27:00 -05:00
|
|
|
package iso
|
2013-06-11 18:12:45 -04:00
|
|
|
|
|
|
|
import (
|
2019-03-22 09:53:28 -04:00
|
|
|
"context"
|
2013-06-11 23:00:30 -04:00
|
|
|
"errors"
|
2013-06-11 18:45:52 -04:00
|
|
|
"fmt"
|
2014-09-02 12:35:59 -04:00
|
|
|
"strings"
|
|
|
|
|
2019-12-17 05:25:56 -05:00
|
|
|
"github.com/hashicorp/hcl/v2/hcldec"
|
2017-04-04 16:39:01 -04:00
|
|
|
vboxcommon "github.com/hashicorp/packer/builder/virtualbox/common"
|
|
|
|
"github.com/hashicorp/packer/common"
|
2018-04-18 19:19:44 -04:00
|
|
|
"github.com/hashicorp/packer/common/bootcommand"
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/helper/communicator"
|
|
|
|
"github.com/hashicorp/packer/helper/config"
|
2018-01-19 19:18:44 -05:00
|
|
|
"github.com/hashicorp/packer/helper/multistep"
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/packer"
|
|
|
|
"github.com/hashicorp/packer/template/interpolate"
|
2013-06-11 18:12:45 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
const BuilderId = "mitchellh.virtualbox"
|
|
|
|
|
|
|
|
type Builder struct {
|
2015-05-27 17:01:08 -04:00
|
|
|
config Config
|
2013-06-11 18:12:45 -04:00
|
|
|
runner multistep.Runner
|
|
|
|
}
|
|
|
|
|
2015-05-27 17:01:08 -04:00
|
|
|
type Config struct {
|
2014-03-12 19:14:44 -04:00
|
|
|
common.PackerConfig `mapstructure:",squash"`
|
2015-11-01 17:29:24 -05:00
|
|
|
common.HTTPConfig `mapstructure:",squash"`
|
2015-10-20 19:27:47 -04:00
|
|
|
common.ISOConfig `mapstructure:",squash"`
|
2016-07-26 15:42:04 -04:00
|
|
|
common.FloppyConfig `mapstructure:",squash"`
|
2018-04-18 19:19:44 -04:00
|
|
|
bootcommand.BootConfig `mapstructure:",squash"`
|
2014-03-12 19:14:44 -04:00
|
|
|
vboxcommon.ExportConfig `mapstructure:",squash"`
|
|
|
|
vboxcommon.OutputConfig `mapstructure:",squash"`
|
|
|
|
vboxcommon.RunConfig `mapstructure:",squash"`
|
|
|
|
vboxcommon.ShutdownConfig `mapstructure:",squash"`
|
|
|
|
vboxcommon.SSHConfig `mapstructure:",squash"`
|
2018-11-17 05:24:32 -05:00
|
|
|
vboxcommon.HWConfig `mapstructure:",squash"`
|
2014-03-12 19:14:44 -04:00
|
|
|
vboxcommon.VBoxManageConfig `mapstructure:",squash"`
|
|
|
|
vboxcommon.VBoxVersionConfig `mapstructure:",squash"`
|
2018-02-26 11:47:59 -05:00
|
|
|
vboxcommon.VBoxBundleConfig `mapstructure:",squash"`
|
2019-03-16 12:15:27 -04:00
|
|
|
vboxcommon.GuestAdditionsConfig `mapstructure:",squash"`
|
2019-06-17 10:42:49 -04:00
|
|
|
// The size, in megabytes, of the hard disk to create for the VM. By
|
|
|
|
// default, this is 40000 (about 40 GB).
|
2019-06-06 10:29:25 -04:00
|
|
|
DiskSize uint `mapstructure:"disk_size" required:"false"`
|
2019-06-17 10:42:49 -04:00
|
|
|
// The method by which guest additions are made available to the guest for
|
|
|
|
// installation. Valid options are upload, attach, or disable. If the mode
|
|
|
|
// is attach the guest additions ISO will be attached as a CD device to the
|
|
|
|
// virtual machine. If the mode is upload the guest additions ISO will be
|
|
|
|
// uploaded to the path specified by guest_additions_path. The default
|
|
|
|
// value is upload. If disable is used, guest additions won't be
|
|
|
|
// downloaded, either.
|
2019-06-06 10:29:25 -04:00
|
|
|
GuestAdditionsMode string `mapstructure:"guest_additions_mode" required:"false"`
|
2019-06-17 10:42:49 -04:00
|
|
|
// The path on the guest virtual machine where the VirtualBox guest
|
|
|
|
// additions ISO will be uploaded. By default this is
|
|
|
|
// VBoxGuestAdditions.iso which should upload into the login directory of
|
|
|
|
// the user. This is a configuration template where the Version variable is
|
|
|
|
// replaced with the VirtualBox version.
|
2019-06-06 10:29:25 -04:00
|
|
|
GuestAdditionsPath string `mapstructure:"guest_additions_path" required:"false"`
|
2019-06-17 10:42:49 -04:00
|
|
|
// The SHA256 checksum of the guest additions ISO that will be uploaded to
|
|
|
|
// the guest VM. By default the checksums will be downloaded from the
|
|
|
|
// VirtualBox website, so this only needs to be set if you want to be
|
|
|
|
// explicit about the checksum.
|
2019-06-06 10:29:25 -04:00
|
|
|
GuestAdditionsSHA256 string `mapstructure:"guest_additions_sha256" required:"false"`
|
2019-06-17 10:42:49 -04:00
|
|
|
// The URL to the guest additions ISO to upload. This can also be a file
|
|
|
|
// URL if the ISO is at a local path. By default, the VirtualBox builder
|
|
|
|
// will attempt to find the guest additions ISO on the local file system.
|
|
|
|
// If it is not available locally, the builder will download the proper
|
|
|
|
// guest additions ISO from the internet.
|
2019-06-06 10:29:25 -04:00
|
|
|
GuestAdditionsURL string `mapstructure:"guest_additions_url" required:"false"`
|
2019-06-17 10:42:49 -04:00
|
|
|
// The interface type to use to mount guest additions when
|
|
|
|
// guest_additions_mode is set to attach. Will default to the value set in
|
|
|
|
// iso_interface, if iso_interface is set. Will default to "ide", if
|
|
|
|
// iso_interface is not set. Options are "ide" and "sata".
|
2019-05-28 11:50:58 -04:00
|
|
|
GuestAdditionsInterface string `mapstructure:"guest_additions_interface" required:"false"`
|
2019-06-17 10:42:49 -04:00
|
|
|
// The guest OS type being installed. By default this is other, but you can
|
|
|
|
// get dramatic performance improvements by setting this to the proper
|
|
|
|
// value. To view all available values for this run VBoxManage list
|
|
|
|
// ostypes. Setting the correct value hints to VirtualBox how to optimize
|
|
|
|
// the virtual hardware to work best with that operating system.
|
2019-06-06 10:29:25 -04:00
|
|
|
GuestOSType string `mapstructure:"guest_os_type" required:"false"`
|
2019-06-17 10:42:49 -04:00
|
|
|
// When this value is set to true, a VDI image will be shrunk in response
|
|
|
|
// to the trim command from the guest OS. The size of the cleared area must
|
|
|
|
// be at least 1MB. Also set hard_drive_nonrotational to true to enable
|
|
|
|
// TRIM support.
|
2019-06-06 10:29:25 -04:00
|
|
|
HardDriveDiscard bool `mapstructure:"hard_drive_discard" required:"false"`
|
2019-06-17 10:42:49 -04:00
|
|
|
// The type of controller that the primary hard drive is attached to,
|
|
|
|
// defaults to ide. When set to sata, the drive is attached to an AHCI SATA
|
|
|
|
// controller. When set to scsi, the drive is attached to an LsiLogic SCSI
|
2019-10-31 18:21:52 -04:00
|
|
|
// controller. When set to pcie, the drive is attached to an NVMe
|
2019-11-04 08:30:59 -05:00
|
|
|
// controller. Please note that when you use "pcie", you'll need to have
|
|
|
|
// Virtualbox 6, install an [extension
|
|
|
|
// pack](https://www.virtualbox.org/wiki/Downloads#VirtualBox6.0.14OracleVMVirtualBoxExtensionPack)
|
|
|
|
// and you will need to enable EFI mode for nvme to work, ex:
|
|
|
|
// "vboxmanage": [
|
|
|
|
// [ "modifyvm", "{{.Name}}", "--firmware", "EFI" ],
|
|
|
|
// ]
|
2019-06-06 10:29:25 -04:00
|
|
|
HardDriveInterface string `mapstructure:"hard_drive_interface" required:"false"`
|
2019-06-17 10:42:49 -04:00
|
|
|
// The number of ports available on any SATA controller created, defaults
|
|
|
|
// to 1. VirtualBox supports up to 30 ports on a maximum of 1 SATA
|
|
|
|
// controller. Increasing this value can be useful if you want to attach
|
|
|
|
// additional drives.
|
2019-06-06 10:29:25 -04:00
|
|
|
SATAPortCount int `mapstructure:"sata_port_count" required:"false"`
|
2019-10-31 18:21:52 -04:00
|
|
|
// The number of ports available on any NVMe controller created, defaults
|
|
|
|
// to 1. VirtualBox supports up to 255 ports on a maximum of 1 NVMe
|
|
|
|
// controller. Increasing this value can be useful if you want to attach
|
|
|
|
// additional drives.
|
|
|
|
NVMePortCount int `mapstructure:"nvme_port_count" required:"false"`
|
2019-06-17 10:42:49 -04:00
|
|
|
// Forces some guests (i.e. Windows 7+) to treat disks as SSDs and stops
|
|
|
|
// them from performing disk fragmentation. Also set hard_drive_discard to
|
|
|
|
// true to enable TRIM support.
|
2019-06-06 10:29:25 -04:00
|
|
|
HardDriveNonrotational bool `mapstructure:"hard_drive_nonrotational" required:"false"`
|
2019-06-17 10:42:49 -04:00
|
|
|
// The type of controller that the ISO is attached to, defaults to ide.
|
|
|
|
// When set to sata, the drive is attached to an AHCI SATA controller.
|
2019-06-06 10:29:25 -04:00
|
|
|
ISOInterface string `mapstructure:"iso_interface" required:"false"`
|
2019-06-17 10:42:49 -04:00
|
|
|
// Set this to true if you would like to keep the VM registered with
|
|
|
|
// virtualbox. Defaults to false.
|
2019-06-06 10:29:25 -04:00
|
|
|
KeepRegistered bool `mapstructure:"keep_registered" required:"false"`
|
2019-06-17 10:42:49 -04:00
|
|
|
// Defaults to false. When enabled, Packer will not export the VM. Useful
|
|
|
|
// if the build output is not the resultant image, but created inside the
|
|
|
|
// VM.
|
2019-06-06 10:29:25 -04:00
|
|
|
SkipExport bool `mapstructure:"skip_export" required:"false"`
|
2019-06-17 10:42:49 -04:00
|
|
|
// This is the name of the OVF file for the new virtual machine, without
|
|
|
|
// the file extension. By default this is packer-BUILDNAME, where
|
|
|
|
// "BUILDNAME" is the name of the build.
|
2019-06-06 10:29:25 -04:00
|
|
|
VMName string `mapstructure:"vm_name" required:"false"`
|
2013-06-13 13:24:10 -04:00
|
|
|
|
2015-05-27 17:01:08 -04:00
|
|
|
ctx interpolate.Context
|
2013-06-11 18:12:45 -04:00
|
|
|
}
|
|
|
|
|
2019-12-17 05:25:56 -05:00
|
|
|
func (b *Builder) ConfigSpec() hcldec.ObjectSpec { return b.config.FlatMapstructure().HCL2Spec() }
|
|
|
|
|
2019-12-17 00:23:05 -05:00
|
|
|
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
|
2015-05-27 17:01:08 -04:00
|
|
|
err := config.Decode(&b.config, &config.DecodeOpts{
|
2015-06-22 12:17:09 -04:00
|
|
|
Interpolate: true,
|
|
|
|
InterpolateContext: &b.config.ctx,
|
2015-05-27 17:01:08 -04:00
|
|
|
InterpolateFilter: &interpolate.RenderFilter{
|
|
|
|
Exclude: []string{
|
|
|
|
"boot_command",
|
|
|
|
"guest_additions_path",
|
|
|
|
"guest_additions_url",
|
|
|
|
"vboxmanage",
|
|
|
|
"vboxmanage_post",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, raws...)
|
2013-08-08 19:00:47 -04:00
|
|
|
if err != nil {
|
2019-12-17 00:23:05 -05:00
|
|
|
return nil, nil, err
|
2013-08-08 19:00:47 -04:00
|
|
|
}
|
|
|
|
|
2013-11-03 00:17:21 -04:00
|
|
|
// Accumulate any errors and warnings
|
2015-05-27 17:01:08 -04:00
|
|
|
var errs *packer.MultiError
|
2015-10-20 19:27:47 -04:00
|
|
|
warnings := make([]string, 0)
|
|
|
|
|
|
|
|
isoWarnings, isoErrs := b.config.ISOConfig.Prepare(&b.config.ctx)
|
|
|
|
warnings = append(warnings, isoWarnings...)
|
|
|
|
errs = packer.MultiErrorAppend(errs, isoErrs...)
|
|
|
|
|
2015-05-27 17:01:08 -04:00
|
|
|
errs = packer.MultiErrorAppend(errs, b.config.ExportConfig.Prepare(&b.config.ctx)...)
|
2019-06-19 10:34:14 -04:00
|
|
|
errs = packer.MultiErrorAppend(errs, b.config.ExportConfig.Prepare(&b.config.ctx)...)
|
2015-05-27 17:01:08 -04:00
|
|
|
errs = packer.MultiErrorAppend(errs, b.config.FloppyConfig.Prepare(&b.config.ctx)...)
|
2013-12-21 20:38:06 -05:00
|
|
|
errs = packer.MultiErrorAppend(
|
2015-05-27 17:01:08 -04:00
|
|
|
errs, b.config.OutputConfig.Prepare(&b.config.ctx, &b.config.PackerConfig)...)
|
2015-11-01 17:29:24 -05:00
|
|
|
errs = packer.MultiErrorAppend(errs, b.config.HTTPConfig.Prepare(&b.config.ctx)...)
|
2015-05-27 17:01:08 -04:00
|
|
|
errs = packer.MultiErrorAppend(errs, b.config.RunConfig.Prepare(&b.config.ctx)...)
|
|
|
|
errs = packer.MultiErrorAppend(errs, b.config.ShutdownConfig.Prepare(&b.config.ctx)...)
|
|
|
|
errs = packer.MultiErrorAppend(errs, b.config.SSHConfig.Prepare(&b.config.ctx)...)
|
2018-11-17 05:24:32 -05:00
|
|
|
errs = packer.MultiErrorAppend(errs, b.config.HWConfig.Prepare(&b.config.ctx)...)
|
2018-02-26 11:47:59 -05:00
|
|
|
errs = packer.MultiErrorAppend(errs, b.config.VBoxBundleConfig.Prepare(&b.config.ctx)...)
|
2015-05-27 17:01:08 -04:00
|
|
|
errs = packer.MultiErrorAppend(errs, b.config.VBoxManageConfig.Prepare(&b.config.ctx)...)
|
|
|
|
errs = packer.MultiErrorAppend(errs, b.config.VBoxVersionConfig.Prepare(&b.config.ctx)...)
|
2018-04-18 19:19:44 -04:00
|
|
|
errs = packer.MultiErrorAppend(errs, b.config.BootConfig.Prepare(&b.config.ctx)...)
|
2019-03-16 12:15:27 -04:00
|
|
|
errs = packer.MultiErrorAppend(errs, b.config.GuestAdditionsConfig.Prepare(&b.config.ctx)...)
|
2013-07-13 20:28:56 -04:00
|
|
|
|
2013-06-23 23:43:40 -04:00
|
|
|
if b.config.DiskSize == 0 {
|
|
|
|
b.config.DiskSize = 40000
|
|
|
|
}
|
|
|
|
|
2013-11-02 04:22:56 -04:00
|
|
|
if b.config.GuestAdditionsMode == "" {
|
|
|
|
b.config.GuestAdditionsMode = "upload"
|
|
|
|
}
|
|
|
|
|
2013-06-24 02:05:32 -04:00
|
|
|
if b.config.GuestAdditionsPath == "" {
|
|
|
|
b.config.GuestAdditionsPath = "VBoxGuestAdditions.iso"
|
|
|
|
}
|
|
|
|
|
2013-09-05 14:00:08 -04:00
|
|
|
if b.config.HardDriveInterface == "" {
|
|
|
|
b.config.HardDriveInterface = "ide"
|
|
|
|
}
|
|
|
|
|
2013-06-11 18:57:20 -04:00
|
|
|
if b.config.GuestOSType == "" {
|
|
|
|
b.config.GuestOSType = "Other"
|
|
|
|
}
|
|
|
|
|
2014-05-23 21:14:24 -04:00
|
|
|
if b.config.ISOInterface == "" {
|
|
|
|
b.config.ISOInterface = "ide"
|
|
|
|
}
|
|
|
|
|
2019-02-08 12:15:15 -05:00
|
|
|
if b.config.GuestAdditionsInterface == "" {
|
|
|
|
b.config.GuestAdditionsInterface = b.config.ISOInterface
|
|
|
|
}
|
|
|
|
|
2015-06-22 12:25:15 -04:00
|
|
|
if b.config.VMName == "" {
|
|
|
|
b.config.VMName = fmt.Sprintf(
|
|
|
|
"packer-%s-%d", b.config.PackerBuildName, interpolate.InitTime.Unix())
|
|
|
|
}
|
|
|
|
|
2019-10-31 17:43:46 -04:00
|
|
|
switch b.config.HardDriveInterface {
|
2019-10-31 18:21:52 -04:00
|
|
|
case "ide", "sata", "scsi", "pcie":
|
2019-10-31 17:43:46 -04:00
|
|
|
// do nothing
|
|
|
|
default:
|
2013-09-05 15:07:58 -04:00
|
|
|
errs = packer.MultiErrorAppend(
|
2019-10-31 18:21:52 -04:00
|
|
|
errs, errors.New("hard_drive_interface can only be ide, sata, pcie or scsi"))
|
2013-09-05 15:07:58 -04:00
|
|
|
}
|
|
|
|
|
2017-03-22 08:09:25 -04:00
|
|
|
if b.config.SATAPortCount == 0 {
|
|
|
|
b.config.SATAPortCount = 1
|
|
|
|
}
|
|
|
|
|
|
|
|
if b.config.SATAPortCount > 30 {
|
|
|
|
errs = packer.MultiErrorAppend(
|
|
|
|
errs, errors.New("sata_port_count cannot be greater than 30"))
|
|
|
|
}
|
|
|
|
|
2019-10-31 18:21:52 -04:00
|
|
|
if b.config.NVMePortCount == 0 {
|
|
|
|
b.config.NVMePortCount = 1
|
|
|
|
}
|
|
|
|
|
|
|
|
if b.config.NVMePortCount > 255 {
|
|
|
|
errs = packer.MultiErrorAppend(
|
|
|
|
errs, errors.New("nvme_port_count cannot be greater than 255"))
|
|
|
|
}
|
|
|
|
|
2014-05-23 21:14:24 -04:00
|
|
|
if b.config.ISOInterface != "ide" && b.config.ISOInterface != "sata" {
|
|
|
|
errs = packer.MultiErrorAppend(
|
|
|
|
errs, errors.New("iso_interface can only be ide or sata"))
|
|
|
|
}
|
|
|
|
|
2013-11-02 04:22:56 -04:00
|
|
|
validMode := false
|
|
|
|
validModes := []string{
|
2014-05-04 11:56:57 -04:00
|
|
|
vboxcommon.GuestAdditionsModeDisable,
|
|
|
|
vboxcommon.GuestAdditionsModeAttach,
|
|
|
|
vboxcommon.GuestAdditionsModeUpload,
|
2013-11-02 04:22:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, mode := range validModes {
|
|
|
|
if b.config.GuestAdditionsMode == mode {
|
|
|
|
validMode = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !validMode {
|
|
|
|
errs = packer.MultiErrorAppend(errs,
|
|
|
|
fmt.Errorf("guest_additions_mode is invalid. Must be one of: %v", validModes))
|
|
|
|
}
|
|
|
|
|
2013-07-06 05:28:56 -04:00
|
|
|
if b.config.GuestAdditionsSHA256 != "" {
|
|
|
|
b.config.GuestAdditionsSHA256 = strings.ToLower(b.config.GuestAdditionsSHA256)
|
|
|
|
}
|
|
|
|
|
2013-11-03 00:17:21 -04:00
|
|
|
// Warnings
|
|
|
|
if b.config.ShutdownCommand == "" {
|
|
|
|
warnings = append(warnings,
|
|
|
|
"A shutdown_command was not specified. Without a shutdown command, Packer\n"+
|
|
|
|
"will forcibly halt the virtual machine, which may result in data loss.")
|
|
|
|
}
|
|
|
|
|
2013-07-19 19:08:25 -04:00
|
|
|
if errs != nil && len(errs.Errors) > 0 {
|
2019-12-17 00:23:05 -05:00
|
|
|
return nil, warnings, errs
|
2013-06-11 18:45:52 -04:00
|
|
|
}
|
|
|
|
|
2019-12-17 00:23:05 -05:00
|
|
|
return nil, warnings, nil
|
2013-06-11 18:12:45 -04:00
|
|
|
}
|
|
|
|
|
2019-03-22 09:53:28 -04:00
|
|
|
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
|
2013-08-13 11:55:33 -04:00
|
|
|
// Create the driver that we'll use to communicate with VirtualBox
|
2013-12-21 18:00:48 -05:00
|
|
|
driver, err := vboxcommon.NewDriver()
|
2013-08-13 11:55:33 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("Failed creating VirtualBox driver: %s", err)
|
|
|
|
}
|
|
|
|
|
2013-06-11 18:45:52 -04:00
|
|
|
steps := []multistep.Step{
|
2014-05-04 11:56:57 -04:00
|
|
|
&vboxcommon.StepDownloadGuestAdditions{
|
|
|
|
GuestAdditionsMode: b.config.GuestAdditionsMode,
|
|
|
|
GuestAdditionsURL: b.config.GuestAdditionsURL,
|
|
|
|
GuestAdditionsSHA256: b.config.GuestAdditionsSHA256,
|
2015-05-27 17:01:08 -04:00
|
|
|
Ctx: b.config.ctx,
|
2014-05-04 11:56:57 -04:00
|
|
|
},
|
2013-08-15 14:05:36 -04:00
|
|
|
&common.StepDownload{
|
|
|
|
Checksum: b.config.ISOChecksum,
|
|
|
|
ChecksumType: b.config.ISOChecksumType,
|
|
|
|
Description: "ISO",
|
2016-12-17 05:49:54 -05:00
|
|
|
Extension: b.config.TargetExtension,
|
2015-10-20 19:27:47 -04:00
|
|
|
ResultKey: "iso_path",
|
2015-07-28 07:45:02 -04:00
|
|
|
TargetPath: b.config.TargetPath,
|
2015-10-20 19:27:47 -04:00
|
|
|
Url: b.config.ISOUrls,
|
2013-08-15 14:05:36 -04:00
|
|
|
},
|
2019-01-11 18:06:36 -05:00
|
|
|
&common.StepOutputDir{
|
2013-12-21 18:20:15 -05:00
|
|
|
Force: b.config.PackerForce,
|
|
|
|
Path: b.config.OutputDir,
|
|
|
|
},
|
2013-07-09 15:29:40 -04:00
|
|
|
&common.StepCreateFloppy{
|
2016-10-01 03:04:50 -04:00
|
|
|
Files: b.config.FloppyConfig.FloppyFiles,
|
|
|
|
Directories: b.config.FloppyConfig.FloppyDirectories,
|
2019-09-12 08:25:22 -04:00
|
|
|
Label: b.config.FloppyConfig.FloppyLabel,
|
2013-07-09 15:29:40 -04:00
|
|
|
},
|
2015-11-01 17:29:24 -05:00
|
|
|
&common.StepHTTPServer{
|
2014-09-05 14:52:55 -04:00
|
|
|
HTTPDir: b.config.HTTPDir,
|
|
|
|
HTTPPortMin: b.config.HTTPPortMin,
|
|
|
|
HTTPPortMax: b.config.HTTPPortMax,
|
|
|
|
},
|
2019-02-03 12:20:52 -05:00
|
|
|
&vboxcommon.StepSshKeyPair{
|
|
|
|
Debug: b.config.PackerDebug,
|
2019-02-04 12:47:18 -05:00
|
|
|
DebugKeyPath: fmt.Sprintf("%s.pem", b.config.PackerBuildName),
|
2019-02-03 12:20:52 -05:00
|
|
|
Comm: &b.config.Comm,
|
|
|
|
},
|
2013-12-21 19:04:41 -05:00
|
|
|
new(vboxcommon.StepSuppressMessages),
|
2013-06-11 19:12:19 -04:00
|
|
|
new(stepCreateVM),
|
2013-06-11 19:34:44 -04:00
|
|
|
new(stepCreateDisk),
|
2013-06-11 23:07:11 -04:00
|
|
|
new(stepAttachISO),
|
2014-05-04 11:56:57 -04:00
|
|
|
&vboxcommon.StepAttachGuestAdditions{
|
2019-02-08 12:15:15 -05:00
|
|
|
GuestAdditionsMode: b.config.GuestAdditionsMode,
|
|
|
|
GuestAdditionsInterface: b.config.GuestAdditionsInterface,
|
2014-05-04 11:56:57 -04:00
|
|
|
},
|
2015-08-22 18:41:08 -04:00
|
|
|
&vboxcommon.StepConfigureVRDP{
|
2016-05-23 09:24:16 -04:00
|
|
|
VRDPBindAddress: b.config.VRDPBindAddress,
|
|
|
|
VRDPPortMin: b.config.VRDPPortMin,
|
|
|
|
VRDPPortMax: b.config.VRDPPortMax,
|
2015-08-22 18:41:08 -04:00
|
|
|
},
|
2013-12-22 11:10:11 -05:00
|
|
|
new(vboxcommon.StepAttachFloppy),
|
2013-12-22 12:08:09 -05:00
|
|
|
&vboxcommon.StepForwardSSH{
|
2015-06-15 00:47:53 -04:00
|
|
|
CommConfig: &b.config.SSHConfig.Comm,
|
2014-03-27 02:11:34 -04:00
|
|
|
HostPortMin: b.config.SSHHostPortMin,
|
|
|
|
HostPortMax: b.config.SSHHostPortMax,
|
|
|
|
SkipNatMapping: b.config.SSHSkipNatMapping,
|
2013-12-22 12:08:09 -05:00
|
|
|
},
|
2013-12-22 12:24:29 -05:00
|
|
|
&vboxcommon.StepVBoxManage{
|
|
|
|
Commands: b.config.VBoxManage,
|
2015-05-27 17:01:08 -04:00
|
|
|
Ctx: b.config.ctx,
|
2013-12-22 12:24:29 -05:00
|
|
|
},
|
2013-12-22 13:30:12 -05:00
|
|
|
&vboxcommon.StepRun{
|
|
|
|
Headless: b.config.Headless,
|
|
|
|
},
|
2014-05-12 22:02:30 -04:00
|
|
|
&vboxcommon.StepTypeBootCommand{
|
2018-08-22 14:25:43 -04:00
|
|
|
BootWait: b.config.BootWait,
|
|
|
|
BootCommand: b.config.FlatBootCommand(),
|
|
|
|
VMName: b.config.VMName,
|
|
|
|
Ctx: b.config.ctx,
|
|
|
|
GroupInterval: b.config.BootConfig.BootGroupInterval,
|
2019-02-03 12:20:52 -05:00
|
|
|
Comm: &b.config.Comm,
|
2014-05-12 22:02:30 -04:00
|
|
|
},
|
2015-06-13 18:08:12 -04:00
|
|
|
&communicator.StepConnect{
|
2015-06-13 19:23:33 -04:00
|
|
|
Config: &b.config.SSHConfig.Comm,
|
2016-08-24 12:30:26 -04:00
|
|
|
Host: vboxcommon.CommHost(b.config.SSHConfig.Comm.SSHHost),
|
2018-08-22 11:02:23 -04:00
|
|
|
SSHConfig: b.config.SSHConfig.Comm.SSHConfigFunc(),
|
2015-06-13 19:23:33 -04:00
|
|
|
SSHPort: vboxcommon.SSHPort,
|
2016-12-23 10:55:10 -05:00
|
|
|
WinRMPort: vboxcommon.SSHPort,
|
2013-07-15 01:17:09 -04:00
|
|
|
},
|
2013-12-22 14:50:29 -05:00
|
|
|
&vboxcommon.StepUploadVersion{
|
2017-03-16 21:04:36 -04:00
|
|
|
Path: *b.config.VBoxVersionFile,
|
2013-12-22 14:50:29 -05:00
|
|
|
},
|
2014-05-04 11:56:57 -04:00
|
|
|
&vboxcommon.StepUploadGuestAdditions{
|
|
|
|
GuestAdditionsMode: b.config.GuestAdditionsMode,
|
|
|
|
GuestAdditionsPath: b.config.GuestAdditionsPath,
|
2015-05-27 17:01:08 -04:00
|
|
|
Ctx: b.config.ctx,
|
2014-05-04 11:56:57 -04:00
|
|
|
},
|
2013-07-16 02:44:41 -04:00
|
|
|
new(common.StepProvision),
|
2018-09-14 14:03:23 -04:00
|
|
|
&common.StepCleanupTempKeys{
|
|
|
|
Comm: &b.config.SSHConfig.Comm,
|
|
|
|
},
|
2013-12-22 12:37:27 -05:00
|
|
|
&vboxcommon.StepShutdown{
|
2019-12-05 08:34:56 -05:00
|
|
|
Command: b.config.ShutdownCommand,
|
|
|
|
Timeout: b.config.ShutdownTimeout,
|
|
|
|
Delay: b.config.PostShutdownDelay,
|
|
|
|
DisableShutdown: b.config.DisableShutdown,
|
2013-12-22 12:37:27 -05:00
|
|
|
},
|
2018-02-26 11:47:59 -05:00
|
|
|
&vboxcommon.StepRemoveDevices{
|
2019-02-08 12:15:15 -05:00
|
|
|
Bundling: b.config.VBoxBundleConfig,
|
|
|
|
GuestAdditionsInterface: b.config.GuestAdditionsInterface,
|
2018-02-26 11:47:59 -05:00
|
|
|
},
|
2014-03-12 19:14:44 -04:00
|
|
|
&vboxcommon.StepVBoxManage{
|
|
|
|
Commands: b.config.VBoxManagePost,
|
2015-05-27 17:01:08 -04:00
|
|
|
Ctx: b.config.ctx,
|
2014-03-12 19:14:44 -04:00
|
|
|
},
|
2013-12-22 13:40:39 -05:00
|
|
|
&vboxcommon.StepExport{
|
2014-03-27 02:11:34 -04:00
|
|
|
Format: b.config.Format,
|
|
|
|
OutputDir: b.config.OutputDir,
|
2019-06-19 10:34:14 -04:00
|
|
|
ExportOpts: b.config.ExportConfig.ExportOpts,
|
2018-02-26 11:47:59 -05:00
|
|
|
Bundling: b.config.VBoxBundleConfig,
|
2014-03-27 02:11:34 -04:00
|
|
|
SkipNatMapping: b.config.SSHSkipNatMapping,
|
2016-12-29 08:19:59 -05:00
|
|
|
SkipExport: b.config.SkipExport,
|
2013-12-22 13:40:39 -05:00
|
|
|
},
|
2013-06-11 18:45:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Setup the state bag
|
2013-08-31 15:44:58 -04:00
|
|
|
state := new(multistep.BasicStateBag)
|
|
|
|
state.Put("config", &b.config)
|
2016-05-17 04:03:45 -04:00
|
|
|
state.Put("debug", b.config.PackerDebug)
|
2013-08-31 15:44:58 -04:00
|
|
|
state.Put("driver", driver)
|
|
|
|
state.Put("hook", hook)
|
|
|
|
state.Put("ui", ui)
|
2013-06-11 18:45:52 -04:00
|
|
|
|
|
|
|
// Run
|
2016-09-13 20:04:18 -04:00
|
|
|
b.runner = common.NewRunnerWithPauseFn(steps, b.config.PackerConfig, ui, state)
|
2019-03-22 09:53:28 -04:00
|
|
|
b.runner.Run(ctx, state)
|
2013-06-11 18:45:52 -04:00
|
|
|
|
2013-06-20 00:07:53 -04:00
|
|
|
// If there was an error, return that
|
2013-08-31 15:44:58 -04:00
|
|
|
if rawErr, ok := state.GetOk("error"); ok {
|
2013-06-20 00:07:53 -04:00
|
|
|
return nil, rawErr.(error)
|
|
|
|
}
|
|
|
|
|
2013-06-27 22:24:53 -04:00
|
|
|
// If we were interrupted or cancelled, then just exit.
|
2013-08-31 15:44:58 -04:00
|
|
|
if _, ok := state.GetOk(multistep.StateCancelled); ok {
|
2013-06-27 22:24:53 -04:00
|
|
|
return nil, errors.New("Build was cancelled.")
|
|
|
|
}
|
|
|
|
|
2013-08-31 15:44:58 -04:00
|
|
|
if _, ok := state.GetOk(multistep.StateHalted); ok {
|
2013-06-27 22:24:53 -04:00
|
|
|
return nil, errors.New("Build was halted.")
|
|
|
|
}
|
|
|
|
|
2013-12-21 17:51:38 -05:00
|
|
|
return vboxcommon.NewArtifact(b.config.OutputDir)
|
2013-06-11 18:12:45 -04:00
|
|
|
}
|