2019-01-11 17:06:15 -05:00
|
|
|
package vagrant
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"strings"
|
|
|
|
|
2020-12-17 16:29:25 -05:00
|
|
|
"github.com/hashicorp/packer-plugin-sdk/multistep"
|
|
|
|
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
|
2019-01-11 17:06:15 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type StepPackage struct {
|
|
|
|
SkipPackage bool
|
|
|
|
Include []string
|
|
|
|
Vagrantfile string
|
2019-01-25 15:32:44 -05:00
|
|
|
GlobalID string
|
2019-01-11 17:06:15 -05:00
|
|
|
}
|
|
|
|
|
2019-03-29 11:50:02 -04:00
|
|
|
func (s *StepPackage) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
2019-01-11 17:06:15 -05:00
|
|
|
driver := state.Get("driver").(VagrantDriver)
|
2020-11-19 14:54:31 -05:00
|
|
|
ui := state.Get("ui").(packersdk.Ui)
|
2019-01-11 17:06:15 -05:00
|
|
|
|
|
|
|
if s.SkipPackage {
|
|
|
|
ui.Say("skip_package flag set; not going to call Vagrant package on this box.")
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
ui.Say("Packaging box...")
|
|
|
|
packageArgs := []string{}
|
2019-09-18 16:15:49 -04:00
|
|
|
box := "source"
|
2019-01-25 15:32:44 -05:00
|
|
|
if s.GlobalID != "" {
|
2019-09-18 16:15:49 -04:00
|
|
|
box = s.GlobalID
|
2019-01-25 15:32:44 -05:00
|
|
|
}
|
|
|
|
|
2019-09-18 16:15:49 -04:00
|
|
|
packageArgs = append(packageArgs, box)
|
|
|
|
|
2019-01-11 17:06:15 -05:00
|
|
|
if len(s.Include) > 0 {
|
|
|
|
packageArgs = append(packageArgs, "--include", strings.Join(s.Include, ","))
|
|
|
|
}
|
|
|
|
if s.Vagrantfile != "" {
|
|
|
|
packageArgs = append(packageArgs, "--vagrantfile", s.Vagrantfile)
|
|
|
|
}
|
|
|
|
|
|
|
|
err := driver.Package(packageArgs)
|
|
|
|
if err != nil {
|
|
|
|
state.Put("error", err)
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StepPackage) Cleanup(state multistep.StateBag) {
|
|
|
|
}
|