Merge pull request #9260 from hashicorp/fix_9256

make package_include match output_vagrantfile parsing and abspath cal…
This commit is contained in:
Megan Marsh 2020-05-29 10:41:26 -07:00 committed by GitHub
commit 184dc6cc44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 6 deletions

View File

@ -138,9 +138,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
}
@ -192,7 +195,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))
}
}
@ -201,11 +204,22 @@ 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))
}
}
if len(b.config.PackageInclude) > 0 {
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))
}
b.config.PackageInclude[i] = inclFile
}
}
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

View File

@ -83,4 +83,7 @@
package your base box into its own standalone .box file.
- `output_vagrantfile` (string) - Output Vagrantfile
- `package_include` ([]string) - Package Include
- `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