From a892d13d563fa0335fdb80e302ed564d1979dd26 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Tue, 19 May 2020 16:32:54 -0700 Subject: [PATCH 1/5] make package_include match output_vagrantfile parsing and abspath calculation --- builder/vagrant/builder.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/builder/vagrant/builder.go b/builder/vagrant/builder.go index ac156a38f..33fa878d4 100644 --- a/builder/vagrant/builder.go +++ b/builder/vagrant/builder.go @@ -125,9 +125,12 @@ type Config struct { 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. - SkipPackage bool `mapstructure:"skip_package" required:"false"` - OutputVagrantfile string `mapstructure:"output_vagrantfile"` - PackageInclude []string `mapstructure:"package_include"` + 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"` ctx interpolate.Context } @@ -193,6 +196,19 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) { } } + if len(b.config.PackageInclude) > 0 { + include := []string{} + for i, inclFile := range b.config.PackageInclude { + b.config.PackageInclude, err = filepath.Abs(b.config.PackageInclude) + if err != nil { + packer.MultiErrorAppend(errs, + fmt.Errorf("unable to determine absolute path for file to be included: %s", inclFile)) + } + include = append(include, inclFile) + } + b.config.PackageInclude = include + } + if b.config.TeardownMethod == "" { // 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 From aadd95497a687068acab3ef95953427acd4d6a3f Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Tue, 19 May 2020 16:39:17 -0700 Subject: [PATCH 2/5] fix tests --- builder/vagrant/builder.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/builder/vagrant/builder.go b/builder/vagrant/builder.go index 33fa878d4..fa968b7a9 100644 --- a/builder/vagrant/builder.go +++ b/builder/vagrant/builder.go @@ -198,11 +198,11 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) { if len(b.config.PackageInclude) > 0 { include := []string{} - for i, inclFile := range b.config.PackageInclude { - b.config.PackageInclude, err = filepath.Abs(b.config.PackageInclude) + for _, rawFile := range b.config.PackageInclude { + inclFile, err := filepath.Abs(rawFile) if err != nil { packer.MultiErrorAppend(errs, - fmt.Errorf("unable to determine absolute path for file to be included: %s", inclFile)) + fmt.Errorf("unable to determine absolute path for file to be included: %s", rawFile)) } include = append(include, inclFile) } From 266bba279b27b93f903345071f45489d71050c25 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Tue, 19 May 2020 16:45:14 -0700 Subject: [PATCH 3/5] linting --- builder/vagrant/builder.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/builder/vagrant/builder.go b/builder/vagrant/builder.go index fa968b7a9..b72b3a39d 100644 --- a/builder/vagrant/builder.go +++ b/builder/vagrant/builder.go @@ -182,7 +182,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) { } if strings.HasSuffix(b.config.SourceBox, ".box") { if _, err := os.Stat(b.config.SourceBox); err != nil { - packer.MultiErrorAppend(errs, + errs = packer.MultiErrorAppend(errs, fmt.Errorf("Source box '%s' needs to exist at time of config validation! %v", b.config.SourceBox, err)) } } @@ -191,7 +191,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) { if b.config.OutputVagrantfile != "" { b.config.OutputVagrantfile, err = filepath.Abs(b.config.OutputVagrantfile) if err != nil { - packer.MultiErrorAppend(errs, + errs = packer.MultiErrorAppend(errs, fmt.Errorf("unable to determine absolute path for output vagrantfile: %s", err)) } } @@ -201,7 +201,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) { for _, rawFile := range b.config.PackageInclude { inclFile, err := filepath.Abs(rawFile) if err != nil { - packer.MultiErrorAppend(errs, + errs = packer.MultiErrorAppend(errs, fmt.Errorf("unable to determine absolute path for file to be included: %s", rawFile)) } include = append(include, inclFile) From a568ffce0a9673808db05c573dfe2a1df28ee172 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Tue, 19 May 2020 16:54:03 -0700 Subject: [PATCH 4/5] generated --- .../pages/partials/builder/vagrant/Config-not-required.mdx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/website/pages/partials/builder/vagrant/Config-not-required.mdx b/website/pages/partials/builder/vagrant/Config-not-required.mdx index 9b7842cc1..908db0d3a 100644 --- a/website/pages/partials/builder/vagrant/Config-not-required.mdx +++ b/website/pages/partials/builder/vagrant/Config-not-required.mdx @@ -70,4 +70,7 @@ package your base box into its own standalone .box file. - `output_vagrantfile` (string) - Output Vagrantfile -- `package_include` ([]string) - Package Include \ No newline at end of file +- `package_include` ([]string) - Equivalent to setting the + [`--include`](https://www.vagrantup.com/docs/cli/package.html#include-x-y-z) option + in `vagrant package`; defaults to unset + \ No newline at end of file From 03b2c4355ed25fe8eba4a71483941473b0609dca Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Thu, 28 May 2020 16:46:33 -0700 Subject: [PATCH 5/5] include Wilken's suggestion --- builder/vagrant/builder.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/builder/vagrant/builder.go b/builder/vagrant/builder.go index b72b3a39d..c2ea099ac 100644 --- a/builder/vagrant/builder.go +++ b/builder/vagrant/builder.go @@ -197,16 +197,14 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) { } if len(b.config.PackageInclude) > 0 { - include := []string{} - for _, rawFile := range b.config.PackageInclude { + for i, rawFile := range b.config.PackageInclude { inclFile, err := filepath.Abs(rawFile) if err != nil { errs = packer.MultiErrorAppend(errs, fmt.Errorf("unable to determine absolute path for file to be included: %s", rawFile)) } - include = append(include, inclFile) + b.config.PackageInclude[i] = inclFile } - b.config.PackageInclude = include } if b.config.TeardownMethod == "" {