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
|
|
|
|
2019-12-17 05:25:56 -05:00
|
|
|
"github.com/hashicorp/hcl/v2/hcldec"
|
2020-12-17 16:29:25 -05:00
|
|
|
"github.com/hashicorp/packer-plugin-sdk/bootcommand"
|
|
|
|
"github.com/hashicorp/packer-plugin-sdk/common"
|
|
|
|
"github.com/hashicorp/packer-plugin-sdk/communicator"
|
|
|
|
"github.com/hashicorp/packer-plugin-sdk/multistep"
|
|
|
|
"github.com/hashicorp/packer-plugin-sdk/multistep/commonsteps"
|
|
|
|
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
|
|
|
|
"github.com/hashicorp/packer-plugin-sdk/template/config"
|
|
|
|
"github.com/hashicorp/packer-plugin-sdk/template/interpolate"
|
2017-04-04 16:39:01 -04:00
|
|
|
vboxcommon "github.com/hashicorp/packer/builder/virtualbox/common"
|
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"`
|
2020-11-11 18:04:28 -05:00
|
|
|
commonsteps.HTTPConfig `mapstructure:",squash"`
|
|
|
|
commonsteps.ISOConfig `mapstructure:",squash"`
|
|
|
|
commonsteps.FloppyConfig `mapstructure:",squash"`
|
|
|
|
commonsteps.CDConfig `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"`
|
2020-01-09 11:37:30 -05:00
|
|
|
vboxcommon.CommConfig `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 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:
|
2020-03-12 10:05:08 -04:00
|
|
|
//
|
2020-08-20 09:43:38 -04:00
|
|
|
// In JSON:
|
2020-03-12 10:05:08 -04:00
|
|
|
// ```json
|
|
|
|
// "vboxmanage": [
|
2019-11-04 08:30:59 -05:00
|
|
|
// [ "modifyvm", "{{.Name}}", "--firmware", "EFI" ],
|
2020-03-12 10:05:08 -04:00
|
|
|
// ]
|
|
|
|
// ```
|
|
|
|
//
|
2020-08-20 09:43:38 -04:00
|
|
|
// In HCL2:
|
|
|
|
// ```hcl
|
|
|
|
// 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{
|
2020-10-09 20:01:55 -04:00
|
|
|
PluginType: vboxcommon.BuilderId, // "mitchellh.virtualbox"
|
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
|
2020-11-19 15:07:02 -05:00
|
|
|
var errs *packersdk.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...)
|
2020-11-19 15:07:02 -05:00
|
|
|
errs = packersdk.MultiErrorAppend(errs, isoErrs...)
|
2015-10-20 19:27:47 -04:00
|
|
|
|
2020-11-19 15:07:02 -05:00
|
|
|
errs = packersdk.MultiErrorAppend(errs, b.config.ExportConfig.Prepare(&b.config.ctx)...)
|
|
|
|
errs = packersdk.MultiErrorAppend(errs, b.config.ExportConfig.Prepare(&b.config.ctx)...)
|
|
|
|
errs = packersdk.MultiErrorAppend(errs, b.config.FloppyConfig.Prepare(&b.config.ctx)...)
|
|
|
|
errs = packersdk.MultiErrorAppend(errs, b.config.CDConfig.Prepare(&b.config.ctx)...)
|
|
|
|
errs = packersdk.MultiErrorAppend(
|
2015-05-27 17:01:08 -04:00
|
|
|
errs, b.config.OutputConfig.Prepare(&b.config.ctx, &b.config.PackerConfig)...)
|
2020-11-20 13:53:16 -05:00
|
|
|
errs = packersdk.MultiErrorAppend(errs, b.config.HTTPConfig.Prepare(&b.config.ctx)...)
|
|
|
|
errs = packersdk.MultiErrorAppend(errs, b.config.RunConfig.Prepare(&b.config.ctx)...)
|
|
|
|
errs = packersdk.MultiErrorAppend(errs, b.config.ShutdownConfig.Prepare(&b.config.ctx)...)
|
|
|
|
errs = packersdk.MultiErrorAppend(errs, b.config.CommConfig.Prepare(&b.config.ctx)...)
|
|
|
|
errs = packersdk.MultiErrorAppend(errs, b.config.HWConfig.Prepare(&b.config.ctx)...)
|
|
|
|
errs = packersdk.MultiErrorAppend(errs, b.config.VBoxBundleConfig.Prepare(&b.config.ctx)...)
|
|
|
|
errs = packersdk.MultiErrorAppend(errs, b.config.VBoxManageConfig.Prepare(&b.config.ctx)...)
|
|
|
|
errs = packersdk.MultiErrorAppend(errs, b.config.VBoxVersionConfig.Prepare(b.config.CommConfig.Comm.Type)...)
|
|
|
|
errs = packersdk.MultiErrorAppend(errs, b.config.BootConfig.Prepare(&b.config.ctx)...)
|
|
|
|
errs = packersdk.MultiErrorAppend(errs, b.config.GuestAdditionsConfig.Prepare(b.config.CommConfig.Comm.Type)...)
|
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-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:
|
2020-11-19 15:07:02 -05:00
|
|
|
errs = packersdk.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 {
|
2020-11-19 15:07:02 -05:00
|
|
|
errs = packersdk.MultiErrorAppend(
|
2017-03-22 08:09:25 -04:00
|
|
|
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 {
|
2020-11-19 15:07:02 -05:00
|
|
|
errs = packersdk.MultiErrorAppend(
|
2019-10-31 18:21:52 -04:00
|
|
|
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" {
|
2020-11-19 15:07:02 -05:00
|
|
|
errs = packersdk.MultiErrorAppend(
|
2014-05-23 21:14:24 -04:00
|
|
|
errs, errors.New("iso_interface can only be ide or sata"))
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-11-19 18:10:00 -05:00
|
|
|
func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook) (packersdk.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
|
|
|
},
|
2020-11-11 18:04:28 -05:00
|
|
|
&commonsteps.StepDownload{
|
2020-05-28 05:02:09 -04:00
|
|
|
Checksum: b.config.ISOChecksum,
|
|
|
|
Description: "ISO",
|
|
|
|
Extension: b.config.TargetExtension,
|
|
|
|
ResultKey: "iso_path",
|
|
|
|
TargetPath: b.config.TargetPath,
|
|
|
|
Url: b.config.ISOUrls,
|
2013-08-15 14:05:36 -04:00
|
|
|
},
|
2020-11-11 18:04:28 -05:00
|
|
|
&commonsteps.StepOutputDir{
|
2013-12-21 18:20:15 -05:00
|
|
|
Force: b.config.PackerForce,
|
|
|
|
Path: b.config.OutputDir,
|
|
|
|
},
|
2020-11-11 18:04:28 -05:00
|
|
|
&commonsteps.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
|
|
|
},
|
2020-11-11 18:04:28 -05:00
|
|
|
&commonsteps.StepCreateCD{
|
2020-09-11 17:15:17 -04:00
|
|
|
Files: b.config.CDConfig.CDFiles,
|
|
|
|
Label: b.config.CDConfig.CDLabel,
|
|
|
|
},
|
2020-02-07 04:38:48 -05:00
|
|
|
new(vboxcommon.StepHTTPIPDiscover),
|
2020-11-11 18:04:28 -05:00
|
|
|
&commonsteps.StepHTTPServer{
|
2014-09-05 14:52:55 -04:00
|
|
|
HTTPDir: b.config.HTTPDir,
|
|
|
|
HTTPPortMin: b.config.HTTPPortMin,
|
|
|
|
HTTPPortMax: b.config.HTTPPortMax,
|
2020-05-27 16:34:24 -04:00
|
|
|
HTTPAddress: b.config.HTTPAddress,
|
2014-09-05 14:52:55 -04:00
|
|
|
},
|
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),
|
2020-09-11 17:15:17 -04:00
|
|
|
&vboxcommon.StepAttachISOs{
|
2020-09-14 13:40:07 -04:00
|
|
|
AttachBootISO: true,
|
2020-09-11 17:15:17 -04:00
|
|
|
ISOInterface: b.config.ISOInterface,
|
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),
|
2020-01-09 11:37:30 -05:00
|
|
|
&vboxcommon.StepPortForwarding{
|
|
|
|
CommConfig: &b.config.CommConfig.Comm,
|
|
|
|
HostPortMin: b.config.HostPortMin,
|
|
|
|
HostPortMax: b.config.HostPortMax,
|
|
|
|
SkipNatMapping: b.config.SkipNatMapping,
|
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{
|
2020-01-09 11:37:30 -05:00
|
|
|
Config: &b.config.CommConfig.Comm,
|
|
|
|
Host: vboxcommon.CommHost(b.config.CommConfig.Comm.SSHHost),
|
|
|
|
SSHConfig: b.config.CommConfig.Comm.SSHConfigFunc(),
|
|
|
|
SSHPort: vboxcommon.CommPort,
|
|
|
|
WinRMPort: vboxcommon.CommPort,
|
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
|
|
|
},
|
2020-11-11 18:04:28 -05:00
|
|
|
new(commonsteps.StepProvision),
|
|
|
|
&commonsteps.StepCleanupTempKeys{
|
2020-01-09 11:37:30 -05:00
|
|
|
Comm: &b.config.CommConfig.Comm,
|
2018-09-14 14:03:23 -04:00
|
|
|
},
|
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,
|
2020-01-09 11:36:19 -05:00
|
|
|
ACPIShutdown: b.config.ACPIShutdown,
|
2013-12-22 12:37:27 -05:00
|
|
|
},
|
2018-02-26 11:47:59 -05:00
|
|
|
&vboxcommon.StepRemoveDevices{
|
2020-09-11 17:15:17 -04:00
|
|
|
Bundling: b.config.VBoxBundleConfig,
|
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,
|
2020-05-05 19:09:05 -04:00
|
|
|
OutputFilename: b.config.OutputFilename,
|
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,
|
2020-01-09 11:37:30 -05:00
|
|
|
SkipNatMapping: b.config.SkipNatMapping,
|
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
|
2020-11-11 18:04:28 -05:00
|
|
|
b.runner = commonsteps.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.")
|
|
|
|
}
|
|
|
|
|
2020-01-30 05:27:58 -05:00
|
|
|
generatedData := map[string]interface{}{"generated_data": state.Get("generated_data")}
|
|
|
|
return vboxcommon.NewArtifact(b.config.OutputDir, generatedData)
|
2013-06-11 18:12:45 -04:00
|
|
|
}
|