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-01-11 17:06:15 -05:00
|
|
|
package vagrant
|
|
|
|
|
|
|
|
import (
|
2019-03-22 09:53:28 -04:00
|
|
|
"context"
|
2019-01-11 17:06:15 -05:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
2020-07-29 04:26:09 -04:00
|
|
|
"net/url"
|
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
|
|
|
"os"
|
2019-02-07 17:35:01 -05:00
|
|
|
"path/filepath"
|
2019-01-11 17:06:15 -05:00
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
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"
|
2019-01-11 17:06:15 -05:00
|
|
|
)
|
|
|
|
|
2020-12-01 16:42:11 -05:00
|
|
|
// Builder implements packersdk.Builder and builds the actual VirtualBox
|
2019-01-11 17:06:15 -05:00
|
|
|
// images.
|
|
|
|
type Builder struct {
|
2019-12-17 05:25:56 -05:00
|
|
|
config Config
|
2019-01-11 17:06:15 -05:00
|
|
|
runner multistep.Runner
|
|
|
|
}
|
|
|
|
|
|
|
|
type Config struct {
|
2020-11-11 18:04:28 -05:00
|
|
|
common.PackerConfig `mapstructure:",squash"`
|
|
|
|
commonsteps.HTTPConfig `mapstructure:",squash"`
|
|
|
|
commonsteps.ISOConfig `mapstructure:",squash"`
|
|
|
|
commonsteps.FloppyConfig `mapstructure:",squash"`
|
|
|
|
bootcommand.BootConfig `mapstructure:",squash"`
|
2019-10-14 10:12:09 -04:00
|
|
|
|
|
|
|
Comm communicator.Config `mapstructure:",squash"`
|
2019-06-05 10:46:33 -04:00
|
|
|
// The directory to create that will contain your output box. We always
|
|
|
|
// create this directory and run from inside of it to prevent Vagrant init
|
|
|
|
// collisions. If unset, it will be set to packer- plus your buildname.
|
2019-05-28 11:50:58 -04:00
|
|
|
OutputDir string `mapstructure:"output_dir" required:"false"`
|
2019-06-05 10:46:33 -04:00
|
|
|
// URL of the vagrant box to use, or the name of the vagrant box.
|
|
|
|
// hashicorp/precise64, ./mylocalbox.box and https://example.com/my-box.box
|
|
|
|
// are all valid source boxes. If your source is a .box file, whether
|
|
|
|
// locally or from a URL like the latter example above, you will also need
|
|
|
|
// to provide a box_name. This option is required, unless you set
|
|
|
|
// global_id. You may only set one or the other, not both.
|
2019-05-28 11:50:58 -04:00
|
|
|
SourceBox string `mapstructure:"source_path" required:"true"`
|
2019-06-05 10:46:33 -04:00
|
|
|
// the global id of a Vagrant box already added to Vagrant on your system.
|
|
|
|
// You can find the global id of your Vagrant boxes using the command
|
|
|
|
// vagrant global-status; your global_id will be a 7-digit number and
|
2019-05-28 11:50:58 -04:00
|
|
|
// letter comination that you'll find in the leftmost column of the
|
|
|
|
// global-status output. If you choose to use global_id instead of
|
|
|
|
// source_box, Packer will skip the Vagrant initialize and add steps, and
|
|
|
|
// simply launch the box directly using the global id.
|
|
|
|
GlobalID string `mapstructure:"global_id" required:"true"`
|
2019-06-05 10:46:33 -04:00
|
|
|
// The checksum for the .box file. The type of the checksum is specified
|
2020-05-28 05:02:09 -04:00
|
|
|
// 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
|
2021-01-05 14:02:17 -05:00
|
|
|
// * file:http://releases.ubuntu.com/20.04/SHA256SUMS
|
2020-05-28 05:02:09 -04:00
|
|
|
// * 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-05-28 11:50:58 -04:00
|
|
|
Checksum string `mapstructure:"checksum" required:"false"`
|
2019-06-05 10:46:33 -04:00
|
|
|
// if your source_box is a boxfile that we need to add to Vagrant, this is
|
|
|
|
// the name to give it. If left blank, will default to "packer_" plus your
|
|
|
|
// buildname.
|
2019-05-28 11:50:58 -04:00
|
|
|
BoxName string `mapstructure:"box_name" required:"false"`
|
2019-10-30 16:27:34 -04:00
|
|
|
// If true, Vagrant will automatically insert a keypair to use for SSH,
|
|
|
|
// replacing Vagrant's default insecure key inside the machine if detected.
|
|
|
|
// By default, Packer sets this to false.
|
|
|
|
InsertKey bool `mapstructure:"insert_key" required:"false"`
|
2019-05-28 11:50:58 -04:00
|
|
|
// The vagrant provider.
|
|
|
|
// This parameter is required when source_path have more than one provider,
|
|
|
|
// or when using vagrant-cloud post-processor. Defaults to unset.
|
|
|
|
Provider string `mapstructure:"provider" required:"false"`
|
2019-01-11 17:06:15 -05:00
|
|
|
// Options for the "vagrant init" command
|
|
|
|
|
2019-05-28 11:50:58 -04:00
|
|
|
// What vagrantfile to use
|
|
|
|
VagrantfileTpl string `mapstructure:"vagrantfile_template"`
|
2019-06-05 10:46:33 -04:00
|
|
|
// Whether to halt, suspend, or destroy the box when the build has
|
|
|
|
// completed. Defaults to "halt"
|
2019-05-28 11:50:58 -04:00
|
|
|
TeardownMethod string `mapstructure:"teardown_method" required:"false"`
|
|
|
|
// What box version to use when initializing Vagrant.
|
|
|
|
BoxVersion string `mapstructure:"box_version" required:"false"`
|
2019-06-05 10:46:33 -04:00
|
|
|
// a path to a golang template for a vagrantfile. Our default template can
|
2019-10-30 16:36:56 -04:00
|
|
|
// be found here. The template variables available to you are
|
2020-03-23 20:02:12 -04:00
|
|
|
// `{{ .BoxName }}`, `{{ .SyncedFolder }}`, and `{{.InsertKey}}`, which
|
2019-10-30 16:36:56 -04:00
|
|
|
// correspond to the Packer options box_name, synced_folder, and insert_key.
|
2019-05-28 11:50:58 -04:00
|
|
|
Template string `mapstructure:"template" required:"false"`
|
2020-07-14 18:47:55 -04:00
|
|
|
// Path to the folder to be synced to the guest. The path can be absolute
|
|
|
|
// or relative to the directory Packer is being run from.
|
2019-05-28 11:50:58 -04:00
|
|
|
SyncedFolder string `mapstructure:"synced_folder"`
|
2019-06-05 10:46:33 -04:00
|
|
|
// Don't call "vagrant add" to add the box to your local environment; this
|
|
|
|
// is necessary if you want to launch a box that is already added to your
|
|
|
|
// vagrant environment.
|
2019-05-28 11:50:58 -04:00
|
|
|
SkipAdd bool `mapstructure:"skip_add" required:"false"`
|
|
|
|
// Equivalent to setting the
|
|
|
|
// --cacert
|
|
|
|
// option in vagrant add; defaults to unset.
|
|
|
|
AddCACert string `mapstructure:"add_cacert" required:"false"`
|
|
|
|
// Equivalent to setting the
|
|
|
|
// --capath option
|
|
|
|
// in vagrant add; defaults to unset.
|
|
|
|
AddCAPath string `mapstructure:"add_capath" required:"false"`
|
|
|
|
// Equivalent to setting the
|
|
|
|
// --cert option in
|
|
|
|
// vagrant add; defaults to unset.
|
|
|
|
AddCert string `mapstructure:"add_cert" required:"false"`
|
|
|
|
// Equivalent to setting the
|
|
|
|
// --clean flag in
|
|
|
|
// vagrant add; defaults to unset.
|
|
|
|
AddClean bool `mapstructure:"add_clean" required:"false"`
|
|
|
|
// Equivalent to setting the
|
|
|
|
// --force flag in
|
|
|
|
// vagrant add; defaults to unset.
|
|
|
|
AddForce bool `mapstructure:"add_force" required:"false"`
|
|
|
|
// Equivalent to setting the
|
|
|
|
// --insecure flag in
|
|
|
|
// vagrant add; defaults to unset.
|
|
|
|
AddInsecure bool `mapstructure:"add_insecure" required:"false"`
|
|
|
|
// if true, Packer will not call vagrant package to
|
|
|
|
// package your base box into its own standalone .box file.
|
2020-05-19 19:32:54 -04:00
|
|
|
SkipPackage bool `mapstructure:"skip_package" required:"false"`
|
|
|
|
OutputVagrantfile string `mapstructure:"output_vagrantfile"`
|
|
|
|
// Equivalent to setting the
|
|
|
|
// [`--include`](https://www.vagrantup.com/docs/cli/package.html#include-x-y-z) option
|
|
|
|
// in `vagrant package`; defaults to unset
|
|
|
|
PackageInclude []string `mapstructure:"package_include"`
|
2019-01-11 17:06:15 -05:00
|
|
|
|
|
|
|
ctx interpolate.Context
|
|
|
|
}
|
|
|
|
|
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) {
|
2019-01-11 17:06:15 -05:00
|
|
|
err := config.Decode(&b.config, &config.DecodeOpts{
|
2020-10-09 20:01:55 -04:00
|
|
|
PluginType: BuilderId,
|
2019-01-11 17:06:15 -05:00
|
|
|
Interpolate: true,
|
|
|
|
InterpolateContext: &b.config.ctx,
|
|
|
|
InterpolateFilter: &interpolate.RenderFilter{
|
|
|
|
Exclude: []string{
|
|
|
|
"boot_command",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, raws...)
|
|
|
|
if err != nil {
|
2019-12-17 00:23:05 -05:00
|
|
|
return nil, nil, err
|
2019-01-11 17:06:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Accumulate any errors and warnings
|
2020-11-19 15:07:02 -05:00
|
|
|
var errs *packersdk.MultiError
|
2019-01-11 17:06:15 -05:00
|
|
|
warnings := make([]string, 0)
|
|
|
|
|
|
|
|
if b.config.OutputDir == "" {
|
|
|
|
b.config.OutputDir = fmt.Sprintf("output-%s", b.config.PackerBuildName)
|
|
|
|
}
|
|
|
|
|
|
|
|
if b.config.Comm.SSHTimeout == 0 {
|
|
|
|
b.config.Comm.SSHTimeout = 10 * time.Minute
|
|
|
|
}
|
|
|
|
|
|
|
|
if b.config.Comm.Type != "ssh" {
|
2020-11-19 15:07:02 -05:00
|
|
|
errs = packersdk.MultiErrorAppend(errs,
|
2019-01-11 17:06:15 -05:00
|
|
|
fmt.Errorf(`The Vagrant builder currently only supports the ssh communicator"`))
|
|
|
|
}
|
2019-01-24 19:56:57 -05:00
|
|
|
// The box isn't a namespace like you'd pull from vagrant cloud
|
|
|
|
if b.config.BoxName == "" {
|
|
|
|
b.config.BoxName = fmt.Sprintf("packer_%s", b.config.PackerBuildName)
|
|
|
|
}
|
|
|
|
|
|
|
|
if b.config.SourceBox == "" {
|
2019-01-25 15:32:44 -05:00
|
|
|
if b.config.GlobalID == "" {
|
2020-11-19 15:07:02 -05:00
|
|
|
errs = packersdk.MultiErrorAppend(errs, fmt.Errorf("source_path is required unless you have set global_id"))
|
2019-01-25 15:32:44 -05:00
|
|
|
}
|
2019-01-24 19:56:57 -05:00
|
|
|
} else {
|
2019-01-25 15:32:44 -05:00
|
|
|
if b.config.GlobalID != "" {
|
2020-11-19 15:07:02 -05:00
|
|
|
errs = packersdk.MultiErrorAppend(errs, fmt.Errorf("You may either set global_id or source_path but not both"))
|
2019-01-25 15:32:44 -05:00
|
|
|
}
|
2020-07-29 04:26:09 -04:00
|
|
|
// We're about to open up an actual boxfile. If the file is local to the
|
|
|
|
// filesystem, let's make sure it exists before we get too far into the
|
|
|
|
// build.
|
2019-01-25 15:32:44 -05:00
|
|
|
if strings.HasSuffix(b.config.SourceBox, ".box") {
|
2020-07-29 04:26:09 -04:00
|
|
|
// If scheme is "file" or empty, then we need to check the
|
|
|
|
// filesystem to make sure the box is present locally.
|
|
|
|
u, err := url.Parse(b.config.SourceBox)
|
|
|
|
if err == nil && (u.Scheme == "" || u.Scheme == "file") {
|
|
|
|
if _, err := os.Stat(b.config.SourceBox); err != nil {
|
2020-11-19 15:07:02 -05:00
|
|
|
errs = packersdk.MultiErrorAppend(errs,
|
2020-07-29 04:26:09 -04:00
|
|
|
fmt.Errorf("Source box '%s' needs to exist at time of"+
|
|
|
|
" config validation! %v", b.config.SourceBox, err))
|
|
|
|
}
|
2019-01-24 19:56:57 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-11 17:06:15 -05:00
|
|
|
|
2019-11-04 18:15:37 -05:00
|
|
|
if b.config.OutputVagrantfile != "" {
|
|
|
|
b.config.OutputVagrantfile, err = filepath.Abs(b.config.OutputVagrantfile)
|
|
|
|
if err != nil {
|
2020-11-19 15:07:02 -05:00
|
|
|
errs = packersdk.MultiErrorAppend(errs,
|
2019-11-04 18:15:37 -05:00
|
|
|
fmt.Errorf("unable to determine absolute path for output vagrantfile: %s", err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-19 19:32:54 -04:00
|
|
|
if len(b.config.PackageInclude) > 0 {
|
2020-05-28 19:46:33 -04:00
|
|
|
for i, rawFile := range b.config.PackageInclude {
|
2020-05-19 19:39:17 -04:00
|
|
|
inclFile, err := filepath.Abs(rawFile)
|
2020-05-19 19:32:54 -04:00
|
|
|
if err != nil {
|
2020-11-19 15:07:02 -05:00
|
|
|
errs = packersdk.MultiErrorAppend(errs,
|
2020-05-19 19:39:17 -04:00
|
|
|
fmt.Errorf("unable to determine absolute path for file to be included: %s", rawFile))
|
2020-05-19 19:32:54 -04:00
|
|
|
}
|
2020-05-28 19:46:33 -04:00
|
|
|
b.config.PackageInclude[i] = inclFile
|
2020-05-19 19:32:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-11 17:06:15 -05:00
|
|
|
if b.config.TeardownMethod == "" {
|
2019-01-25 15:32:44 -05:00
|
|
|
// If we're using a box that's already opened on the system, don't
|
|
|
|
// automatically destroy it. If we open the box ourselves, then go ahead
|
|
|
|
// and kill it by default.
|
|
|
|
if b.config.GlobalID != "" {
|
|
|
|
b.config.TeardownMethod = "halt"
|
|
|
|
} else {
|
|
|
|
b.config.TeardownMethod = "destroy"
|
|
|
|
}
|
2019-01-11 17:06:15 -05:00
|
|
|
} else {
|
|
|
|
matches := false
|
|
|
|
for _, name := range []string{"halt", "suspend", "destroy"} {
|
|
|
|
if strings.ToLower(b.config.TeardownMethod) == name {
|
|
|
|
matches = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !matches {
|
2020-11-19 15:07:02 -05:00
|
|
|
errs = packersdk.MultiErrorAppend(errs,
|
2019-01-11 17:06:15 -05:00
|
|
|
fmt.Errorf(`TeardownMethod must be "halt", "suspend", or "destroy"`))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-14 18:47:55 -04:00
|
|
|
if b.config.SyncedFolder != "" {
|
|
|
|
b.config.SyncedFolder, err = filepath.Abs(b.config.SyncedFolder)
|
|
|
|
if err != nil {
|
2020-11-19 15:07:02 -05:00
|
|
|
errs = packersdk.MultiErrorAppend(errs,
|
2020-07-14 18:47:55 -04:00
|
|
|
fmt.Errorf("unable to determine absolute path for synced_folder: %s", b.config.SyncedFolder))
|
|
|
|
}
|
|
|
|
if _, err := os.Stat(b.config.SyncedFolder); err != nil {
|
2020-11-19 15:07:02 -05:00
|
|
|
errs = packersdk.MultiErrorAppend(errs,
|
2020-07-14 18:47:55 -04:00
|
|
|
fmt.Errorf("synced_folder \"%s\" does not exist on the Packer host.", b.config.SyncedFolder))
|
|
|
|
}
|
2020-07-14 14:34:40 -04:00
|
|
|
}
|
|
|
|
|
2019-01-11 17:06:15 -05:00
|
|
|
if errs != nil && len(errs.Errors) > 0 {
|
2019-12-17 00:23:05 -05:00
|
|
|
return nil, warnings, errs
|
2019-01-11 17:06:15 -05:00
|
|
|
}
|
|
|
|
|
2019-12-17 00:23:05 -05:00
|
|
|
return nil, warnings, nil
|
2019-01-11 17:06:15 -05:00
|
|
|
}
|
|
|
|
|
2020-11-19 15:17:11 -05:00
|
|
|
// Run executes a Packer build and returns a packersdk.Artifact representing
|
2019-01-11 17:06:15 -05:00
|
|
|
// a VirtualBox appliance.
|
2020-11-19 18:10:00 -05:00
|
|
|
func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook) (packersdk.Artifact, error) {
|
2019-01-11 17:06:15 -05:00
|
|
|
// Create the driver that we'll use to communicate with VirtualBox
|
2019-02-07 17:35:01 -05:00
|
|
|
VagrantCWD, err := filepath.Abs(b.config.OutputDir)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
driver, err := NewDriver(VagrantCWD)
|
2019-01-11 17:06:15 -05:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("Failed creating VirtualBox driver: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set up the state.
|
|
|
|
state := new(multistep.BasicStateBag)
|
2019-12-19 11:01:55 -05:00
|
|
|
state.Put("config", &b.config)
|
2019-01-11 17:06:15 -05:00
|
|
|
state.Put("debug", b.config.PackerDebug)
|
|
|
|
state.Put("driver", driver)
|
|
|
|
state.Put("hook", hook)
|
|
|
|
state.Put("ui", ui)
|
|
|
|
|
|
|
|
// Build the steps.
|
|
|
|
steps := []multistep.Step{}
|
2019-01-24 19:56:57 -05:00
|
|
|
// Download if source box isn't from vagrant cloud.
|
2019-01-25 15:32:44 -05:00
|
|
|
if strings.HasSuffix(b.config.SourceBox, ".box") {
|
2020-11-11 18:04:28 -05:00
|
|
|
steps = append(steps, &commonsteps.StepDownload{
|
2020-05-28 05:02:09 -04:00
|
|
|
Checksum: b.config.Checksum,
|
|
|
|
Description: "Box",
|
|
|
|
Extension: "box",
|
|
|
|
ResultKey: "box_path",
|
|
|
|
Url: []string{b.config.SourceBox},
|
2019-01-24 19:56:57 -05:00
|
|
|
})
|
2019-01-11 17:06:15 -05:00
|
|
|
}
|
|
|
|
steps = append(steps,
|
2020-11-11 18:04:28 -05:00
|
|
|
&commonsteps.StepOutputDir{
|
2019-01-24 19:56:57 -05:00
|
|
|
Force: b.config.PackerForce,
|
|
|
|
Path: b.config.OutputDir,
|
|
|
|
},
|
2019-02-07 15:39:56 -05:00
|
|
|
&StepCreateVagrantfile{
|
|
|
|
Template: b.config.Template,
|
|
|
|
SyncedFolder: b.config.SyncedFolder,
|
|
|
|
SourceBox: b.config.SourceBox,
|
2019-07-09 18:26:04 -04:00
|
|
|
BoxName: b.config.BoxName,
|
2019-02-07 15:39:56 -05:00
|
|
|
OutputDir: b.config.OutputDir,
|
|
|
|
GlobalID: b.config.GlobalID,
|
2019-10-30 16:27:34 -04:00
|
|
|
InsertKey: b.config.InsertKey,
|
2019-01-11 17:06:15 -05:00
|
|
|
},
|
|
|
|
&StepAddBox{
|
|
|
|
BoxVersion: b.config.BoxVersion,
|
|
|
|
CACert: b.config.AddCACert,
|
|
|
|
CAPath: b.config.AddCAPath,
|
|
|
|
DownloadCert: b.config.AddCert,
|
|
|
|
Clean: b.config.AddClean,
|
|
|
|
Force: b.config.AddForce,
|
|
|
|
Insecure: b.config.AddInsecure,
|
|
|
|
Provider: b.config.Provider,
|
|
|
|
SourceBox: b.config.SourceBox,
|
2019-01-24 19:56:57 -05:00
|
|
|
BoxName: b.config.BoxName,
|
2019-01-25 15:32:44 -05:00
|
|
|
GlobalID: b.config.GlobalID,
|
2019-02-14 17:46:14 -05:00
|
|
|
SkipAdd: b.config.SkipAdd,
|
2019-01-11 17:06:15 -05:00
|
|
|
},
|
|
|
|
&StepUp{
|
2019-01-25 15:32:44 -05:00
|
|
|
TeardownMethod: b.config.TeardownMethod,
|
|
|
|
Provider: b.config.Provider,
|
|
|
|
GlobalID: b.config.GlobalID,
|
|
|
|
},
|
|
|
|
&StepSSHConfig{
|
|
|
|
b.config.GlobalID,
|
2019-01-11 17:06:15 -05:00
|
|
|
},
|
|
|
|
&communicator.StepConnect{
|
2019-10-14 10:12:09 -04:00
|
|
|
Config: &b.config.Comm,
|
2019-01-11 17:06:15 -05:00
|
|
|
Host: CommHost(),
|
2019-10-14 10:12:09 -04:00
|
|
|
SSHConfig: b.config.Comm.SSHConfigFunc(),
|
2019-01-11 17:06:15 -05:00
|
|
|
},
|
2020-11-11 18:04:28 -05:00
|
|
|
new(commonsteps.StepProvision),
|
2019-01-11 17:06:15 -05:00
|
|
|
&StepPackage{
|
|
|
|
SkipPackage: b.config.SkipPackage,
|
|
|
|
Include: b.config.PackageInclude,
|
|
|
|
Vagrantfile: b.config.OutputVagrantfile,
|
2019-01-25 15:32:44 -05:00
|
|
|
GlobalID: b.config.GlobalID,
|
2019-01-11 17:06:15 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
// Run the steps.
|
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)
|
2019-01-11 17:06:15 -05:00
|
|
|
|
|
|
|
// Report any errors.
|
|
|
|
if rawErr, ok := state.GetOk("error"); ok {
|
|
|
|
return nil, rawErr.(error)
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we were interrupted or cancelled, then just exit.
|
|
|
|
if _, ok := state.GetOk(multistep.StateCancelled); ok {
|
|
|
|
return nil, errors.New("Build was cancelled.")
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, ok := state.GetOk(multistep.StateHalted); ok {
|
|
|
|
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 NewArtifact(b.config.Provider, b.config.OutputDir, generatedData), nil
|
2019-01-11 17:06:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Cancel.
|