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
|
|
|
|
2019-02-08 12:31:30 -05:00
|
|
|
package ovf
|
2013-12-21 20:38:06 -05:00
|
|
|
|
|
|
|
import (
|
2013-12-22 18:24:24 -05:00
|
|
|
"fmt"
|
2013-12-22 20:02:22 -05:00
|
|
|
|
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"
|
2020-11-11 18:04:28 -05:00
|
|
|
"github.com/hashicorp/packer/common/commonsteps"
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/helper/config"
|
|
|
|
"github.com/hashicorp/packer/packer"
|
2020-11-11 13:21:37 -05:00
|
|
|
"github.com/hashicorp/packer/packer-plugin-sdk/template/interpolate"
|
2013-12-21 20:38:06 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// Config is the configuration structure for the builder.
|
|
|
|
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.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"`
|
2020-01-09 11:37:30 -05:00
|
|
|
vboxcommon.CommConfig `mapstructure:",squash"`
|
2014-03-12 19:14:44 -04:00
|
|
|
vboxcommon.ShutdownConfig `mapstructure:",squash"`
|
|
|
|
vboxcommon.VBoxManageConfig `mapstructure:",squash"`
|
|
|
|
vboxcommon.VBoxVersionConfig `mapstructure:",squash"`
|
2019-03-16 12:15:27 -04:00
|
|
|
vboxcommon.GuestAdditionsConfig `mapstructure:",squash"`
|
2020-05-28 05:02:09 -04:00
|
|
|
// The checksum for the source_path file. The type of the checksum is
|
|
|
|
// specified within the checksum field as a prefix, ex: "md5:{$checksum}".
|
|
|
|
// The type of the checksum can also be omitted and Packer will try to
|
|
|
|
// infer it based on string length. Valid values are "none", "{$checksum}",
|
|
|
|
// "md5:{$checksum}", "sha1:{$checksum}", "sha256:{$checksum}",
|
|
|
|
// "sha512:{$checksum}" or "file:{$path}". Here is a list of valid checksum
|
|
|
|
// values:
|
|
|
|
// * md5:090992ba9fd140077b0661cb75f7ce13
|
|
|
|
// * 090992ba9fd140077b0661cb75f7ce13
|
|
|
|
// * sha1:ebfb681885ddf1234c18094a45bbeafd91467911
|
|
|
|
// * ebfb681885ddf1234c18094a45bbeafd91467911
|
|
|
|
// * sha256:ed363350696a726b7932db864dda019bd2017365c9e299627830f06954643f93
|
|
|
|
// * ed363350696a726b7932db864dda019bd2017365c9e299627830f06954643f93
|
|
|
|
// * file:http://releases.ubuntu.com/20.04/MD5SUMS
|
|
|
|
// * file:file://./local/path/file.sum
|
|
|
|
// * file:./local/path/file.sum
|
|
|
|
// * none
|
|
|
|
// Although the checksum will not be verified when it is set to "none",
|
|
|
|
// this is not recommended since these files can be very large and
|
|
|
|
// corruption does happen from time to time.
|
2019-06-06 10:29:25 -04:00
|
|
|
Checksum string `mapstructure:"checksum" required:"true"`
|
2019-05-28 11:50:58 -04:00
|
|
|
// Additional flags to pass to
|
2019-06-06 10:29:25 -04:00
|
|
|
// VBoxManage import. This can be used to add additional command-line flags
|
|
|
|
// such as --eula-accept to accept a EULA in the OVF.
|
|
|
|
ImportFlags []string `mapstructure:"import_flags" required:"false"`
|
2019-05-28 11:50:58 -04:00
|
|
|
// Additional options to pass to the
|
2019-06-06 10:29:25 -04:00
|
|
|
// VBoxManage import. This can be useful for passing keepallmacs or
|
|
|
|
// keepnatmacs options for existing ovf images.
|
|
|
|
ImportOpts string `mapstructure:"import_opts" required:"false"`
|
2019-12-16 10:50:21 -05:00
|
|
|
// The filepath or URL to an OVF or OVA file that acts as the
|
|
|
|
// source of this build.
|
2019-06-06 10:29:25 -04:00
|
|
|
SourcePath string `mapstructure:"source_path" required:"true"`
|
2019-05-28 11:50:58 -04:00
|
|
|
// The path where the OVA should be saved
|
2019-06-06 10:29:25 -04:00
|
|
|
// after download. By default, it will go in the packer cache, with a hash of
|
|
|
|
// the original filename as its name.
|
|
|
|
TargetPath string `mapstructure:"target_path" required:"false"`
|
2019-05-28 11:50:58 -04:00
|
|
|
// This is the name of the OVF file for the new virtual
|
2019-06-06 10:29:25 -04:00
|
|
|
// machine, without the file extension. By default this is packer-BUILDNAME,
|
|
|
|
// where "BUILDNAME" is the name of the build.
|
|
|
|
VMName string `mapstructure:"vm_name" required:"false"`
|
2019-05-28 11:50:58 -04:00
|
|
|
// Set this to true if you would like to keep
|
2019-06-06 10:29:25 -04:00
|
|
|
// the VM registered with virtualbox. Defaults to false.
|
|
|
|
KeepRegistered bool `mapstructure:"keep_registered" required:"false"`
|
2019-05-28 11:50:58 -04:00
|
|
|
// Defaults to false. When enabled, Packer will
|
2019-06-06 10:29:25 -04:00
|
|
|
// not export the VM. Useful if the build output is not the resultant image,
|
|
|
|
// but created inside the VM.
|
|
|
|
SkipExport bool `mapstructure:"skip_export" required:"false"`
|
2013-12-22 18:19:19 -05:00
|
|
|
|
2015-05-27 17:03:56 -04:00
|
|
|
ctx interpolate.Context
|
2013-12-21 20:38:06 -05:00
|
|
|
}
|
|
|
|
|
2019-12-17 05:25:56 -05:00
|
|
|
func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
|
2015-06-12 17:02:09 -04:00
|
|
|
err := config.Decode(c, &config.DecodeOpts{
|
2020-10-09 20:01:55 -04:00
|
|
|
PluginType: vboxcommon.BuilderId, // "mitchellh.virtualbox"
|
2015-06-22 12:22:42 -04:00
|
|
|
Interpolate: true,
|
|
|
|
InterpolateContext: &c.ctx,
|
2015-05-27 17:03:56 -04:00
|
|
|
InterpolateFilter: &interpolate.RenderFilter{
|
|
|
|
Exclude: []string{
|
|
|
|
"boot_command",
|
|
|
|
"guest_additions_path",
|
|
|
|
"guest_additions_url",
|
|
|
|
"vboxmanage",
|
|
|
|
"vboxmanage_post",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, raws...)
|
2013-12-21 20:38:06 -05:00
|
|
|
if err != nil {
|
2019-12-17 05:25:56 -05:00
|
|
|
return nil, err
|
2013-12-21 20:38:06 -05:00
|
|
|
}
|
|
|
|
|
2013-12-22 18:24:24 -05:00
|
|
|
// Defaults
|
|
|
|
if c.VMName == "" {
|
2015-06-22 12:25:15 -04:00
|
|
|
c.VMName = fmt.Sprintf(
|
|
|
|
"packer-%s-%d", c.PackerBuildName, interpolate.InitTime.Unix())
|
2013-12-22 18:24:24 -05:00
|
|
|
}
|
|
|
|
|
2013-12-21 20:38:06 -05:00
|
|
|
// Prepare the errors
|
2015-05-27 17:03:56 -04:00
|
|
|
var errs *packer.MultiError
|
|
|
|
errs = packer.MultiErrorAppend(errs, c.ExportConfig.Prepare(&c.ctx)...)
|
2019-06-19 10:34:14 -04:00
|
|
|
errs = packer.MultiErrorAppend(errs, c.ExportConfig.Prepare(&c.ctx)...)
|
2015-05-27 17:03:56 -04:00
|
|
|
errs = packer.MultiErrorAppend(errs, c.FloppyConfig.Prepare(&c.ctx)...)
|
2020-09-11 17:15:17 -04:00
|
|
|
errs = packer.MultiErrorAppend(errs, c.CDConfig.Prepare(&c.ctx)...)
|
2015-11-01 17:29:24 -05:00
|
|
|
errs = packer.MultiErrorAppend(errs, c.HTTPConfig.Prepare(&c.ctx)...)
|
2015-05-27 17:03:56 -04:00
|
|
|
errs = packer.MultiErrorAppend(errs, c.OutputConfig.Prepare(&c.ctx, &c.PackerConfig)...)
|
|
|
|
errs = packer.MultiErrorAppend(errs, c.RunConfig.Prepare(&c.ctx)...)
|
|
|
|
errs = packer.MultiErrorAppend(errs, c.ShutdownConfig.Prepare(&c.ctx)...)
|
2020-01-09 11:37:30 -05:00
|
|
|
errs = packer.MultiErrorAppend(errs, c.CommConfig.Prepare(&c.ctx)...)
|
2015-05-27 17:03:56 -04:00
|
|
|
errs = packer.MultiErrorAppend(errs, c.VBoxManageConfig.Prepare(&c.ctx)...)
|
|
|
|
errs = packer.MultiErrorAppend(errs, c.VBoxVersionConfig.Prepare(&c.ctx)...)
|
2018-04-18 19:19:44 -04:00
|
|
|
errs = packer.MultiErrorAppend(errs, c.BootConfig.Prepare(&c.ctx)...)
|
2019-03-16 12:15:27 -04:00
|
|
|
errs = packer.MultiErrorAppend(errs, c.GuestAdditionsConfig.Prepare(&c.ctx)...)
|
2014-09-05 13:23:37 -04:00
|
|
|
|
2013-12-22 20:02:22 -05:00
|
|
|
if c.SourcePath == "" {
|
|
|
|
errs = packer.MultiErrorAppend(errs, fmt.Errorf("source_path is required"))
|
Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 07:11:58 -04:00
|
|
|
}
|
2018-01-03 19:53:47 -05:00
|
|
|
|
2020-09-11 17:15:17 -04:00
|
|
|
if c.GuestAdditionsInterface == "" {
|
|
|
|
c.GuestAdditionsInterface = "ide"
|
2014-05-04 11:56:57 -04:00
|
|
|
}
|
|
|
|
|
2013-12-22 12:37:27 -05:00
|
|
|
// Warnings
|
|
|
|
var warnings []string
|
|
|
|
if c.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-12-21 20:38:06 -05:00
|
|
|
// Check for any errors.
|
|
|
|
if errs != nil && len(errs.Errors) > 0 {
|
2019-12-17 05:25:56 -05:00
|
|
|
return warnings, errs
|
2013-12-21 20:38:06 -05:00
|
|
|
}
|
|
|
|
|
2014-09-05 13:23:37 -04:00
|
|
|
// TODO: Write a packer fix and just remove import_opts
|
|
|
|
if c.ImportOpts != "" {
|
|
|
|
c.ImportFlags = append(c.ImportFlags, "--options", c.ImportOpts)
|
|
|
|
}
|
|
|
|
|
2019-12-17 05:25:56 -05:00
|
|
|
return warnings, nil
|
2013-12-21 20:38:06 -05:00
|
|
|
}
|